Skip to content

fix/53317-gateway-overwrites-oauth-token - #53754

Closed
luoxiao6645 wants to merge 18 commits into
openclaw:mainfrom
luoxiao6645:fix/53317-gateway-overwrites-oauth-token
Closed

luoxiao6645 wants to merge 18 commits into
openclaw:mainfrom
luoxiao6645:fix/53317-gateway-overwrites-oauth-token

Conversation

@luoxiao6645

@luoxiao6645 luoxiao6645 commented Mar 24, 2026 •

Copy link
Copy Markdown

Summary

Problem: Gateway overwrites fresh OAuth tokens with stale cached state on startup, burning single-use refresh tokens and blocking all Codex requests.
Why it matters: 100% reproducible regression that completely breaks openai-codex provider usage on v2026.3.22+.
What changed: Added mtime-based staleness detection to resolveRuntimeAuthProfileStore() — before returning a cached snapshot, compare disk file mtime against snapshot load timestamp; invalidate on stale. Includes multiple fixes for edge cases:

  • Per-path mtime tracking (instead of global earliest mtime)
  • Clear stale mtime keys when agent is removed
  • Record mtime at prepare time (not activation) to close race window
  • Update mtime after self-induced writes
  • Preserve resolved secrets in runtime snapshot after save

Change Type

  • Bug fix
  • Security hardening

Scope

  • Auth / tokens

Linked Issue

Fixes #53317

User-visible / Behavior Changes

OAuth tokens written by openclaw models auth login while gateway is stopped are no longer overwritten on startup.

Root Cause

resolveRuntimeAuthProfileStore() returns the in-memory snapshot populated by replaceRuntimeAuthProfileStoreSnapshots() on gateway startup, without checking if the on-disk file was modified since. The existing loadedAuthStoreCache has mtime-based invalidation, but runtimeAuthStoreSnapshots (a separate cache layer) does not — and it takes priority.
When openclaw models auth login writes a fresh token to auth-profiles.json while the gateway is stopped, the next gateway startup loads the old snapshot, and any subsequent write-back (usage stats, profile sync) overwrites the fresh token.

Additional Fixes (Reviewer Feedback)

  1. Per-path mtime tracking: Each agent now tracks its own mtime independently, preventing incorrect invalidation when different agents have different file timestamps.
  2. Stale key cleanup: Clear mtime keys from prior activations to prevent removed agents from causing false positives.
  3. Prepare-time mtime recording: Record mtime when store is read in prepareSecretsRuntimeSnapshot(), not during activation, closing the race window between prepare and activate.
  4. Self-induced write handling: Update both mtime and snapshot after saveAuthProfileStore() to prevent false staleness detection from gateway's own writes.
  5. Preserve resolved secrets: Write original store (with resolved key/token) to runtime snapshot, not sanitized payload.

Repro + Verification

Steps:

  1. Stop gateway
  2. Run openclaw models auth login --provider openai-codex (fresh token written)
  3. Start gateway
  4. Check auth-profiles.json — previously: old token restored; now: fresh token preserved

Verification

  • TypeScript type check ✓
  • Lint ✓
  • Tests: oauth.test.ts ✓, runtime-snapshot-save.test.ts ✓, secrets/runtime.test.ts ✓, runtime-snapshot-staleness.test.ts ✓

Compatibility / Migration

  • Backward compatible: Yes
  • Config/env changes: No
  • Migration needed: No

Failure Recovery

Revert the commit to restore previous behavior.

Risks and Mitigations

Risk: Additional statSync call on every resolveRuntimeAuthProfileStore() invocation.
Mitigation: statSync is sub-millisecond (kernel dentry cache), and this function is not called in tight loops. The performance cost is negligible compared to the security benefit.

…file is newer

Problem:
Gateway overwrites fresh OAuth tokens with stale cached state on startup,
burning single-use refresh tokens and blocking all Codex requests.

Root cause:
resolveRuntimeAuthProfileStore() returns in-memory snapshots without
checking if on-disk auth-profiles.json was modified after snapshot load.

Fix:
- Add runtimeSnapshotsLoadedAtMs timestamp to track snapshot load time
- In replaceRuntimeAuthProfileStoreSnapshots(), record timestamp BEFORE
  populating the map to eliminate race window
- In resolveRuntimeAuthProfileStore(), compare disk file mtime against
  snapshot load timestamp; invalidate on stale
- Only clear runtimeAuthStoreSnapshots (not loadedAuthStoreCache, which
  already has mtime-based invalidation)

Fixes openclaw#53317
@luoxiao6645
luoxiao6645 requested a review from a team as a code owner March 24, 2026 14:57
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Mar 24, 2026
@luoxiao6645

