Skip to content

fix(github-copilot): accept fine-grained access tokens - #114282

Merged
joshavant merged 9 commits into
mainfrom
fix/copilot-source-token-runtime-auth
Jul 28, 2026
Merged

joshavant merged 9 commits into
mainfrom
fix/copilot-source-token-runtime-auth

Conversation

@joshavant

@joshavant joshavant commented Jul 27, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #108738

What Problem This Solves

Fixes an issue where GitHub Copilot users authenticating with a fine-grained PAT could not use OpenClaw because its retired short-lived token exchange rejected the otherwise valid credential before any model request was attempted.

Why This Change Was Made

OpenClaw now validates the original GitHub credential through Copilot's current /copilot_internal/user contract, uses the returned trusted API endpoint, and keeps the source credential for runtime requests as required by the current Copilot SDK. Runtime traffic identifies as copilot-developer-cli; the legacy device-login exchange remains narrowly unchanged. Custom embeddings endpoints continue to require their own explicit API key and never receive the stored GitHub credential.

This is the provider-auth prerequisite for the post-#108738 pure-inference work; it is intentionally separated because the auth path is shared by streaming, catalogs, embeddings, usage, media, and caching.

User Impact

GitHub Copilot users can use supported PAT/OAuth credentials across OpenClaw's existing Copilot runtime surfaces, including fine-grained PATs that the old exchange rejected.

Evidence

Source-credential live proof (prior exact head)

Commit 69ad007387685a0726403c86a8ddc1e0a0cd937e was exercised with a fine-grained GitHub PAT injected from a scoped secret provider. The credential was not logged. The real provider runtime authenticated, fetched the catalog, and streamed a model response:

[provider-transport-fetch] start method=POST url=https://api.individual.githubcopilot.com/responses
[provider-transport-fetch] response status=200 contentType=text/event-stream
{
  "head": "69ad007387685a0726403c86a8ddc1e0a0cd937e",
  "runtimeAuth": true,
  "catalogCount": 45,
  "model": "gpt-5.4",
  "streamStopReason": "stop",
  "markerMatched": true
}

Existing-profile upgrade proof

The candidate tree that became the exact head was tested with a real device-login OAuth profile in both relevant persisted states. The only subsequent source change was formatting the same provider formatter expression; exact-head focused tests and the PAT live proof above followed it.

{
  "unexpiredLegacyProfile": {
    "agentTurn": "passed",
    "sourceCredentialPreserved": true,
    "accessChanged": false,
    "expiryAdvanced": false
  },
  "forcedExpiredLegacyProfile": {
    "agentTurn": "passed",
    "sourceCredentialPreserved": true,
    "accessChanged": true,
    "expiryAdvanced": true
  },
  "postMatrixRuntimeAuth": true,
  "postMatrixLegacyRefresh": true
}

This proves an existing unexpired profile remains usable without needless refresh, while an expired profile refreshes normally without replacing or expiring its durable source credential.

Integration-identity sibling-surface proof

The same live credential was tested under both the prior vscode-chat and proposed copilot-developer-cli identities:

Surface Result
Catalog CLI identity: 48 models; VS Code identity: 28; CLI-only: 20; VS-Code-only: 0
Responses Common gpt-5.4-mini model passed under both identities
Anthropic Messages Common Claude Sonnet 4.5 model passed under both identities
Chat Completions Common Gemini 2.5 Pro model returned HTTP 200 and non-empty output under both identities
Embeddings Both identities returned 1,536-dimensional embeddings
Vision/media Valid PNG requests with gpt-5.4 and gpt-5.4-mini passed under both identities
Usage Passed with the proposed CLI identity

No tested sibling surface lost authorization or model availability. Enterprise policy behavior remains untested because no enterprise credential was available. A high-level local media harness stalled before issuing a provider request; direct production vision requests passed under both identities, isolating that harness issue from the identity change.

Provider-owned request identity proof (current exact head)

Current head d673267fbf71e24d0e031c2f4a6d3b8b616ae4d8 contains provider-identity implementation commit 1005f522325046a2dbc2670a4d7d87711b63ed5c, which removes the second core-owned Copilot runtime identity and routes core callers through the existing generic provider-prepared auth/header contract. The follow-up commit refreshes the generated SDK hash after the removed core import changes TypeScript declaration alias selection; no SDK export or underlying type changes.

