Skip to content

Fix Copilot token integration identity - #80074

Merged
steipete merged 2 commits into
openclaw:mainfrom
TurboTheTurtle:fix/copilot-token-integration-id
May 10, 2026
Merged

steipete merged 2 commits into
openclaw:mainfrom
TurboTheTurtle:fix/copilot-token-integration-id

Conversation

@TurboTheTurtle

@TurboTheTurtle TurboTheTurtle commented May 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Send Copilot-Integration-Id: vscode-chat during the GitHub Copilot /copilot_internal/v2/token exchange, matching the identity used by downstream Copilot runtime requests.
  • Persist that integration identity with cached short-lived Copilot API tokens and refresh legacy cached tokens that were minted without it.
  • Share the Copilot integration id constant between token exchange and runtime dynamic-header construction so the two paths stay aligned.
  • Align stale CLI error-message expectations with the shared backticked command formatter after CI exposed those mismatches in the full checks-node-agentic-cli shard.

Fixes #79946.

Root Cause

Runtime Copilot model requests identified as vscode-chat, but the token exchange that minted the short-lived Copilot API token only sent IDE headers. Tokens minted under the fallback/default identity could then be scoped as copilot-language-server, so later image-capable model requests still failed even though the runtime request headers contained Copilot-Integration-Id: vscode-chat.

Real Behavior Proof

  • Behavior or issue addressed: Copilot API tokens are now fetched with the same vscode-chat integration identity as runtime Copilot requests, and older cached tokens missing that identity are not reused.

  • Real environment tested: Local OpenClaw source checkout at /Users/andy/openclaw-79946 on macOS, using the repo's Copilot token exchange and provider tests with mocked token endpoint responses.

  • Exact steps or command run after this patch:

    pnpm test src/agents/github-copilot-token.test.ts extensions/github-copilot/models.test.ts src/plugin-sdk/provider-stream-shared.test.ts extensions/github-copilot/index.test.ts src/agents/pi-hooks/compaction-safeguard.test.ts src/cli/channel-auth.test.ts src/cli/plugins-cli.policy.test.ts
    pnpm exec oxfmt --check --threads=1 src/plugin-sdk/provider-auth.ts src/agents/copilot-dynamic-headers.ts src/agents/github-copilot-token.test.ts extensions/github-copilot/models.test.ts CHANGELOG.md src/cli/channel-auth.test.ts src/cli/plugins-cli.policy.test.ts
    git diff --check upstream/main
    pnpm check:changed --base upstream/main
  • Evidence after fix:

    [test] passed 4 Vitest shards in 24.48s
    All matched files use the correct format.
    git diff --check upstream/main exited 0
    pnpm check:changed --base upstream/main exited 0
    

    The new token regression verifies the exchange request includes Copilot-Integration-Id: vscode-chat. A second regression seeds a still-valid legacy cached token without that identity and verifies OpenClaw ignores it, fetches a fresh token, and stores integrationId: "vscode-chat" with the new cache payload. After the first CI run, the full CLI shard failure was reproduced locally with src/cli/channel-auth.test.ts and src/cli/plugins-cli.policy.test.ts; those stale expectations now match the existing shared formatter output and pass with the Copilot tests.

  • Observed result after fix: The token-minting path and runtime request path now use one shared integration id, preventing a valid-but-wrongly-scoped cached token from continuing to route image-capable Copilot requests under the copilot-language-server identity. The previously failing CLI shard assertions now match the actual user-facing command-hint formatting.

  • What was not tested: I did not have live GitHub Copilot credentials for a redacted github-copilot/gemini-3.1-pro-preview image-tool request in this session, so live endpoint entitlement validation was not captured.

