Repository navigation
fix: sync runtimeAuthStoreSnapshots on save to prevent stale OAuth tokens (#55389) - #55465
factnest365-ops wants to merge 11 commits into
Conversation
Greptile SummaryThis PR fixes a well-described OAuth token staleness bug where Confidence Score: 5/5Safe to merge — the fix is minimal, targeted, and directly addresses the documented root cause with no regressions. Single-file change with a clean, guarded update that only affects stores already registered in the runtime snapshot map. The choice of store over payload is correct and future-proof. No new code paths are introduced, and the guard prevents unintended snapshot creation. No files require special attention.
|
| Filename | Overview |
|---|---|
| src/agents/auth-profiles/store.ts | Adds runtime snapshot sync in saveAuthProfileStore() to prevent stale OAuth tokens after token rotation; uses the unsanitized store rather than the disk payload, which is the correct choice to preserve in-memory credentials. |
Reviews (1): Last reviewed commit: "fix: sync runtimeAuthStoreSnapshots on s..." | Re-trigger Greptile
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 48cd3c6059
ℹ️ 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 (runtimeAuthStoreSnapshots.has(runtimeKey)) { | ||
| runtimeAuthStoreSnapshots.set(runtimeKey, cloneAuthProfileStore(store)); |
There was a problem hiding this comment.
Preserve resolved secrets when syncing runtime auth snapshots
saveAuthProfileStore now overwrites runtimeAuthStoreSnapshots with the passed store, but lock-based writers call it with a store reloaded from disk (updateAuthProfileStoreWithLock), and disk persistence intentionally strips plaintext key/token when keyRef/tokenRef is present. In an active secrets runtime snapshot, a normal usage/cooldown write can therefore replace resolved in-memory credentials with unresolved refs, so later ensureAuthProfileStore() calls no longer return the frozen resolved value and must re-resolve (or fail if file/exec/env refs are unavailable), which is a runtime regression introduced by this sync path.
Useful? React with 👍 / 👎.
| if (runtimeAuthStoreSnapshots.has(runtimeKey)) { | ||
| runtimeAuthStoreSnapshots.set(runtimeKey, cloneAuthProfileStore(store)); |
There was a problem hiding this comment.
Sync active snapshot state when mutating runtime auth map
This update only mutates runtimeAuthStoreSnapshots, but getActiveSecretsRuntimeSnapshot() still returns stale activeSnapshot.authStores; on gateway hot-reload failure, src/gateway/server.impl.ts restores previousSnapshot via activateSecretsRuntimeSnapshot(previousSnapshot), which repopulates the runtime auth map from those stale auth stores and can roll back freshly refreshed OAuth tokens in memory. That rollback path is now inconsistent specifically because this commit introduced one-sided snapshot mutation.
Useful? React with 👍 / 👎.
- Add owner-only tools section to tools/index.md (gateway, cron, nodes) - Fix /help/faq#where-does-openclaw-store-its-data -> #where-things-live-on-disk - Fix exec-approvals channel links (headings no longer exist) - Fix docker sandbox anchor (heading renamed) Ref: openclaw#50828
Fix Vercel/Venice order in docs/providers/index.md Vercel should come before Venice alphabetically Ref: openclaw#50826
…kens saveAuthProfileStore() writes refreshed tokens to disk and file cache but never updates runtimeAuthStoreSnapshots. Since ensureAuthProfileStore() checks the runtime snapshot first, subsequent API calls read stale tokens containing the consumed (rotated) refresh token. After the first OAuth refresh succeeds (which rotates the refresh token server-side), the second refresh always fails with invalid_grant because the runtime snapshot still holds the consumed refresh token. The fix clones the full store (not the sanitized disk payload) into runtimeAuthStoreSnapshots when a snapshot entry exists, keeping the in-memory cache in sync with disk after every save. Fixes openclaw#55389
48cd3c6 to
9551663
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 955166325f
ℹ️ 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".
| ...resolveManifestProviderSetupFlowContributions({ | ||
| ...params, | ||
| scope: "text-inference", | ||
| }).map((contribution) => contribution.option.value), |
There was a problem hiding this comment.
Avoid loading provider plugins when building auth-choice help
formatAuthChoiceChoicesForCli now calls resolveManifestProviderSetupFlowContributions, which in turn resolves provider docs via runtime provider loading (resolvePluginProviders) before returning simple choice ids. This path is used to build static CLI help text at startup (for onboard --auth-choice), so every CLI run now does plugin loading work and can surface plugin-load side effects/errors even when onboarding is not being used. Please keep this helper on a manifest-only path (or skip docs resolution here) so help generation stays lightweight and side-effect free.
Useful? React with 👍 / 👎.
|
Closing this as implemented after Codex review. Close. Current What I checked:
So I’m closing this as already implemented rather than keeping a duplicate issue open. Review notes: reviewed against d3d9b5738f83; fix evidence: release v2026.4.22, commit 00bd2cf7a376. |
Summary
Fixes OAuth token refresh failure that occurs after the second refresh attempt (~16 hours after gateway startup).
Root Cause
saveAuthProfileStore()writes refreshed OAuth tokens to disk and the file cache, but never updatesruntimeAuthStoreSnapshots. SinceensureAuthProfileStore()checks the runtime snapshot first (and returns a clone if it exists), all subsequent API calls read stale tokens containing the consumed (rotated) refresh token.Token rotation lifecycle (broken):
runtimeAuthStoreSnapshots(refresh token =R1)R2saveAuthProfileStorewritesR2to disk and file cache ✅R1(consumed/invalidated by provider) ❌ensureAuthProfileStore→ returns snapshot clone withR1R1→invalid_grant❌Fix
After writing to disk and cache, update
runtimeAuthStoreSnapshotsif a snapshot entry exists for the agent directory. UsescloneAuthProfileStore(store)(the full unsanitized store) rather thancloneAuthProfileStore(payload)(the sanitized disk version) to preserve credentials needed for API calls.Impact
All OAuth-authenticated providers (Anthropic, OpenAI Codex, etc.) stop working ~16 hours after gateway startup. This fix ensures the in-memory snapshot stays in sync with disk after every token refresh.
Fixes #55389