Repository navigation
Conversation
…up-to-date IDE headers - Bump COPILOT_USER_AGENT from 0.26.7 to 0.35.0 and COPILOT_EDITOR_VERSION from vscode/1.96.2 to vscode/1.107.0 to match the VS Code Chat extension versions that GitHub maps to the vscode-chat integrator scope. - Add /v2/token exchange in resolveImageRuntime for github-copilot models so the image tool obtains a short-lived Copilot API token instead of sending the raw GitHub OAuth access token directly. The raw OAuth token inherits the copilot-language-server integrator scope, which lacks image-capable models like gemini-3.1-pro-preview. Normal chat requests already exchange via prepareRuntimeAuth; this aligns the image tool path. Refs: openclaw#79946
|
Codex review: needs maintainer review before merge. Summary Reproducibility: yes. source-level. Current main's image runtime stores and passes the raw resolved key for github-copilot image models, and the supplied before/after screenshots show the live integrator authorization error moving past the auth layer after the patch. Real behavior proof Next step before merge Security Review detailsBest possible solution: Land this scoped auth/baseUrl alignment after maintainer review, then handle Gemini message-layout compatibility through the separate follow-up. Do we have a high-confidence way to reproduce the issue? Yes, source-level. Current main's image runtime stores and passes the raw resolved key for github-copilot image models, and the supplied before/after screenshots show the live integrator authorization error moving past the auth layer after the patch. Is this the best way to solve the issue? Yes for the scoped auth fix. Reusing resolveCopilotApiToken and propagating the returned baseUrl matches the adjacent simple completion contract; the later Gemini payload-layout error is a separate narrower repair. What I checked:
Likely related people:
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against a4e6d00770f4. |
There was a problem hiding this comment.
Pull request overview
This PR fixes GitHub Copilot image-tool authentication so image requests use a minted short-lived Copilot API token (via /copilot_internal/v2/token) rather than sending the raw GitHub OAuth token, and updates Copilot IDE header version constants to match current VS Code Chat identifiers.
Changes:
- Bumped
COPILOT_USER_AGENTandCOPILOT_EDITOR_VERSIONto newer VS Code Chat-aligned values. - Added a Copilot token-exchange step in the image runtime path (
resolveImageRuntime) forgithub-copilotmodels. - Updated a header assertion in
compaction-safeguardtests to match the new User-Agent.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/plugin-sdk/provider-auth.ts | Updates Copilot IDE header version constants used during token exchange. |
| src/media-understanding/image.ts | Exchanges GitHub OAuth token for a Copilot API token for image-tool requests. |
| src/agents/pi-hooks/compaction-safeguard.test.ts | Updates expected User-Agent header in a test to match the new constant. |
resolveCopilotApiToken returns both a minted token and the API endpoint derived from it. The normal chat path applies baseUrl to the model before calling complete(); the image path was discarding it, which would break enterprise or proxy-routed Copilot deployments where the minted token points to a non-default host.
2e84c60 to
e7e3ba0
Compare
Add two tests verifying the payload structure for image context: 1. github-copilot provider: prompt and image data are bundled together in the user message, with NO separate systemPrompt. 2. Non-copilot provider (openai): prompt goes to systemPrompt, images stay in user message without text. Refs: openclaw#79946, openclaw#80393
Fixes Copilot image understanding by exchanging OAuth tokens for Copilot API tokens, routing Copilot Gemini image requests through Chat Completions, and sending the prompt in user content with Copilot vision headers. Real behavior proof: - Old Responses route with real Copilot key reproduced `400 model gemini-3.1-pro-preview does not support Responses API`. - Fixed route with the same real Copilot key returned `Cat`. - Final CLI live smoke returned `ok: true` and `text: Cat` for `github-copilot/gemini-3.1-pro-preview`. Verification: - pnpm test src/media-understanding/image.test.ts extensions/github-copilot/models.test.ts extensions/github-copilot/stream.test.ts src/agents/pi-hooks/compaction-safeguard.test.ts -- --reporter=verbose - pnpm check:changed via Blacksmith Testbox tbx_01krgt56pqmft8txekt017wke6, Actions run https://github.com/openclaw/openclaw/actions/runs/25803926150, exit 0. Refs #80393, #80442. Co-authored-by: Yang Haoyu <[email protected]>
|
Thanks @afunnyhy. I landed this as part of the combined maintainer follow-up in #81429 because the two Copilot image fixes needed to be rebased and cleaned up together. Landed commit: 0b8ee46 What landed:
Proof:
Closing this PR as superseded by the landed replacement. Your commits were preserved in the replacement branch, and the squash merge includes your co-author credit. |
Fixes Copilot image understanding by exchanging OAuth tokens for Copilot API tokens, routing Copilot Gemini image requests through Chat Completions, and sending the prompt in user content with Copilot vision headers. Real behavior proof: - Old Responses route with real Copilot key reproduced `400 model gemini-3.1-pro-preview does not support Responses API`. - Fixed route with the same real Copilot key returned `Cat`. - Final CLI live smoke returned `ok: true` and `text: Cat` for `github-copilot/gemini-3.1-pro-preview`. Verification: - pnpm test src/media-understanding/image.test.ts extensions/github-copilot/models.test.ts extensions/github-copilot/stream.test.ts src/agents/pi-hooks/compaction-safeguard.test.ts -- --reporter=verbose - pnpm check:changed via Blacksmith Testbox tbx_01krgt56pqmft8txekt017wke6, Actions run https://github.com/openclaw/openclaw/actions/runs/25803926150, exit 0. Refs openclaw#80393, openclaw#80442. Co-authored-by: Yang Haoyu <[email protected]>
Fixes Copilot image understanding by exchanging OAuth tokens for Copilot API tokens, routing Copilot Gemini image requests through Chat Completions, and sending the prompt in user content with Copilot vision headers. Real behavior proof: - Old Responses route with real Copilot key reproduced `400 model gemini-3.1-pro-preview does not support Responses API`. - Fixed route with the same real Copilot key returned `Cat`. - Final CLI live smoke returned `ok: true` and `text: Cat` for `github-copilot/gemini-3.1-pro-preview`. Verification: - pnpm test src/media-understanding/image.test.ts extensions/github-copilot/models.test.ts extensions/github-copilot/stream.test.ts src/agents/pi-hooks/compaction-safeguard.test.ts -- --reporter=verbose - pnpm check:changed via Blacksmith Testbox tbx_01krgt56pqmft8txekt017wke6, Actions run https://github.com/openclaw/openclaw/actions/runs/25803926150, exit 0. Refs openclaw#80393, openclaw#80442. Co-authored-by: Yang Haoyu <[email protected]>
Fixes Copilot image understanding by exchanging OAuth tokens for Copilot API tokens, routing Copilot Gemini image requests through Chat Completions, and sending the prompt in user content with Copilot vision headers. Real behavior proof: - Old Responses route with real Copilot key reproduced `400 model gemini-3.1-pro-preview does not support Responses API`. - Fixed route with the same real Copilot key returned `Cat`. - Final CLI live smoke returned `ok: true` and `text: Cat` for `github-copilot/gemini-3.1-pro-preview`. Verification: - pnpm test src/media-understanding/image.test.ts extensions/github-copilot/models.test.ts extensions/github-copilot/stream.test.ts src/agents/pi-hooks/compaction-safeguard.test.ts -- --reporter=verbose - pnpm check:changed via Blacksmith Testbox tbx_01krgt56pqmft8txekt017wke6, Actions run https://github.com/openclaw/openclaw/actions/runs/25803926150, exit 0. Refs openclaw#80393, openclaw#80442. Co-authored-by: Yang Haoyu <[email protected]>
Fixes Copilot image understanding by exchanging OAuth tokens for Copilot API tokens, routing Copilot Gemini image requests through Chat Completions, and sending the prompt in user content with Copilot vision headers. Real behavior proof: - Old Responses route with real Copilot key reproduced `400 model gemini-3.1-pro-preview does not support Responses API`. - Fixed route with the same real Copilot key returned `Cat`. - Final CLI live smoke returned `ok: true` and `text: Cat` for `github-copilot/gemini-3.1-pro-preview`. Verification: - pnpm test src/media-understanding/image.test.ts extensions/github-copilot/models.test.ts extensions/github-copilot/stream.test.ts src/agents/pi-hooks/compaction-safeguard.test.ts -- --reporter=verbose - pnpm check:changed via Blacksmith Testbox tbx_01krgt56pqmft8txekt017wke6, Actions run https://github.com/openclaw/openclaw/actions/runs/25803926150, exit 0. Refs openclaw#80393, openclaw#80442. Co-authored-by: Yang Haoyu <[email protected]>
Bump
COPILOT_USER_AGENTfrom 0.26.7 to 0.35.0 andCOPILOT_EDITOR_VERSIONfrom vscode/1.96.2 to vscode/1.107.0 to match the VS Code Chat extension versions that GitHub maps to thevscode-chatintegrator scope.Add
/v2/tokenexchange inresolveImageRuntimeforgithub-copilotmodels so the image tool obtains a short-lived Copilot API token instead of sending the raw GitHub OAuth access token directly. The raw OAuth token inherits thecopilot-language-serverintegrator scope, which lacks image-capable models likegemini-3.1-pro-preview.Propagate the derived
baseUrlfrom the minted Copilot token to the image model. This aligns the image tool path with the normal chat path and ensures enterprise or proxy-routed Copilot deployments connect to the correct host.Refs: #79946, Follow-up to #80074
Summary
prepareRuntimeAuthand sends the raw GitHub OAuth access token directly to the Copilot API. This token defaults to thecopilot-language-serverscope, causing400 The requested model is not available for integratorerrors when requesting multi-modal models likegemini-3.1-pro-preview./v2/tokenexchange step inresolveImageRuntimeforgithub-copilotproviders, and ensured the returnedbaseUrlis correctly applied to the completion model. Bumped outdatedUser-AgentandEditor-Versionconstants to prevent shadow downgrades by GitHub's API gateway.isCopilotTokenUsable) and the standard text chat authentication flow remain untouched.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
Real behavior proof (required for external PRs)
github-copilot/gemini-3.1-pro-preview.Describe this image, focusing on expressions.400 The requested model is not available for integrator "copilot-language-server") is completely resolved. The image tool now obtains a short-lived Copilot API token with thevscode-chatintegrator scope, which has access to multi-modal models likegemini-3.1-pro-preview. The separate payload-format issue (Gemini rejecting system-level prompt placement) is addressed in a focused follow-up PR per the "Keep PRs focused" guideline.Root Cause
This PR addresses two root causes that prevented the image tool from using Copilot-hosted Gemini models:
Cause 1 — Token exchange and baseUrl bypass (core): The image tool in
media-understanding/image.tsfetches the raw GitHub OAuth access token viagetApiKeyForModeland passes it directly topi-ai.complete(), bypassing the/v2/tokenexchange that normal chat performs viaprepareRuntimeAuth. This caused two issues: it inherited the restrictedcopilot-language-serverintegrator scope, and it discarded the custombaseUrlrequired by enterprise or proxy-routed Copilot deployments.Cause 2 — Stale IDE header versions:
COPILOT_USER_AGENTandCOPILOT_EDITOR_VERSIONwere pinned to0.26.7/vscode/1.96.2. GitHub's/v2/tokenendpoint maps these older versions to thecopilot-language-serverintegrator. Updated to0.35.0/vscode/1.107.0to match the current VS Code Chat extension identifiers used bypi-ai.Missing detection: E2E tests mock the endpoint but don't validate token scope/claims required by Copilot's multi-modal models.
Contributing context: PR #80074 added the
Copilot-Integration-Idheader and cache invalidation for the standardprepareRuntimeAuthchat flow, but did not cover the image tool's separate auth path or the outdated IDE version headers.Regression Test Plan
Coverage level that should have caught this:
Existing tests updated:
compaction-safeguard.test.ts— UA assertion updated from0.26.7to0.35.0.Scenario that should be locked in: When
provider === 'github-copilot', the image tool must callresolveCopilotApiTokento exchange the OAuth token for a short-lived Copilot API token.Why live E2E is the right level: The
/v2/tokenexchange and Copilot API behavior can only be validated against GitHub's live infrastructure. CI-mocked endpoints cannot exercise the actual token scope logic.User-visible / Behavior Changes
Users can now successfully use
github-copilot/gemini-3.1-pro-preview(and future multi-modal Copilot models) as their designated image model without hitting integrator authorization errors.Diagram (if applicable)
Security Impact (required)
NoYesYesNoNoYes, explain risk + mitigation: Added a network call tohttps://api.github.com/copilot_internal/v2/tokenduring the image tool initialization. Mitigation: This leverages the exact same secureresolveCopilotApiTokenhelper used by standard chat, which inherently caches the short-lived token to prevent network spam.Repro + Verification
Environment
github-copilot/gemini-3.1-pro-previewimageModel: { primary: "github-copilot/gemini-3.1-pro-preview" }Steps
github-copilot/gemini-3.1-pro-previewinopenclaw.json.Expected
Actual
The requested model is not available for integrator "copilot-language-server".Evidence
Attach at least one:
Screenshots embedded in the Real behavior proof section above.
Human Verification (required)
What you personally verified (not just CI), and how:
Verified scenarios:
github-copilot/gemini-3.1-pro-previewas image model — image tool successfully identified a solid red 100×100 PNG as "red", confirming thevscode-chatintegrator scope is now applied and Gemini multimodal models respond correctly.github-copilot.token.json) now includes"integrationId": "vscode-chat"in its payload, confirming the exchange logic and cache metadata are aligned.User-Agent: GitHubCopilotChat/0.35.0andEditor-Version: vscode/1.107.0, confirmed via diagnostic logging.Edge cases checked:
integrationIdis correctly rejected and a fresh/v2/tokenexchange is triggered (existing test coverage).What you did not verify:
gemini-3.1-pro-preview(GPT-4o, Claude Sonnet 4.5, etc.) — these use different auth paths before this PR and should be unaffected.Review Conversations
If a bot review conversation is addressed by this PR, resolve that conversation yourself. Do not leave bot review conversation cleanup for maintainers.
Compatibility / Migration
integrationIdcache field is optional (backward compatible with older cache files, which are rejected and re-minted).Risks and Mitigations
Risk: The image tool now makes an additional network call (
/v2/token) on first use per session, adding latency (~200-500ms).isCopilotTokenUsable), so subsequent image calls within a session reuse the cached token without an additional exchange.Risk: Updated IDE header versions (
0.26.7→0.35.0,1.96.2→1.107.0) could theoretically change Copilot API behavior for models other than Gemini.pi-aiinternally). The Copilot runtime chat path already sends these headers successfully for all models. No behavioral change expected for non-image Copilot requests.Risk: Token exchange failure in the image tool causes a silent fallback to the raw OAuth token.
copilot-language-serverscope) rather than breaking the image tool entirely. Failed exchanges are likely transient and self-heal on the next call.