Validation

  • pnpm test src/agents/github-copilot-token.test.ts extensions/github-copilot/models.test.ts src/plugin-sdk/provider-stream-shared.test.ts extensions/github-copilot/index.test.ts src/agents/pi-hooks/compaction-safeguard.test.ts src/cli/channel-auth.test.ts src/cli/plugins-cli.policy.test.ts
  • pnpm exec oxfmt --check --threads=1 src/plugin-sdk/provider-auth.ts src/agents/copilot-dynamic-headers.ts src/agents/github-copilot-token.test.ts extensions/github-copilot/models.test.ts CHANGELOG.md src/cli/channel-auth.test.ts src/cli/plugins-cli.policy.test.ts
  • git diff --check upstream/main
  • pnpm check:changed --base upstream/main

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S proof: supplied External PR includes structured after-fix real behavior proof. labels May 10, 2026
@clawsweeper

clawsweeper Bot commented May 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

Summary
The PR adds a shared GitHub Copilot integration id, sends it on the Copilot token exchange, persists it in cached token metadata, invalidates legacy cached tokens, updates targeted tests, adjusts CLI test expectations, and adds a changelog entry.

Reproducibility: yes. for source-level reproduction: current main exchanges the Copilot token without Copilot-Integration-Id while runtime requests send vscode-chat, and the linked bug provides observed HTTP 400 output. I did not run a live Copilot subscription image/tool request in this read-only review.

Real behavior proof
Needs real behavior proof before merge: Mock-only: the PR body reports mocked endpoint/provider tests and explicitly says no live Copilot credentials or image-tool request were tested; add redacted terminal/log/video/screenshot proof, then update the PR body for a fresh review.

Next step before merge
Human/contributor action is needed for redacted live behavior proof; automation cannot produce the contributor’s Copilot subscription evidence.

Security
Cleared: Cleared: the diff only changes existing Copilot auth header/cache metadata, tests, and changelog; it adds no dependency, workflow, secret-access, or package-resolution surface.

Review details

Best possible solution:

Land this PR or an equivalent canonical fix after redacted live Copilot request proof, preserving the shared identity constant, legacy-cache invalidation, and regression tests while superseding the older header-only duplicate PR.

Do we have a high-confidence way to reproduce the issue?

Yes for source-level reproduction: current main exchanges the Copilot token without Copilot-Integration-Id while runtime requests send vscode-chat, and the linked bug provides observed HTTP 400 output. I did not run a live Copilot subscription image/tool request in this read-only review.

Is this the best way to solve the issue?

Yes: aligning the token exchange identity and invalidating legacy cached tokens is the narrow maintainable fix for the reported mismatch. The code direction is stronger than the older header-only duplicate, but it still needs live endpoint proof before merge.

Acceptance criteria:

  • Provide redacted live proof for a GitHub Copilot /copilot_internal/v2/token exchange or github-copilot/gemini-3.1-pro-preview image/tool request showing the copilot-language-server integrator error is gone.
  • pnpm test src/agents/github-copilot-token.test.ts extensions/github-copilot/models.test.ts src/plugin-sdk/provider-stream-shared.test.ts extensions/github-copilot/index.test.ts src/agents/pi-hooks/compaction-safeguard.test.ts src/cli/channel-auth.test.ts src/cli/plugins-cli.policy.test.ts
  • pnpm exec oxfmt --check --threads=1 src/plugin-sdk/provider-auth.ts src/agents/copilot-dynamic-headers.ts src/agents/github-copilot-token.test.ts extensions/github-copilot/models.test.ts CHANGELOG.md src/cli/channel-auth.test.ts src/cli/plugins-cli.policy.test.ts
  • git diff --check upstream/main
  • pnpm check:changed --base upstream/main

