Repository navigation
Conversation
| const account2Hash = crypto.createHash("sha256").update("ghu_account2").digest("hex"); | ||
| expect(saved.githubTokenHash).toBe(account2Hash); | ||
| }); | ||
|
|
||
| it("fetches and stores token when cache is missing", async () => { |
Contributor
There was a problem hiding this comment.
Consider adding explicit test for backward compatibility: cache exists with valid token but no githubTokenHash field should trigger fresh fetch and save hash
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/providers/github-copilot-token.test.ts
Line: 88
Comment:
Consider adding explicit test for backward compatibility: cache exists with valid token but no `githubTokenHash` field should trigger fresh fetch and save hash
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise.
Contributor
Author
|
@greptileai review |
xinhuagu
force-pushed
the
fix/copilot-token-cache-per-account
branch
from
February 23, 2026 22:12
d1d2a37 to
6f64e2e
Compare
Contributor
Author
|
Addressed ✅ Added explicit backward-compat coverage in src/providers/github-copilot-token.test.ts: when cache has a valid token but no githubTokenHash (pre-upgrade cache), resolver re-fetches and persists the hash. Re-ran the token test locally; green. |
xinhuagu
force-pushed
the
fix/copilot-token-cache-per-account
branch
from
February 28, 2026 19:20
6f64e2e to
9ab20b7
Compare
Contributor
Author
|
Rebased onto latest main to keep this PR current (scope unchanged). |
xinhuagu
force-pushed
the
fix/copilot-token-cache-per-account
branch
from
February 28, 2026 21:22
9ab20b7 to
98e3530
Compare
The shared cache file github-copilot.token.json stores a single API token without recording which GitHub account produced it. When multiple Copilot auth profiles are configured, a cached token from account A is returned for requests intended for account B, breaking multi-account failover. Store a SHA-256 hash of the ghu_ token alongside the cached API token and compare it on cache read. A mismatch triggers a fresh token exchange, ensuring each account always gets its own Copilot API token. Closes openclaw#22264
xinhuagu
force-pushed
the
fix/copilot-token-cache-per-account
branch
from
March 5, 2026 18:32
98e3530 to
a3b0c6c
Compare
Contributor
Author
|
Closing to make room — will revisit later. |
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.
Problem
resolveCopilotApiToken()uses a single shared cache file (github-copilot.token.json) for all Copilot auth profiles. When multiple GitHub accounts are configured, a cached API token from account A is returned for requests meant for account B. If account A is rate-limited, account B's requests fail too — even though account B has available quota (#22264).The cache check only validates expiry (
isTokenUsable), never whether the cached token actually belongs to the requesting account.Fix
Store a SHA-256 hash of the
ghu_token alongside the cached API token. On cache read, compare the hash against the current request'sgithubToken. A mismatch triggers a fresh token exchange instead of returning the wrong account's token.This is backward-compatible: existing cache files without
githubTokenHashsimply miss the cache on first read and get refreshed with the hash included.Changes
src/providers/github-copilot-token.ts: AddgithubTokenHashtoCachedCopilotToken, validate on read, persist on writesrc/providers/github-copilot-token.test.ts: Add test for cross-account cache rejection, update existing cache test to include hashCloses #22264
Greptile Summary
Fixes a multi-account Copilot auth bug where a single shared cache file (
github-copilot.token.json) could serve a stale token from account A to requests intended for account B, causing cross-account rate-limit bleed (#22264).ghu_GitHub token to the cached payload (githubTokenHashfield inCachedCopilotToken)githubTokenHashsimply miss on first read and get refreshed with the hash includedConfidence Score: 5/5
undefined !== string. The SHA-256 hashing avoids storing raw tokens. All three callers in the codebase passgithubTokento the function already, so no caller changes are needed. Tests cover the key scenarios.Last reviewed commit: d1d2a37