Skip to content

fix(chat-headers): skip x-initiator override for @ai-sdk/github-copilot models#2125

Open
zhzy0077 wants to merge 1 commit intocode-yeongyu:devfrom
zhzy0077:fix/copilot-invalid-initiator
Open

fix(chat-headers): skip x-initiator override for @ai-sdk/github-copilot models#2125
zhzy0077 wants to merge 1 commit intocode-yeongyu:devfrom
zhzy0077:fix/copilot-invalid-initiator

Conversation

@zhzy0077
Copy link

@zhzy0077 zhzy0077 commented Feb 26, 2026

Summary

Fixes the Bad Request: bad request: error: invalid initiator error 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 sets x-initiator based on the actual HTTP request body — if the last message is role: "user", it sets x-initiator: user.

oh-my-opencode's chat.headers hook was overriding this with x-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.headers handler already handles this correctly — it explicitly skips @ai-sdk/github-copilot models because the fetch wrapper handles x-initiator on its own:
PR: anomalyco/opencode#13485

// opencode/packages/opencode/src/plugin/copilot.ts:311-314
// Skip x-initiator override when using @ai-sdk/github-copilot - it has its own
// fetch wrapper that sets x-initiator based on message content, and overriding
// it here causes "invalid initiator" validation errors from Copilot API
if (incoming.model.api.npm === "@ai-sdk/github-copilot") return

Fix

Skip the x-initiator override when model.api.npm === "@ai-sdk/github-copilot", matching OpenCode's approach.

Changes

  • src/plugin/chat-headers.ts — Check model.api.npm and skip override for @ai-sdk/github-copilot
  • src/plugin/chat-headers.test.ts — Added test for the skip behavior

Summary 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.

  • Bug Fixes
    • Do not set x-initiator when model.api.npm === "@ai-sdk/github-copilot".
    • Added a test to verify the skip behavior.

Written for commit 890a737. Summary will update on new commits.

…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.
@github-actions
Copy link
Contributor

github-actions bot commented Feb 26, 2026

All contributors have signed the CLA. Thank you! ✅
Posted by the CLA Assistant Lite bot.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@zhzy0077
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant