fix(chat-headers): skip x-initiator override for @ai-sdk/github-copilot models#2125
Open
zhzy0077 wants to merge 1 commit intocode-yeongyu:devfrom
Open
fix(chat-headers): skip x-initiator override for @ai-sdk/github-copilot models#2125zhzy0077 wants to merge 1 commit intocode-yeongyu:devfrom
zhzy0077 wants to merge 1 commit intocode-yeongyu:devfrom
Conversation
…ot models OpenCode's copilot fetch wrapper already sets x-initiator based on the actual HTTP request body content. When oh-my-opencode's chat.headers hook overrides it with 'agent', the Copilot API detects a mismatch between the header and the request body and rejects the request with 'invalid initiator'. This matches the approach OpenCode's own chat.headers handler uses (copilot.ts:314) — it explicitly skips @ai-sdk/github-copilot models because the fetch wrapper handles x-initiator correctly on its own.
Contributor
|
All contributors have signed the CLA. Thank you! ✅ |
There was a problem hiding this comment.
No issues found across 2 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Auto-approved: Fixes 'invalid initiator' error for Copilot by aligning with upstream SDK handling. Minimal logic change with defensive checks and verified by tests.
Author
|
I have read the CLA Document and I hereby sign the CLA |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the
Bad Request: bad request: error: invalid initiatorerror that occurs when subagents are scheduled via oh-my-opencode on GitHub Copilot providers.Root Cause
OpenCode recently switched all Copilot models to use
@ai-sdk/github-copilot(copilot.ts:56). This SDK package has its own fetch wrapper that setsx-initiatorbased on the actual HTTP request body — if the last message isrole: "user", it setsx-initiator: user.oh-my-opencode's
chat.headershook was overriding this withx-initiator: agent(because it detected the<!-- OMO_INTERNAL_INITIATOR -->marker). The Copilot API then saw a mismatch between the header (agent) and the request body content (role: "user") and rejected the request.OpenCode's own
chat.headershandler already handles this correctly — it explicitly skips@ai-sdk/github-copilotmodels because the fetch wrapper handlesx-initiatoron its own:PR: anomalyco/opencode#13485
Fix
Skip the
x-initiatoroverride whenmodel.api.npm === "@ai-sdk/github-copilot", matching OpenCode's approach.Changes
src/plugin/chat-headers.ts— Checkmodel.api.npmand skip override for@ai-sdk/github-copilotsrc/plugin/chat-headers.test.ts— Added test for the skip behaviorSummary by cubic
Skip x-initiator override for @ai-sdk/github-copilot models to prevent “invalid initiator” errors on Copilot requests. This matches OpenCode’s behavior and restores successful subagent scheduling.
Written for commit 890a737. Summary will update on new commits.