What I checked:

  • Current main token exchange omits integration id: On current main, resolveCopilotApiToken builds the /copilot_internal/v2/token request with Accept, Authorization, and IDE headers, but no Copilot-Integration-Id. (src/plugin-sdk/provider-auth.ts:230, 7458f41e7009)
  • Current main runtime requests use vscode-chat: The downstream Copilot runtime header builder already sends Copilot-Integration-Id: vscode-chat, confirming the identity mismatch is in the token-minting path. (src/agents/copilot-dynamic-headers.ts:44, 7458f41e7009)
  • PR aligns token exchange and cache metadata: The PR head adds COPILOT_INTEGRATION_ID, requires that id for cached-token reuse, sends it during token exchange, and stores it with refreshed cache payloads. (src/plugin-sdk/provider-auth.ts:101, 5ece4dc7a9ec)
  • PR adds focused mocked regression coverage: The PR head updates the token header assertion and adds a regression proving a valid legacy cache entry without integrationId is ignored and replaced. (src/agents/github-copilot-token.test.ts:50, 5ece4dc7a9ec)
  • PR proof is mock-only: The PR body reports mocked token endpoint/provider tests and explicitly says no live GitHub Copilot credentials or live image-tool endpoint validation were captured. (5ece4dc7a9ec)
  • Current head checks have no failing check run: The check-runs API for the latest head reported 94 success, 22 skipped, 1 neutral, and two cancelled bot checks; this removes the earlier failed-check concern but does not satisfy live behavior proof. (5ece4dc7a9ec)

Likely related people:

  • vincentkoc: GitHub history links this person to Copilot native endpoint/proxy parsing and IDE auth header work in the same token/runtime paths, including the older token test and dynamic header surface. (role: introduced behavior and recent area contributor; confidence: high; commits: 5abd5d889f14, cdccbf2c1c8e; files: src/agents/github-copilot-token.ts, src/agents/github-copilot-token.test.ts, src/agents/copilot-dynamic-headers.ts)
  • efpiva: Recent GitHub Copilot live catalog work uses the same short-lived Copilot API token and adjacent Copilot-Integration-Id request behavior in the provider plugin. (role: recent adjacent owner; confidence: medium; commits: 75405f64d0a7; files: extensions/github-copilot/index.ts, extensions/github-copilot/models.ts, extensions/github-copilot/models.test.ts)
  • steipete: Current local blame on the central provider-auth and Copilot dynamic-header lines points to recent work by this person in the affected provider/auth boundary. (role: recent area contributor; confidence: medium; commits: 467b0f87ff67; files: src/plugin-sdk/provider-auth.ts, src/agents/copilot-dynamic-headers.ts, extensions/github-copilot/models.ts)

Remaining risk / open question:

Codex review notes: model gpt-5.5, reasoning high; reviewed against 7458f41e7009.

@TurboTheTurtle
TurboTheTurtle force-pushed the fix/copilot-token-integration-id branch from cfe6289 to 5ece4dc Compare May 10, 2026 03:36
@openclaw-barnacle openclaw-barnacle Bot added the cli CLI command changes label May 10, 2026
@steipete
steipete force-pushed the fix/copilot-token-integration-id branch from 5ece4dc to 0ef1a59 Compare May 10, 2026 04:51
@openclaw-barnacle openclaw-barnacle Bot removed the cli CLI command changes label May 10, 2026
@steipete
steipete force-pushed the fix/copilot-token-integration-id branch from 8c73b91 to 3b9e299 Compare May 10, 2026 04:59
@steipete
steipete merged commit d83877a into openclaw:main May 10, 2026
112 of 113 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Landed via rebase onto current main.

  • Copilot fix commit: c20450a82b
  • Changelog credit commit: d83877ae2b
  • Local proof: pnpm check:test-types; pnpm test src/agents/github-copilot-token.test.ts extensions/github-copilot/models.test.ts src/plugin-sdk/provider-stream-shared.test.ts extensions/github-copilot/index.test.ts; targeted oxfmt; git diff --check
  • Live proof: redacted GitHub Copilot auth profile token exchange with Copilot-Integration-Id: vscode-chat returned 200, and /models returned 200 including gemini-3.1-pro-preview.

Thanks @TurboTheTurtle!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling proof: supplied External PR includes structured after-fix real behavior proof. size: S

Projects

None yet

2 participants