Repository navigation
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 921ebb9d60
ℹ️ 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".
Greptile SummaryThis PR fixes a race condition where concurrent callers in the same gateway process could each independently attempt to refresh the same OAuth profile, burning the rotation token multiple times. It introduces a process-scoped in-flight map (keyed by Confidence Score: 4/5Safe to merge; the core logic is correct and no data-loss or security regressions were found. The serialization approach is sound for Node.js's single-threaded event loop, the refresh_token_reused retry is properly bounded to one attempt, and idempotent writes prevent duplicate disk operations. One minor targeted fix would strengthen the test: the concurrent test should also assert that workerAgentDir's store receives the refreshed credentials, since that is the second half of the deduplication contract that awaitOAuthRefreshResult is responsible for. oauth.openai-codex-refresh-fallback.test.ts — the concurrent test is missing an assertion for workerAgentDir store update.
|
| Filename | Overview |
|---|---|
| src/agents/auth-profiles/oauth.ts | Core OAuth refresh logic refactored to add process-scoped in-flight deduplication, refresh_token_reused recovery (reload + single retry), and a new syncOAuthCredentialToStore helper. Logic is sound; minor redundant sync for the in-flight originator when fresh credentials were already on disk. |
| src/agents/auth-profiles/oauth.openai-codex-refresh-fallback.test.ts | Three new regression tests added for concurrent refresh, reload-after-reuse, and reload+retry paths. The concurrent test is missing an assertion that workerAgentDir's store receives the refreshed credentials. |
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/agents/auth-profiles/oauth.ts
Line: 374-383
Comment:
**Redundant `syncOAuthCredentialToStore` call for the in-flight originator**
When `loadFreshStoredOAuthCredential` finds fresh credentials it already syncs them to `params.agentDir` (line ~215–222). The IIFE then resolves with that value, and the outer `awaitOAuthRefreshResult` call (line 417) invokes `syncOAuthCredentialToStore` on the same `agentDir` a second time. The idempotency check inside `syncOAuthCredentialToStore` prevents a duplicate disk write, but it still acquires and releases the file lock a second time for the originating caller.
Secondary / waiting callers are fine — their `agentDir` differs from the IIFE's and only the outer `awaitOAuthRefreshResult` writes to them. The redundancy is limited to the caller that actually started the refresh. Consider skipping the outer sync when `freshStored` was the source of the result (e.g. by returning an already-synced marker or by having `loadFreshStoredOAuthCredential` accept a flag indicating it should skip in-place sync when the caller will sync afterwards).
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/agents/auth-profiles/oauth.openai-codex-refresh-fallback.test.ts
Line: 245-261
Comment:
**Worker agent dir credentials not verified**
The concurrent-serialization test is the core regression coverage for this PR's deduplication guarantee, but it only asserts that `agentDir` (the main agent) ends up with the refreshed credentials. Since `awaitOAuthRefreshResult` is responsible for writing the result to each waiter's own `agentDir`, a matching `readStoredProfile(workerAgentDir, profileId)` assertion would confirm that secondary callers also get their stores updated — the other half of the shared-refresh contract.
Consider adding after the existing `readStoredProfile(agentDir, profileId)` assertion:
```ts
await expect(readStoredProfile(workerAgentDir, profileId)).resolves.toMatchObject({
access: "fresh-access-token", // pragma: allowlist secret
refresh: "fresh-refresh-token",
});
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix: serialize oauth profile refreshes" | Re-trigger Greptile
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8af734bdf7
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c3c459c128
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 79142def9e
ℹ️ 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".
Replace blacklist-style guards in syncOAuthCredentialToStore with a single whitelist condition: only update when an existing OAuth profile with a matching provider is present. This prevents resurrecting deleted profiles and simplifies the guard logic.
All Date.now() < expires comparisons now guard with Number.isFinite() first, so NaN/undefined/non-numeric expires values are treated as stale and trigger a refresh instead of silently reusing an invalid access token.
a27c505 to
cd18846
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cd1884630f
ℹ️ 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 current = store.profiles[params.profileId]; | ||
| if (!current || current.type !== "oauth" || current.provider !== params.provider) { | ||
| return false; | ||
| } |
There was a problem hiding this comment.
Guard OAuth sync against concurrent OAuth credential swaps
syncOAuthCredentialToStore only checks type and provider before writing, so an in-flight refresh can still overwrite a newer OAuth login for the same profile/provider. This happens when an operator (or another process) re-authenticates the profile to a different OAuth account while the refresh promise is running: the updater still accepts the row and writes newCredentials, effectively rolling back the newer credential set. The updater should also verify the current OAuth fields still match the credential snapshot that initiated the refresh (or another monotonic version check) before replacing tokens.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
This PR addresses concurrent refresh serialization for the same profile, not mid-refresh account re-authentication.
The syncOAuthCredentialToStore write guard (type + provider match) is pre-existing behavior unchanged by this PR. A monotonic version check for credential swaps during refresh is a valid hardening idea but falls outside this fix's scope — happy to track as a follow-up issue.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 683d1b1060
ℹ️ 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".
| previous?: Pick<OAuthCredential, "access" | "refresh" | "expires">; | ||
| requireChange?: boolean; | ||
| }): Promise<OAuthRefreshResult | null> { | ||
| const reloadedStore = loadAuthProfileStoreForSecretsRuntime(params.agentDir); |
There was a problem hiding this comment.
Keep OAuth refresh reloads snapshot-aware
loadFreshStoredOAuthCredential now reloads credentials with loadAuthProfileStoreForSecretsRuntime, which bypasses active runtime auth-store snapshots and reads directly from disk. In an active secrets-runtime snapshot (where callers pass snapshot-backed stores from ensureAuthProfileStore), this can silently return fresher/different disk credentials than the snapshot and change which account/token is used during refresh resolution, breaking snapshot consistency for that run. The reload here should use the same snapshot-aware source as the caller (or explicitly gate disk reloads when snapshots are active).
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The disk reload in loadFreshStoredOAuthCredential is intentional — it detects whether another process has already rotated the refresh token, which is the core mechanism for refresh_token_reused recovery. Using snapshot-aware stores here would return stale credentials in exactly the scenario this PR fixes.
This disk read is scoped to the refresh-retry path only and doesn't affect normal token resolution. Secrets-runtime snapshot consistency is a broader pre-existing concern outside this PR's scope.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e117fb0cc9
ℹ️ 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".
| if ( | ||
| result && | ||
| params.agentDir && | ||
| (!result.originAgentDir || result.originAgentDir !== params.agentDir) |
There was a problem hiding this comment.
Skip post-refresh resync when origin is unknown
The new awaitOAuthRefreshResult path rewrites result.newCredentials whenever originAgentDir is falsy, and refreshOAuthTokenFromStoreWithLock's plugin-refresh return still omits originAgentDir; that means plugin refreshes for agent-scoped stores now do an extra post-lock write. If the profile is re-authenticated to a different OAuth account (same provider/profileId) between the lock-protected refresh write and this follow-up sync, this second write can roll back the newer credentials. Fresh evidence in this commit is the newly introduced awaitOAuthRefreshResult branch with the !result.originAgentDir condition.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
This follows the same pattern as the earlier credential-swap concern (#7). The !originAgentDir branch ensures plugin-refresh results are propagated to the requesting agent's store — without it, agent-scoped callers would silently miss refreshed tokens.
The mid-refresh re-authentication race is a pre-existing concern outside this PR's scope, as noted in #7. The extra write is intentional and necessary for correctness in the common case.
|
@tyler6204 @vincentkoc This PR is ready for review — all bot review conversations have been addressed, and the remaining CI failure (task-owner-access.test.ts timeout on Windows) is an infra-flaky issue unrelated to this change. Would appreciate a look when you get a chance. 🙏 |
|
Thanks, I landed a narrowed version of this directly on What shipped from the original direction:
What I intentionally left out:
Reason for the cut: the minimal refresh-recovery fix was clear and shippable on its own, while the larger PR was mixing that with adjacent profile-selection/store-topology problems. |
|
Thanks for the focused refresh-race fix. I am closing this as superseded by the merged Codex OAuth hardening in #68396 and the canonical issue closeout at #52037. The merged path includes shared OAuth refresh hardening, fresh-store reload/retry behavior, and Codex CLI bootstrap/auth-store coverage beyond this older PR. If you think a specific assertion from this PR is still missing on current |
Summary
Closes #26322.
Validation
AI Disclosure