Copy link
Copy Markdown
Author

@codex review

@greptile-apps

greptile-apps Bot commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds mtime-based staleness detection to resolveRuntimeAuthProfileStore() in src/agents/auth-profiles/store.ts to prevent stale in-memory runtime snapshots from overwriting freshly-written OAuth tokens. A new module-level runtimeSnapshotsLoadedAtMs timestamp is recorded whenever replaceRuntimeAuthProfileStoreSnapshots() is called; on every subsequent resolveRuntimeAuthProfileStore() call, the on-disk file's mtime is compared against that timestamp — if the file is newer, the snapshot is invalidated and callers fall through to a fresh disk read.

Changes:

  • Adds runtimeSnapshotsLoadedAtMs variable initialized to 0 and reset on clearRuntimeAuthProfileStoreSnapshots()
  • In resolveRuntimeAuthProfileStore(): two new mtime-gated invalidation blocks — one for the main auth path (always checked) and one for the agent-specific path (checked only when it differs from main)
  • In replaceRuntimeAuthProfileStoreSnapshots(): runtimeSnapshotsLoadedAtMs = Date.now() is set before clearing and repopulating the map, so writes that occur during the population loop are also caught on the next check
  • The fix is correct and effective for the primary race: an external token write (openclaw models auth login) that occurs while the gateway is already running and has a cached snapshot

Potential concern:
The comment on the new timestamp assignment claims it catches writes "between 'load from disk' and 'stamp here'", but the actual disk reads occur inside prepareSecretsRuntimeSnapshot — well before activateSecretsRuntimeSnapshot calls this function. Writes in that window have mtime < runtimeSnapshotsLoadedAtMs and are not detected. What pre-population stamping actually buys is catching writes that occur during map population, not before it. The comment should be corrected to avoid misleading future maintainers.

Confidence Score: 4/5

  • Safe to merge — single-file change with correct staleness-detection logic; the only issue is a misleading comment on the new timestamp line.
  • The core logic (mtime-based snapshot invalidation) is sound and matches the existing pattern used by loadedAuthStoreCache. The statSync overhead is acknowledged and negligible. The sole concern is a factually inaccurate inline comment that mischaracterises which race window the pre-population timestamp protects against; this doesn't affect correctness but could mislead future maintainers. No new failure modes are introduced.
  • No files require special attention beyond correcting the comment in src/agents/auth-profiles/store.ts at the runtimeSnapshotsLoadedAtMs = Date.now() assignment.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/agents/auth-profiles/store.ts
Line: 104-107

Comment:
**Misleading comment about what the pre-population timestamp prevents**

The comment says: *"any disk writes that happen between 'load from disk' and 'stamp here' are still detected as stale (the mtime will be >= this timestamp)"* — but this is the opposite of what actually happens.

The disk reads occur in `prepareSecretsRuntimeSnapshot` (via `loadAuthStore(agentDir)` for each agent dir), which completes well before `activateSecretsRuntimeSnapshot` calls `replaceRuntimeAuthProfileStoreSnapshots`. Any write with `mtime < runtimeSnapshotsLoadedAtMs` (i.e. writes between the disk read and this timestamp) will **not** be detected as stale — the condition `mainMtime > runtimeSnapshotsLoadedAtMs` will be `false`.

What setting the timestamp **before** map population actually achieves is: any write that occurs **during or after** the map-population loop (steps between `Date.now()` and the end of the `for` loop) will have `mtime >= timestamp` and will be detected on the next check. If the timestamp were set *after* populating, writes during population would be missed.

A more accurate comment:

