Repository navigation
Conversation
Greptile SummaryThis PR adds mtime-based staleness detection to What changed:
Issues found:
The primary regression scenario (login while gateway is stopped) is well-covered by this fix; the race window is narrow enough that it would not affect the described repro in practice. Confidence Score: 4/5
Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/agents/auth-profiles/store.ts
Line: 57-62
Comment:
**IIFE adds unnecessary indirection**
The IIFE used for short-circuit evaluation on the agent-specific mtime check works correctly, but it's an unusual pattern here. A plain early assignment achieves the same result with less cognitive overhead:
```suggestion
const requestedMtime = requestedKey !== mainKey ? readAuthStoreMtimeMs(requestedKey) : null;
const isRequestedStale = requestedMtime !== null && requestedMtime > runtimeSnapshotsLoadedAtMs;
```
This avoids the self-calling arrow function and keeps both staleness checks visually parallel.
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/store.ts
Line: 63-68
Comment:
**Aggressive `loadedAuthStoreCache` eviction may be unnecessary**
When a stale runtime snapshot is detected, the code clears `loadedAuthStoreCache` as well. However, `loadedAuthStoreCache` is already mtime-aware — `readCachedAuthProfileStore` validates the cached entry's `mtimeMs` against the current file mtime, so it would self-invalidate naturally when the caller falls through to it.
Clearing it here can evict a *valid* `loadedAuthStoreCache` entry that was already populated with the newer file's mtime (e.g., if another code path loaded the updated file just before this staleness check ran), forcing a redundant disk read.
Consider only clearing `runtimeAuthStoreSnapshots` and `runtimeSnapshotsLoadedAtMs`:
```suggestion
runtimeAuthStoreSnapshots.clear();
runtimeSnapshotsLoadedAtMs = 0;
return null;
```
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/store.ts
Line: 98-101
Comment:
**Timestamp set after load creates a narrow staleness blind spot**
`runtimeSnapshotsLoadedAtMs` is stamped at the moment the in-memory map is written, but the actual disk reads that produced `entries` happen *before* `replaceRuntimeAuthProfileStoreSnapshots` is called. This means there is a window where:
1. Auth store is loaded from disk at time **T₁**
2. `openclaw models auth login` writes a fresh token at time **T₂** (T₁ < T₂)
3. `replaceRuntimeAuthProfileStoreSnapshots` runs at **T₃** (T₃ > T₂) and sets `runtimeSnapshotsLoadedAtMs = T₃`
4. Staleness check sees `disk_mtime (T₂) < runtimeSnapshotsLoadedAtMs (T₃)` → **stale write not detected**
The staleness check was designed to catch exactly this scenario, but the ordering means it misses any write that lands between the disk load and the map population.
A robust fix would capture the timestamp *before* the disk reads and thread it into this function:
```ts
// At call site, before loading entries from disk:
const snapshotTimestamp = Date.now();
// ... load entries ...
replaceRuntimeAuthProfileStoreSnapshots(entries, snapshotTimestamp);
```
```ts
export function replaceRuntimeAuthProfileStoreSnapshots(
entries: Array<{ agentDir?: string; store: AuthProfileStore }>,
loadedAtMs = Date.now(),
): void {
runtimeAuthStoreSnapshots.clear();
runtimeSnapshotsLoadedAtMs = loadedAtMs;
...
}
```
This is admittedly a narrow race window and would rarely trigger in the described repro scenario (gateway stopped → login → start), but it is exploitable in a running gateway if the startup sequence is slow.
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 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c9ded4af82
ℹ️ 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: f80fd244fb
ℹ️ 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".
|
Can someone review this Pull Request? Seems like a fix for users who are facing the bug #53317 |
|
Rebased onto latest main. |
f80fd24 to
fce4c60
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fce4c6035b
ℹ️ 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".
fce4c60 to
fdc78a7
Compare
|
Related work from PRtags group Title: auth: stale runtime snapshots overwrite OAuth tokens
|
fdc78a7 to
9d3c701
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9d3c701f67
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
9d3c701 to
71086a3
Compare
44173b4 to
25a370f
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 25a370f596
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@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: a2ad44685a
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Closing this as implemented after Codex review. Current What I checked:
So I’m closing this as already implemented rather than keeping a duplicate issue open. Review notes: reviewed against c070509b7f8f; fix evidence: release v2026.4.23, commit a9797214338b. |
Summary
resolveRuntimeAuthProfileStore()— before returning a cached snapshot, compare disk file mtime against snapshot load timestamp; invalidate on staleloadedAuthStoreCachemtime logic unchangedChange Type
Scope
Linked Issue
User-visible / Behavior Changes
OAuth tokens written by
openclaw models auth loginwhile gateway is stopped are no longer overwritten on startup.Security Impact (required)
NoYes— stale cached OAuth tokens are invalidated when the on-disk store is newer, preventing accidental credential rollbackNoNoNoRoot Cause
resolveRuntimeAuthProfileStore()returns the in-memory snapshot populated byreplaceRuntimeAuthProfileStoreSnapshots()on gateway startup, without checking if the on-disk file was modified since. The existingloadedAuthStoreCachehas mtime-based invalidation, butruntimeAuthStoreSnapshots(a separate cache layer) does not — and it takes priority.When
openclaw models auth loginwrites a fresh token toauth-profiles.jsonwhile 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.Repro + Verification
Environment
Steps
openclaw models auth login --provider openai-codex(fresh token written)auth-profiles.json— previously: old token restored; now: fresh token preservedExpected
Gateway uses the fresh token without overwriting it.
Actual (before fix)
Gateway writes stale January token back within 30 seconds of startup.
Evidence
npm run buildpasses (0 PARSE_ERROR)Human Verification (required)
readAuthStoreMtimeMs()correctly reads file mtime viafs.statSyncclearRuntimeAuthProfileStoreSnapshots()resets the timestampReview Conversations
Compatibility / Migration
YesNoNoFailure Recovery
Risks and Mitigations
statSynccall on everyresolveRuntimeAuthProfileStore()invocationstatSyncis sub-millisecond (kernel dentry cache), and this function is not called in tight loops. The performance cost is negligible compared to the security benefit.🤖 Generated with Claude Code