Live OpenClaw agent turns using the pushed implementation completed against all three affected Copilot transports:

Transport Model Result
OpenAI Responses gpt-5.4 HTTP 200; exact marker matched
Anthropic Messages claude-sonnet-4.5 HTTP 200; exact marker matched
Chat Completions gemini-2.5-pro HTTP 200; exact marker matched

A direct production vision request with a valid PNG and gpt-5.4 also returned HTTP 200 with non-empty output. The high-level local media harness still stalls before its first provider fetch; focused tests prove prepared headers are applied and sentinel-unwrapped at final media egress, while the direct vision proof isolates the remaining harness stall from Copilot auth or identity.

Expired legacy-profile upgrade proof

The current head removes the hidden dependency on the retired token exchange for existing OAuth profiles whose legacy Copilot access token has expired. The stored refresh field remains the durable GitHub credential; provider refresh now returns that unchanged bundle, and both OAuth managers avoid rewriting unchanged state.

A real expired OAuth profile was created with the same fine-grained PAT previously rejected by /copilot_internal/v2/token. A local OpenClaw agent turn authenticated through the new runtime path and completed a gpt-5.4 Responses request with HTTP 200 and the exact marker. The persisted profile retained its original expired access token, expiry, and durable source credential. The matching unexpired-profile control also completed with HTTP 200 and remained unchanged.

Automated verification

  • Focused OAuth/provider tests passed after the formatter fix: 57 tests (25 core OAuth + 32 provider).
  • The current exact-head build passed under Node 24 during the live matrix.
  • 422 focused provider, agent-runtime, auth-egress, compaction, and media tests passed.
  • 125 focused OAuth-manager, session-auth-storage, Copilot OAuth, onboarding, and refresh-fail-closed tests passed for the legacy-expiry follow-up.
  • Formatting, git diff --check, and plugin-sdk:api:check passed.
  • The remote changed gate classified the intended core/plugin lanes, then stopped on a pre-existing max-lines baseline shrink in nine untouched files.
  • Fresh pre-commit autoreview was clean with no accepted/actionable findings.
  • The latest AWS Crabbox lease failed during SSH bootstrap and was stopped; under the trusted-source fallback policy, the exact-head live proof above ran locally. The earlier fresh AWS paired repro and fix proof remain valid supporting evidence for the unchanged PAT path.

AI-assisted: yes. I understand the implementation and validated it against the installed Copilot SDK source/types, official behavior, upgrade states, and live provider traffic.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling extensions: github-copilot size: XL maintainer Maintainer-authored PR labels Jul 27, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels Jul 27, 2026
@clawsweeper

clawsweeper Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 27, 2026, 11:30 PM ET / July 28, 2026, 03:30 UTC.

ClawSweeper review

What this changes

The branch replaces GitHub Copilot’s retired exchanged-token runtime path with validation of the original GitHub credential, endpoint resolution from Copilot’s user contract, and provider-owned copilot-developer-cli request headers across catalog, completion, embedding, and media paths.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep this PR open for maintainer review. It has strong real-provider proof and no concrete patch defect in the reviewed material, but it deliberately changes the Copilot request identity and credential path; the author explicitly could not verify GitHub Enterprise tenant policy behavior, so landing that compatibility-sensitive change needs an owner decision rather than an automatic close or merge verdict.

Priority: P1
Reviewed head: 528f00973889cb361f0af243652f59062c326089
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch has strong real-provider and upgrade evidence, with one maintainer-facing enterprise compatibility decision remaining before merge.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body supplies redacted live after-fix provider output for a fine-grained credential plus real upgrade-state controls and transport coverage; the only stated gap is GitHub Enterprise tenant policy behavior.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body supplies redacted live after-fix provider output for a fine-grained credential plus real upgrade-state controls and transport coverage; the only stated gap is GitHub Enterprise tenant policy behavior.
Evidence reviewed 4 items Provider-owned runtime preparation: The branch adds source-token validation and endpoint resolution in the Copilot plugin, then removes core-owned default Copilot headers so generic runtime callers consume prepared provider auth instead.
Persisted-profile upgrade handling: The OAuth provider normalizes legacy exchanged-token profiles so the durable GitHub source credential becomes the active non-expiring credential, while the shared OAuth paths retain fail-closed behavior for unchanged expired refresh results.
Exact-head proof and remaining gap: The PR body reports live fine-grained-PAT requests across Responses, Anthropic Messages, Chat Completions, vision, embeddings, catalog, and usage, plus persisted-profile controls. It also explicitly states that enterprise policy behavior was not tested because an enterprise credential was unavailable.
Findings None None.
Security None None.

