#813·openwiki

[Bug]: Copilot provider (claude-sonnet-5) repository generation crashes with "expected AIMessage or Command, got object" in OpenWikiRepositoryWorkerNoDelegation

Author: RajeshLTIMCreated Sep 4, 2026Updated Sep 10, 2026

Description

openwiki --init (repository/code mode) fails on the first model call when the provider is copilot with a Claude model, in the repository-generation page-job path (src/agent/repository-runner.ts), not the chat-mode agent path:

Error Invalid response from "wrapModelCall" in middleware "OpenWikiRepositoryWorkerNoDelegation": expected AIMessage or Command, got object

This looks related to #213 / #659 (same validator, same error text) but is a distinct, unfixed path:

  • #213/#659's fix (PR #660) only special-cases provider !== "openai-compatible" in src/agent/index.ts's runOpenWikiAgentCore, dropping the "messages" stream mode to avoid ChatMessageChunk aggregation from providers that stream reasoning deltas before the first role:"assistant" delta.
  • The repository-generation path used by --init/--update (runNativeRepositoryGenerationrunPlanningAgent/runPageAgent in repository-runner.ts) never uses "messages" stream mode at all — streamWorkerTools only streams ["tools"]. So the #660 fix's root cause (chunk-aggregation from a streamed roleless-first delta) does not apply here, meaning something else is producing a non-AIMessage object from the model call in this path.
  • The middleware named in the error, OpenWikiRepositoryWorkerNoDelegation, only exists in repository-runner.ts (added to strip the task tool from DeepAgents 1.12+). It just forwards wrapModelCall's result untouched — it isn't the source of the invalid object, only the outermost middleware that surfaces the agent loop's rejection.

Steps to Reproduce

  1. Configure the GitHub Copilot provider with a Claude model:
    OPENWIKI_PROVIDER=copilot
    OPENWIKI_MODEL_ID=claude-sonnet-5
    COPILOT_API_KEY=<GitHub OAuth token>
  2. Run openwiki --init in any repository (code/repository mode).
  3. The first agent turn (planning worker) crashes with the error above. No wiki is produced.

Expected Behavior

The run completes and the wiki is generated, as it does with other providers/models.

Actual Behavior

Crash on the first model call in the repository planning worker. Credential diagnostics confirm OPENWIKI_PROVIDER=copilot, OPENWIKI_MODEL_ID=claude-sonnet-5, and COPILOT_API_KEY are all present and correctly sourced — this is not a missing-credential issue.

Environment

  • OpenWiki version: 0.5.0
  • Provider: copilot (routes through https://api.githubcopilot.com, OpenAI-compatible surface)
  • Model: claude-sonnet-5
  • OS: Windows

Additional Context

  • Searched existing issues for copilot + wrapModelCall/AIMessage and for OpenWikiRepositoryWorkerNoDelegation — no existing reports found.
  • Suspect the Copilot API's response shape for Claude models (proxied through an OpenAI-compatible surface) produces a message object that the DeepAgents/langchain AgentNode's wrapModelCall validator (AIMessage.isInstance(...) || isCommand(...) || {structuredResponse, messages}) doesn't recognize, similar in class to #659 but via _generate/.invoke() rather than streaming chunk-aggregation, since this path never streams "messages".
  • A repro comparing the raw object returned by ChatOpenAI (as constructed for the copilot provider in createModel) against AIMessage.isInstance() for a claude-sonnet-5 completion would likely confirm the shape mismatch.