```suggestion
  // Record timestamp BEFORE populating the map so that any disk writes
  // that occur during or after map population are detected as stale on
  // the next resolveRuntimeAuthProfileStore() call (mtime will be >= this timestamp).
  // Note: writes between the upstream disk read and this point are NOT caught —
  // that is an inherent limitation of mtime-based invalidation without holding a
  // file lock across the entire prepare→activate sequence.
  runtimeSnapshotsLoadedAtMs = Date.now();
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "fix(auth): invalidate stale runtime auth..." | Re-trigger Greptile

Comment thread src/agents/auth-profiles/store.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4b475cfa66

ℹ️ 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".

Comment thread src/agents/auth-profiles/store.ts Resolved
Read the earliest mtime across all auth store files at activation time
instead of using Date.now(). This ensures that any file update that
landed before replaceRuntimeAuthProfileStoreSnapshots() is detected as
stale, closing the window between prepareSecretsRuntimeSnapshot's disk
reads and this function call.
@luoxiao6645

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ddc182ea6b

ℹ️ 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".

Comment thread src/agents/auth-profiles/store.ts Resolved
@steipete

Copy link
Copy Markdown
Contributor

I dug through this one again because the user-visible symptom is real and severe, but I don't think it's ready to land as-is.

Two blockers:

  1. The new invalidation logic in src/agents/auth-profiles/store.ts tracks one global earliest mtime / load timestamp across runtime snapshots. That means a different auth store with a later mtime can immediately invalidate an otherwise-correct runtime snapshot. The current red Windows failure on src/secrets/runtime.integration.test.ts looks consistent with that behavior.

  2. The PR still doesn't add a regression test for the exact startup race from Bug: Gateway overwrites fresh OAuth token with stale cached state on startup (v2026.3.22, openai-codex) #53317:

    • stop gateway
    • write fresh OAuth token to disk
    • start gateway
    • verify no later write-back restores the stale token

I think the right next step is:

  • track invalidation per store path instead of one global earliest mtime
  • add the startup-race regression test above
  • rerun CI, then re-review

I would keep the PR open, but I would not merge this revision.

- Track mtime per auth store path instead of global earliest mtime
- Prevents incorrect invalidation when different agents have different mtimes
- Add regression tests for startup race condition (openclaw#53317)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 59eb171b9e

ℹ️ 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".

Comment thread src/agents/auth-profiles/store.ts Resolved
Clear runtimeSnapshotMtimes before populating fresh entries to prevent
removed agent paths from causing false-positive staleness detection.
- Test stale mtime key cleanup when agent is removed
- Test handling of non-existent auth-profiles.json
- Covers 5 test scenarios for per-path mtime tracking

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3aeef80b7f

ℹ️ 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".

Comment thread src/agents/auth-profiles/store.ts Resolved
- Add authStoreMtimes to PreparedSecretsRuntimeSnapshot type
- Record mtime when loadAuthStore() reads the store in prepareSecretsRuntimeSnapshot()
- Pass snapshotMtimes to replaceRuntimeAuthProfileStoreSnapshots() to close the
  prepare->activate race window where external file modifications could pair stale
  in-memory stores with newer on-disk mtimes, causing invalid credentials to be saved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3aeef80b7f

ℹ️ 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".

Comment thread src/agents/auth-profiles/store.ts Resolved
After saveAuthProfileStore() writes to disk, update runtimeSnapshotMtimes
to the new mtime. This prevents self-induced file updates (e.g. usage-stat
writes) from triggering false-positive staleness detection that would clear
the runtime snapshot and lose runtime-resolved secret values.
…Store

Also update runtimeAuthStoreSnapshots when saveAuthProfileStore writes to disk
to ensure subsequent ensureAuthProfileStore() calls return the newly saved content
rather than stale in-memory data. Combined with the mtime update, this prevents
self-induced writes from triggering false staleness detection.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 229fc1ff58

ℹ️ 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".

Comment thread src/agents/auth-profiles/store.ts Resolved
Write original store (with resolved key/token) to runtimeAuthStoreSnapshots,
not the sanitized payload (which strips keyRef/tokenRef values). This preserves
runtime-resolved secret values after save operations.
@luoxiao6645

Copy link
Copy Markdown
Author

@steipete Thanks for the review
Both blockers have been addressed:
Blocker 1 (per-path mtime): Fixed in commit 59eb171. Changed from global runtimeSnapshotsLoadedAtMs to runtimeSnapshotMtimes Map that tracks mtime per auth store path independently. This prevents a different auth store with a later mtime from incorrectly invalidating valid snapshots.
Blocker 2 (regression test): Added in runtime-snapshot-staleness.test.ts with 6 tests covering:

  • External file modification detection
  • Valid snapshot preservation
  • Multi-agent per-path staleness
  • Stale key cleanup when agent is removed
  • Non-existent file handling
  • Self-induced write handling
    All tests pass locally. Ready for re-review.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 38c4ffd601

ℹ️ 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".

Comment thread src/secrets/runtime.ts Resolved
Comment thread src/agents/auth-profiles/store.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d8e30cec9f

ℹ️ 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".

Comment thread src/agents/auth-profiles/store.ts Resolved
Comment thread src/agents/auth-profiles/store.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 03485b9c00

ℹ️ 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".

Comment thread src/agents/auth-profiles/store.ts Resolved
@luoxiao6645

Copy link
Copy Markdown
Author

@steipete please review again

…ain-sync

# Conflicts:
#	src/agents/auth-profiles.markauthprofilefailure.test.ts
#	src/agents/auth-profiles/store.ts
#	src/secrets/runtime.integration.test.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3a839b68ac

ℹ️ 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".

Comment thread src/agents/auth-profiles/store.ts Outdated
Comment on lines +107 to +109
if (requestedMtime !== null && requestedMtime > requestedLoadedMtime) {
invalidateRuntimeAuthProfileStoreSnapshot(agentDir);
return null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve main runtime secrets when agent snapshot turns stale

When a subagent auth file has a newer mtime, this path invalidates only that agent snapshot and returns null, which forces ensureAuthProfileStore(agentDir) down the disk-load path for both agent and main stores. In an active secrets runtime, main credentials resolved from keyRef/tokenRef can exist only in the in-memory runtime snapshot, so this fallback can drop usable main credentials for that agent until a full runtime snapshot rebuild, causing auth failures after an external subagent auth write.

Useful? React with 👍 / 👎.

@openclaw-barnacle openclaw-barnacle Bot added the app: macos App: macos label Apr 10, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fa17899d10

ℹ️ 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".

Comment on lines +113 to +114
invalidateRuntimeAuthProfileStoreSnapshot(agentDir);
return null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve main runtime secrets after stale-agent invalidation

When an agent-specific auth file is detected as stale, this branch invalidates that agent snapshot and immediately returns null, which forces ensureAuthProfileStore(agentDir) down the disk-load path even if the main runtime snapshot is still valid. In secrets-runtime flows where main credentials are resolved only in memory (for example keyRef/tokenRef profiles whose plaintext value is intentionally not persisted), that fallback drops usable main credentials for the agent after any external edit to the agent store. Fresh evidence in this commit is the new early return after invalidateRuntimeAuthProfileStoreSnapshot(agentDir), together with the stale-key guard that prevents main-snapshot fallback.

Useful? React with 👍 / 👎.

@prtags

prtags Bot commented Apr 23, 2026

Copy link
Copy Markdown

Related work from PRtags group apt-oryx-nhva

Title: auth: stale runtime snapshots overwrite OAuth tokens

Number Title
#53317 Title unavailable
#53367 fix(auth): invalidate stale runtime auth-profile snapshots when disk file is newer
#53754* fix/53317-gateway-overwrites-oauth-token
#68866 fix(auth): invalidate stale runtime auth snapshots when auth files change

* This PR

@steipete

Copy link
Copy Markdown
Contributor

Closing this as implemented after Codex review.

Current main already fixes the stale-auth overwrite behavior through locked disk reloads and runtime-snapshot refreshes, with direct regression coverage for the stale-in-memory/fresh-on-disk case this PR targets.

What I checked:

  • Locked auth-store writers reload from disk: updateAuthProfileStoreWithLock() acquires the auth file lock and reloads the persisted store with loadAuthProfileStoreForAgent() before saving; the inline comment explicitly says this prevents live gateway writes from overwriting fresher CLI/config-auth state with stale in-memory auth. (src/agents/auth-profiles/store.ts:127, 8f64cd3e4d83)
  • Failure write-back path uses the locked reload path: markAuthProfileFailure() now routes its write-back through updateAuthProfileStoreWithLock(), so cooldown/usage updates no longer persist whatever stale auth snapshot the caller happened to hold. (src/agents/auth-profiles/usage.ts:656, 8f64cd3e4d83)
  • OAuth refresh path also reloads persisted credentials under lock: The locked OAuth refresh flow reads loadAuthProfileStoreForSecretsRuntime() inside the auth-store lock before deciding whether to refresh or adopt credentials, which is the exact restart/relogin stale-cache class described in the PR. (src/agents/auth-profiles/oauth-manager.ts:315, 8f64cd3e4d83)
  • Direct regression test for fresh-on-disk vs stale-runtime store: Current main includes a test that writes a fresh token to auth-profiles.json, keeps a stale in-memory store, calls markAuthProfileFailure(), and asserts the fresh on-disk token survives instead of being overwritten. (src/agents/auth-profiles.markauthprofilefailure.test.ts:76, 8f64cd3e4d83)
  • Shipped release notes already describe this fix class: The changelog already records shipped fixes for stale auth writes and stale cached Codex OAuth recovery, including Auth/OpenAI tokens: stop live gateway auth-profile writes from reverting freshly saved credentials back to stale in-memory values and reload fresh on-disk credentials inside the locked refresh path ... so relogin/restart recovery stops getting stuck on stale cached auth state. (CHANGELOG.md:2158, 8f64cd3e4d83)

So I’m closing this as already implemented rather than keeping a duplicate issue open.

Review notes: reviewed against 8f64cd3e4d83.

@steipete steipete closed this Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: macos App: macos size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Gateway overwrites fresh OAuth token with stale cached state on startup (v2026.3.22, openai-codex)

3 participants