How this fits together

The GitHub Copilot plugin obtains a GitHub credential and prepares runtime auth for OpenClaw’s generic provider pipeline. Agent, compaction, embedding, and image runtimes consume that prepared auth to send Copilot API requests without core code owning Copilot-specific headers or token-exchange policy.

flowchart LR
  Credential[GitHub credential] --> Plugin[GitHub Copilot plugin]
  Plugin --> Validation[Copilot account validation]
  Validation --> Prepared[Prepared auth and endpoint]
  Prepared --> Agent[Agent and compaction runtime]
  Prepared --> Media[Embedding and image runtime]
  Agent --> Copilot[Copilot API]
  Media --> Copilot
Loading

Decision needed

Question Recommendation
Should OpenClaw change all GitHub Copilot runtime requests to the copilot-developer-cli integration identity before representative GitHub Enterprise tenant policy behavior has been verified? Require enterprise validation: Obtain a redacted enterprise-tenant catalog and completion proof using the new identity before merging.

Why: The code and public-account proof support the new contract, but enterprise authorization and allow-list policy can be controlled outside OpenClaw and was not exercised by the supplied evidence.

Before merge

  • Resolve merge risk (P1) - GitHub Enterprise tenants may authorize or restrict copilot-developer-cli differently from the former vscode-chat identity; public and personal-account proof does not settle that operator-facing compatibility question.
  • Complete next step (P2) - No discrete mechanical repair is supported by the review; a maintainer must decide whether the untested Enterprise integration-policy risk is acceptable before merge.
Agent review details

Security

None.

PR surface

Source -141, Tests +32, Docs 0, Generated 0. Total -109 across 33 files.

View PR surface stats
Area Files Added Removed Net
Source 18 255 396 -141
Tests 13 411 379 +32
Docs 1 22 22 0
Config 0 0 0 0
Generated 1 1 1 0
Other 0 0 0 0
Total 33 689 798 -109

Review metrics

Metric Value Why it matters
Runtime credential transition 1 retired exchanged-token/cache path removed; 1 source-credential validation path added This changes how existing Copilot profiles authenticate and therefore requires both fresh-login and upgrade evidence.

Stored data model

Persistent data-model change detected: persistent cache schema: extensions/github-copilot/connection-bound-ids.live.test.ts, persistent cache schema: extensions/github-copilot/index.ts, persistent cache schema: extensions/github-copilot/models.test.ts, persistent cache schema: extensions/github-copilot/token-cache.ts, persistent cache schema: extensions/github-copilot/token.ts, serialized state: src/agents/sessions/auth-storage.ts, and 5 more. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Merge-risk options

Maintainer options:

  1. Add enterprise-tenant proof (recommended)
    Before merging, capture redacted GitHub Enterprise evidence that catalog resolution and one completion succeed with the new integration identity.
  2. Accept the enterprise-policy uncertainty
    A maintainer may merge based on the broad public-account and upgrade matrix while explicitly accepting that tenant-specific Copilot policy remains unverified.

Technical review

Best possible solution:

Keep Copilot request identity and credential handling owned by the Copilot plugin, then merge only after the responsible owner accepts the Enterprise-policy uncertainty or obtains a representative enterprise validation result.

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

Yes for the reported fine-grained-token failure: the PR identifies the retired exchange as the rejecting path and provides a live provider run where source-credential validation reaches a streamed response. Enterprise tenant policy behavior is not reproduced or verified.

Is this the best way to solve the issue?

Yes for the main design direction: moving Copilot-specific validation and request identity into the Copilot plugin avoids duplicate core policy and preserves generic prepared-auth consumption. The remaining question is rollout confidence for enterprise identity policy, not a better competing implementation shape.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 7653bcce58b3.

Labels

