Repository navigation
fix(cache): keep private cache TTLs on elapsed time - #191606
Conversation
The CodexPluginMetadataCache measured its 60-minute window on the host wall clock while the entry is process-local. A wall-clock correction (NTP step, resume, VM restore) collapses or extends the window: a +1h step evicts a settled plugin catalog that still had ~59 minutes of real freshness left, re-issuing plugin/list against the upstream registry. Measure the window on elapsed time (performance.now) at both the write and the expiry comparison, matching the process-local elapsed-time cache shape already landed in usage-cache, the Discord entity cache, the GitHub detail cache, and the outbound directory cache. Co-Authored-By: nebulacoder-v8.0 <[email protected]>
…defect The wall-clock case previously loaded the cache before mocking Date.now, then returned a raw 1970 epoch (3_610_000 ms) that moved the clock backward instead of forward by one hour. The unchanged Date.now implementation therefore also served a cached entry and the regression could not detect the bug. Fix the initial wall reading before load and advance that same mock by more than the 60-minute TTL, so the case fails on main and passes on the elapsed-time head. Co-Authored-By: nebulacoder-v8.0 <[email protected]>
The in-process link-preview cache anchors its TTL on Date.now(); a wall-clock correction (NTP step, manual change, suspend/resume) extends or shortens the window. Anchor on performance.now() so the module-local cache ages by elapsed time. Compare and write in the same clock domain; no entry leaves the process.
The in-process CI check-details cache anchors its TTL on Date.now(); a wall-clock correction (NTP step, manual change, suspend/resume) extends or shortens the window. Anchor on performance.now() so the module-local cache ages by elapsed time. Compare and write in the same clock domain; no entry leaves the process.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Built Gateway RED → GREEN: all three private cache ownersFrozen main Secretless Linux The fixture starts with preview/check revision 1. After the no-step repeated-read controls, its upstream content changes to revision 2 and the Gateway receives a +61-minute process-local Date.now wall-clock step. This is not a system clock jump; the OS clock, performance.now and timers are untouched, matching #190894. Codex gets its own warm/no-step/stepped sequence after the core sequence's wall offset is reset. Exact observed counters (preview page fetches / CI jobs fetches / native plugin-installed RPCs): [
{"ref":"main","round":1,"warm":[1,1,1],"noStep":[1,1,1],"afterStep":[2,2,2],"preview":"Preview revision 2","check":"fixture-check-2"},
{"ref":"main","round":2,"warm":[1,1,1],"noStep":[1,1,1],"afterStep":[2,2,2],"preview":"Preview revision 2","check":"fixture-check-2"},
{"ref":"candidate","round":1,"warm":[1,1,1],"noStep":[1,1,1],"afterStep":[1,1,1],"preview":"Preview revision 1","check":"fixture-check-1"},
{"ref":"candidate","round":2,"warm":[1,1,1],"noStep":[1,1,1],"afterStep":[1,1,1],"preview":"Preview revision 1","check":"fixture-check-1"}
]Main prematurely expires all three still-fresh caches; the candidate holds each elapsed-time window. The Codex recorder is a transparent stdio relay to the real binary, not a fake app-server; it forwards requests/responses unchanged. A task-only synthetic managed OpenAI API-key profile and task-trusted CONNECT/TLS Responses fixture complete the turns without a real key or login. Link/GitHub responses are local final-HTTP-transport fixtures; request admission, DNS/SSRF policy and current principal/session/credential validation still execute unchanged. No live upstream service proof is claimed. Personally inspected Focused candidate suites 48/48 pass. Same existing elapsed-expiry fixtures on main: preview success/failure expiry cases fail with 2 rather than 4 fetches; Codex expiry case fails by retaining its snapshot; other 45 cases pass. This retains scope separation, SSRF/redirect guards, credential/generation isolation, revocation, retries, coalescing, invalidation and clear controls without growing tests. Oxfmt and Oxlint pass. Production +12/-8 (net +4); tests +3/-3 (net 0); docs +9. Container stopped after proof; no system clock changed. |
|
Codex review: needs maintainer review before merge. What this changesThis PR measures three private cache TTLs with elapsed time so host clock corrections cannot prematurely expire or prolong cached results. Example: A fresh plugin metadata snapshot is followed by a +61-minute process-local wall-clock step.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open for landing: it fixes a current cache-freshness defect with a focused change, and no actionable correctness or security findings remain. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherGateway preview and CI-detail readers and the Codex metadata reader cache upstream responses in memory; scoped callers receive cached responses until expiration or invalidation. flowchart TD
A[Control UI requests] --> B[Gateway cache owners]
C[Native Codex turns] --> D[Plugin metadata cache]
E[Elapsed clock] --> B
E --> D
B --> F[HTTP reads on cache miss]
D --> G[Codex RPCs on cache miss]
Technical reviewBest possible solution: Land the focused clock-domain repair using the existing cache owners and canonical core clock helper. Do we have a high-confidence way to reproduce the issue? Pinned main directly compares process-local cache deadlines against Date.now; the supplied production-entry receipt demonstrates premature expiry after a +61-minute wall-clock step, although this review executed no target code. Is this the best way to solve the issue? This is the smallest complete repair: each existing owner writes and compares deadlines in one elapsed-time domain, preserving TTLs, keys, coalescing, invalidation, and access checks. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against f75bd97cda9f. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +4, Tests 0, Docs +9. Total +13 across 8 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 2, 2026, 9:30 PM ET / November 3, 2026, 02:30 UTC. |
|
Landed in 022e70a. Thanks @wangmiao0668000666. These caches now expire by elapsed time across clock changes. |
|
Hi @obviyus — following up on this sweep: it absorbed #191575 and #191577 but excluded #191576 (the session branch-PR cache in #191576 is now rebased onto latest main ( |
fix: expire private caches by elapsed time, not the wall clock Three private caches measured their lifetime with `Date.now()`. When the system clock jumped forward, fresh entries were refetched early; when it moved back, stale entries were kept too long. These caches now use the monotonic clock. Auth, network guards and principal scope are unchanged. This sweep includes openclaw#191533, openclaw#191575 and openclaw#191577, with the contributor's commits kept for credit. Evidence: built Gateway in secretless Linux Node 24.22.1 Docker with public RPCs and real Codex 0.164.0 turns against local fixtures, stepping only the process wall clock (no system clock change). On main a +61-minute step refetched all three caches early, twice; with this change all three kept their fresh entries twice. No-step controls passed, and all 12 native turns completed. Details: openclaw#191606 (comment). Thanks @wangmiao0668000666. Co-authored-by: wangmiao0668000666 <wangmiao0668000666> Co-authored-by: nebulacoder-v8.0 <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
fix: keep the branch pull-request cache deadline on elapsed time The branch pull-request cache still measured its deadline with the wall clock, which was missed in the #191606 sweep. After the clock moved, the branch snapshot expired early. The deadline now uses the monotonic clock. Behavior without a clock change is unchanged. Evidence: built Gateway with real Git and a WebSocket subscription, stepping only the process wall clock (no system clock change). Main expired the branch snapshot early twice; with this change the correct deadline was kept twice, rechecked on the final head. No-step controls passed. Details: #191576 (comment) and #191576 (comment). Thanks @wangmiao0668000666. Co-authored-by: nebulacoder-v8.0 <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
…aw#191576) fix: keep the branch pull-request cache deadline on elapsed time The branch pull-request cache still measured its deadline with the wall clock, which was missed in the openclaw#191606 sweep. After the clock moved, the branch snapshot expired early. The deadline now uses the monotonic clock. Behavior without a clock change is unchanged. Evidence: built Gateway with real Git and a WebSocket subscription, stepping only the process wall clock (no system clock change). Main expired the branch snapshot early twice; with this change the correct deadline was kept twice, rechecked on the final head. No-step controls passed. Details: openclaw#191576 (comment) and openclaw#191576 (comment). Thanks @wangmiao0668000666. Co-authored-by: nebulacoder-v8.0 <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
The active-memory recall cache measured its TTL with the wall clock, so a backwards clock step kept stale recall results past their TTL: a repeated prompt within a session returned the previous turn's memory summary instead of searching again until the step elapsed. Cache expiry now runs on `performance.now()`, matching the elapsed-time caches in other extensions. The test fixture that forces expiry advances the same clock so its intent is unchanged. Sweep of the elapsed-cache family (openclaw#191606, openclaw#192700, openclaw#193147).
The shared provider live catalog cache measured its TTL with the wall clock, so a backwards clock step kept stale catalogs past their TTL: provider model rows and the shared upstream metadata feed kept serving an expired answer and new or retired models did not refresh until the step elapsed. Cache expiry now runs on elapsed time. The deadline recorded for catalog expiries stays on the wall clock because its consumers compare it to Date.now(), so expiry and the published deadline keep separate fields. Sweep of the elapsed-cache family (openclaw#191606, openclaw#192700, openclaw#193147).
The catalog tree watch arms its restart backoff with Date.now(), so a wall-clock correction can postpone or accelerate the retry: rolling the clock back keeps an unavailable watch un-retried (every read degrades to a full rescan), while a forward step retries early. Measure the 5s retry deadline with performance.now(), matching the elapsed-time sweep shape (openclaw#191606).
What Problem This Solves
A wall-clock correction can prematurely expire or extend three private in-memory cache windows: native Codex plugin metadata, Control UI link previews, and session CI check details.
User Impact
A host clock correction no longer triggers unnecessary native plugin discovery, preview downloads, or CI job-detail fetches while their elapsed-time windows are still fresh. TTL values, retry delays, authentication, network guards, principal/session/credential scope, and explicit invalidation are unchanged. No configuration or migration.
Why This Change Was Made
Keep expiry writes and reads in one elapsed-time domain: the existing
monotonicNow()owner in core, andperformance.now()inside the Codex extension. These private readings never leave their caches and are not persisted as wall-clock timestamps.Includes #191533, #191575 and #191577. The original commits by wangmiao0668000666 are cherry-picked for credit, including the contributor's regression-fixture correction. #191576 and #191210 are intentionally excluded; no source PR is closed by this PR.
Evidence
Exact runtime counters and proof receipt.
Built both Gateway/CLI artifacts on Linux in secretless
node:24.22.1Docker. Frozen main913f025cd15ba79d4002ad4e6db1fe2739ba8f8f; candidate production artifactc772becb16e5f64fd022c0bcd814a4eaf54b4d1a(final follow-up changes tests/docs and formatting only).Four fresh-profile runs, main twice and candidate twice, through authenticated public Gateway RPCs and real native Codex turns:
plugin/installed; next fresh session reuses itplugin/installedplugin/installedAll 12 native Codex turns completed and returned
CACHE_TURN_OK. The real bundled Codex app-server talks to a task-only synthetic managed API-key profile and a local trusted CONNECT/TLS Responses fixture. A transparent stdio recorder forwards bytes unchanged and records actual plugin RPCs. Link/GitHub HTTP transports are local fixtures at the final fetch boundary; production request admission, DNS/SSRF checks, credentials and scope logic remain unchanged. This is not a live upstream service claim.Clock method: the same preload approach as #190894 steps only the Gateway process's
Date.now()by +61 minutes. This is a process-local wall-clock step, not a system clock jump.performance.now(), timers and the operating-system clock are not altered.Personally inspected native Codex source at
ce0323f2f2d3b25e82806cd555237da3db4e1897: plugin request/response contracts and catalog processing/background refresh. OpenClaw's fail-open/cacheable guard is unchanged.Focused existing suites: candidate 48/48 pass (42 Gateway + 6 Codex). Same updated expiry tests on main: two intended preview expiry failures and one intended Codex expiry failure; remaining 45 pass. Existing scope, network, coalescing, revocation, retry and invalidation controls retained. Targeted formatting and Oxlint pass. Tests net 0; no allocations or SDK exports.
Merge Danger
Two-way door: reverting restores the old private clock comparisons without a state migration. Blast radius is cache reuse for native Codex plugin metadata, link previews and session CI details; no permission or network policy changes.