Repository navigation
Conversation
Greptile SummaryThis PR fixes the Copilot API token cache so that each GitHub PAT gets its own cache file (named with a short SHA-256 prefix of the token), preventing one profile's cached token from being served to a different profile and making rate-limit rotation actually effective. An in-file Key observations:
Confidence Score: 4/5
Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/providers/github-copilot-token.ts
Line: 113-117
Comment:
**Comment contradicts actual code behavior**
The comment on line 114 says the hash check is "only enforce[d] for the default (auto-resolved) path", implying it is skipped when a custom `cachePath` is supplied. But the expression on line 116 applies equally to both custom and default paths — if a cached file contains a `githubTokenHash` that does not match the current profile's token, the cache is always rejected, regardless of whether `cachePath` was explicitly provided.
In practice this stricter behavior is arguably more correct (the test "rejects cache when githubTokenHash does not match current profile" explicitly passes a custom `cachePath` and still expects rejection). The comment should be updated to reflect what the code actually does:
```suggestion
// Accept the cached token only when it belongs to the same profile. A
// missing hash (legacy cache written before this change) is treated as a
// match so that existing single-profile users are not forced to re-fetch.
const hashMatches = !cached.githubTokenHash || cached.githubTokenHash === tokenHash;
```
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: src/providers/github-copilot-token.ts
Line: 22-24
Comment:
**Short hash increases collision probability**
Only the first 12 hex characters (48 bits) of the SHA-256 digest are kept. Birthday-paradox probability of a collision reaches ~1 % around ~22 million distinct tokens, which is fine for personal use today. However, for fleet-scale or enterprise deployments where hundreds of distinct PATs may be cycled, two profiles could silently share the same cache file and serve each other's tokens.
If the goal is simply a "filesystem-safe" suffix, using 16 or even 20 hex chars (64–80 bits) would still be very short while pushing the collision risk well below practical concern:
```suggestion
return createHash("sha256").update(githubToken).digest("hex").slice(0, 16);
```
How can I resolve this? If you propose a fix, please make it concise.Last reviewed commit: 06ccb39 |
| if (cached && typeof cached.token === "string" && typeof cached.expiresAt === "number") { | ||
| if (isTokenUsable(cached)) { | ||
| // When a custom cachePath is provided the caller manages isolation, so we | ||
| // only enforce the hash check for the default (auto-resolved) path. | ||
| const hashMatches = !cached.githubTokenHash || cached.githubTokenHash === tokenHash; | ||
| if (hashMatches && isTokenUsable(cached)) { |
There was a problem hiding this comment.
Comment contradicts actual code behavior
The comment on line 114 says the hash check is "only enforce[d] for the default (auto-resolved) path", implying it is skipped when a custom cachePath is supplied. But the expression on line 116 applies equally to both custom and default paths — if a cached file contains a githubTokenHash that does not match the current profile's token, the cache is always rejected, regardless of whether cachePath was explicitly provided.
In practice this stricter behavior is arguably more correct (the test "rejects cache when githubTokenHash does not match current profile" explicitly passes a custom cachePath and still expects rejection). The comment should be updated to reflect what the code actually does:
| if (cached && typeof cached.token === "string" && typeof cached.expiresAt === "number") { | |
| if (isTokenUsable(cached)) { | |
| // When a custom cachePath is provided the caller manages isolation, so we | |
| // only enforce the hash check for the default (auto-resolved) path. | |
| const hashMatches = !cached.githubTokenHash || cached.githubTokenHash === tokenHash; | |
| if (hashMatches && isTokenUsable(cached)) { | |
| // Accept the cached token only when it belongs to the same profile. A | |
| // missing hash (legacy cache written before this change) is treated as a | |
| // match so that existing single-profile users are not forced to re-fetch. | |
| const hashMatches = !cached.githubTokenHash || cached.githubTokenHash === tokenHash; |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/providers/github-copilot-token.ts
Line: 113-117
Comment:
**Comment contradicts actual code behavior**
The comment on line 114 says the hash check is "only enforce[d] for the default (auto-resolved) path", implying it is skipped when a custom `cachePath` is supplied. But the expression on line 116 applies equally to both custom and default paths — if a cached file contains a `githubTokenHash` that does not match the current profile's token, the cache is always rejected, regardless of whether `cachePath` was explicitly provided.
In practice this stricter behavior is arguably more correct (the test "rejects cache when githubTokenHash does not match current profile" explicitly passes a custom `cachePath` and still expects rejection). The comment should be updated to reflect what the code actually does:
```suggestion
// Accept the cached token only when it belongs to the same profile. A
// missing hash (legacy cache written before this change) is treated as a
// match so that existing single-profile users are not forced to re-fetch.
const hashMatches = !cached.githubTokenHash || cached.githubTokenHash === tokenHash;
```
How can I resolve this? If you propose a fix, please make it concise.| export function hashGithubToken(githubToken: string): string { | ||
| return createHash("sha256").update(githubToken).digest("hex").slice(0, 12); | ||
| } |
There was a problem hiding this comment.
Short hash increases collision probability
Only the first 12 hex characters (48 bits) of the SHA-256 digest are kept. Birthday-paradox probability of a collision reaches ~1 % around ~22 million distinct tokens, which is fine for personal use today. However, for fleet-scale or enterprise deployments where hundreds of distinct PATs may be cycled, two profiles could silently share the same cache file and serve each other's tokens.
If the goal is simply a "filesystem-safe" suffix, using 16 or even 20 hex chars (64–80 bits) would still be very short while pushing the collision risk well below practical concern:
| export function hashGithubToken(githubToken: string): string { | |
| return createHash("sha256").update(githubToken).digest("hex").slice(0, 12); | |
| } | |
| return createHash("sha256").update(githubToken).digest("hex").slice(0, 16); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/providers/github-copilot-token.ts
Line: 22-24
Comment:
**Short hash increases collision probability**
Only the first 12 hex characters (48 bits) of the SHA-256 digest are kept. Birthday-paradox probability of a collision reaches ~1 % around ~22 million distinct tokens, which is fine for personal use today. However, for fleet-scale or enterprise deployments where hundreds of distinct PATs may be cycled, two profiles could silently share the same cache file and serve each other's tokens.
If the goal is simply a "filesystem-safe" suffix, using 16 or even 20 hex chars (64–80 bits) would still be very short while pushing the collision risk well below practical concern:
```suggestion
return createHash("sha256").update(githubToken).digest("hex").slice(0, 16);
```
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 06ccb390b3
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const cachePath = | ||
| params.cachePath?.trim() || resolveCopilotTokenCachePath(params.githubToken, env); |
There was a problem hiding this comment.
Fall back to legacy Copilot cache file before fetching
resolveCopilotApiToken now resolves only the new hashed cache filename, so upgrades stop reading previously persisted tokens from credentials/github-copilot.token.json. In a common migration case (single-profile user with a still-valid old cache but no network/GitHub outage), this forces a token exchange and fails instead of using the cached token that worked before, which is a functional regression introduced by the new path logic.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 562b6ebb1c
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const legacyHashMatches = !legacyCached.githubTokenHash || legacyCached.githubTokenHash === tokenHash; | ||
| if (legacyHashMatches && isTokenUsable(legacyCached)) { |
There was a problem hiding this comment.
Reject unscoped legacy cache during profile migration
When legacyCached.githubTokenHash is missing (the normal pre-migration case), the fallback path treats it as a match for any current PAT and immediately migrates that token into the new per-profile cache. In an upgrade scenario with PAT rotation or multiple Copilot profiles, this copies profile A’s still-valid API token into profile B’s hashed cache, so B keeps using A’s token until expiry and rotation/failover remains ineffective during that window. The migration should avoid reusing unscoped legacy entries across different PATs (for example by marking/locking legacy ownership on first migration or forcing a fetch when scope is unknown).
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f574160761
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| typeof legacyCached.expiresAt === "number" | ||
| ) { | ||
| const legacyHashMatches = | ||
| !legacyCached.githubTokenHash || legacyCached.githubTokenHash === tokenHash; |
There was a problem hiding this comment.
Refuse hashless legacy token during profile migration
The legacy fallback treats a missing githubTokenHash as a match, so an unscoped credentials/github-copilot.token.json entry can be migrated into any new per-profile cache file. After upgrade, if profile A populated the legacy cache and profile B is used next (or PATs were rotated), profile B can incorrectly reuse A’s Copilot API token until expiry, which defeats the per-profile isolation this change is meant to provide and can keep failover/rate-limit recovery broken for that window.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5a9becd70a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const legacyHashMatches = legacyCached.githubTokenHash === tokenHash; | ||
| if (legacyHashMatches && isTokenUsable(legacyCached)) { |
There was a problem hiding this comment.
Accept hashless legacy cache on first migration
The legacy fallback is currently ineffective for real pre-migration caches because legacyHashMatches requires legacyCached.githubTokenHash === tokenHash, but older github-copilot.token.json entries were written without githubTokenHash. In an upgrade where only the legacy cache exists (especially during GitHub outages/offline runs), this path always skips the cached token and forces a network exchange, regressing previously working cached-auth behavior despite the new "smooth upgrades" fallback.
Useful? React with 👍 / 👎.
…loses openclaw#43658) Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b79cd4c6a4
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| id === defaultSlotIdForKey("contextEngine") && | ||
| normalizedOwner !== CORE_CONTEXT_ENGINE_OWNER | ||
| ) { | ||
| return { ok: false, existingOwner: CORE_CONTEXT_ENGINE_OWNER }; |
There was a problem hiding this comment.
Allow registering the default context engine
This new ownership guard rejects legacy registrations from any owner except core, but the only public registration path still used by registerLegacyContextEngine() is registerContextEngine(), which hardcodes owner public-sdk; that means ensureContextEnginesInitialized() no longer registers the default engine, and resolveContextEngine() will throw for default contextEngine configs in normal run/compact/subagent flows instead of starting with the legacy engine.
Useful? React with 👍 / 👎.
|
Closing to manage active PR count. Will reopen when slot is available. |
Summary
Change Type
Scope
Linked Issue/PR
Security Impact
Evidence
Compatibility / Migration
Failure Recovery
This PR was AI-assisted (fully tested with pnpm build/check/test).