Label justifications:

  • P1: The PR addresses a real provider-auth regression that prevents fine-grained GitHub credentials from reaching existing Copilot runtime surfaces.
  • merge-risk: 🚨 compatibility: Existing persisted Copilot OAuth profiles are normalized away from an exchanged access token and toward the durable source credential.
  • merge-risk: 🚨 auth-provider: The plugin changes runtime credential validation, resolved API endpoint selection, and the Copilot integration identity used on requests.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body supplies redacted live after-fix provider output for a fine-grained credential plus real upgrade-state controls and transport coverage; the only stated gap is GitHub Enterprise tenant policy behavior.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies redacted live after-fix provider output for a fine-grained credential plus real upgrade-state controls and transport coverage; the only stated gap is GitHub Enterprise tenant policy behavior.

Evidence

What I checked:

Likely related people:

  • joshavant: Authored the nine commits that move Copilot runtime authentication, identity preparation, persisted-profile normalization, tests, and related documentation together; current-main ownership could not be established from the supplied evidence. (role: primary implementation contributor; confidence: medium; commits: 1fc48a5ec78b, 0e6d6c5d1991, 9e38cc116ab5; files: extensions/github-copilot/runtime-auth.ts, extensions/github-copilot/runtime-identity.ts, src/llm/utils/oauth/github-copilot.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Obtain representative enterprise-tenant proof or record maintainer acceptance of the untested identity-policy risk.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (9 earlier review cycles; latest 8 shown)
  • reviewed 2026-07-27T16:27:41.606Z sha 014c276 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-27T22:06:45.412Z sha 69ad007 :: found issues before merge. :: [P2] Keep the Copilot runtime identity provider-owned
  • reviewed 2026-07-27T23:23:56.102Z sha 1005f52 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-27T23:39:37.601Z sha 702a8b6 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-28T00:39:13.430Z sha d673267 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-28T01:08:12.429Z sha c1f6a6e :: needs maintainer review before merge. :: none
  • reviewed 2026-07-28T01:48:44.501Z sha dd785104e1cf30868e09745118b73a2ec9a4a555 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-28T03:14:57.186Z sha 9e38cc1 :: needs maintainer review before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Jul 27, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jul 27, 2026
@joshavant
joshavant requested a review from a team as a code owner July 28, 2026 00:33
@joshavant

Copy link
Copy Markdown
Collaborator Author

OAuth upgrade-policy follow-up at head dd785104e1cf30868e09745118b73a2ec9a4a555:

  • Removed the two generic core exceptions that interpreted an unchanged expired OAuth refresh result as provider-owned success. Shared OAuth persistence once again requires refresh providers to return a persistable credential state.
  • Kept the compatibility policy in the GitHub Copilot owner: an expired legacy exchanged-token profile is normalized once to make the durable source credential active and non-expiring. No token exchange occurs during this normalization.
  • Added adjacent OpenAI regression coverage proving an unchanged expired refresh result still fails closed.
  • Focused proof passed: 152 tests across the OAuth manager, SQLite auth storage, OpenAI refresh fallback, Copilot OAuth, and OpenAI provider suites.
  • Live credential proof passed for both upgrade states: an unexpired legacy Copilot profile remained unchanged; an expired profile normalized once; both paths resolved the durable source credential, authenticated through the current Copilot runtime, and enumerated 45 models.
  • Fresh autoreview reported no accepted/actionable findings.
  • A current three-way merge-tree against origin/main was conflict-free (tree 6cc5f7137adcec10480e90d0c53629f784f2fb32); current main has not changed the two shared OAuth persistence modules since this branch point.

Relevant ownership and regression points: src/llm/utils/oauth/github-copilot.ts:572, src/agents/auth-profiles/oauth-manager.ts:621, src/agents/sessions/auth-storage.ts:736, src/agents/auth-profiles/oauth.openai-codex-refresh-fallback.test.ts:226, src/llm/utils/oauth/github-copilot.test.ts:305.

@joshavant
joshavant force-pushed the fix/copilot-source-token-runtime-auth branch from dd78510 to 9e38cc1 Compare July 28, 2026 03:10
@joshavant
joshavant merged commit 1153ef4 into main Jul 28, 2026
118 checks passed
@joshavant
joshavant deleted the fix/copilot-source-token-runtime-auth branch July 28, 2026 03:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation extensions: github-copilot maintainer Maintainer-authored PR merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants