Skip to content

fix(cache): keep private cache TTLs on elapsed time - #191606

Merged
obviyus merged 6 commits into
mainfrom
fix/private-cache-monotonic-sweep
Nov 3, 2026
Merged

obviyus merged 6 commits into
mainfrom
fix/private-cache-monotonic-sweep

Conversation

@obviyus

@obviyus obviyus commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

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, and performance.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.1 Docker. Frozen main 913f025cd15ba79d4002ad4e6db1fe2739ba8f8f; candidate production artifact c772becb16e5f64fd022c0bcd814a4eaf54b4d1a (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:

Cache No-step control, all runs Main after +61-minute wall step, twice Candidate after same step, twice
Link preview One page fetch; repeated read reuses revision 1 Premature refetch, revision 2 One fetch retained; revision 1
CI check details One jobs request; repeated read reuses check 1 Premature jobs refetch, check 2 One jobs request retained; check 1
Codex plugin metadata One real plugin/installed; next fresh session reuses it Third real turn issues a second plugin/installed Third real turn retains one plugin/installed

All 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.

wangmiao0668000666 and others added 6 commits November 3, 2026 07:08
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.
@clawsweeper

clawsweeper Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@obviyus

obviyus commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime extensions: codex size: XS labels Nov 3, 2026
@obviyus

obviyus commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator Author

Built Gateway RED → GREEN: all three private cache owners

Frozen main 913f025cd15ba79d4002ad4e6db1fe2739ba8f8f; built candidate production code c772becb16e5f64fd022c0bcd814a4eaf54b4d1a. Final changes only consolidate tests, document behavior and format one expression. Includes #191533, #191575 and #191577; excludes #191576 and #191210. Contributor commits retained by cherry-pick.

Secretless Linux node:24.22.1, fresh private state/config/profile per run, exact built-CLI config and database path probes. Public Gateway RPCs controlUi.linkPreview and controlUi.sessionPullRequests.checks ran with the same live client and admitted real session/Git checkout. The native case uses three fresh sessions per run, the real bundled Codex 0.164.0 app-server and real plugin/installed JSON-RPC. Every native turn completed with CACHE_TURN_OK (12/12 turns).

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 ~/Developer/codex at ce0323f2f2d3b25e82806cd555237da3db4e1897, especially plugin request/response types, catalog processing, and custom CA handling. No auth, network-guard, principal-scope or fail-open guard changes.

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.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 3, 2026
@clawsweeper

clawsweeper Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This 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.

  • Before: The next native Codex turn issues a second plugin/installed request.
  • After: The next turn reuses the snapshot until its actual 60-minute freshness window expires.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused owner-level repair with applicable production-entry evidence, retained expiry tests, green exact-head gates, and no findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The inspected runtime receipt exercises all three cache owners through built Gateway RPCs and real native Codex turns in secretless Linux containers, recording baseline refetches and candidate reuse after the same process-local wall-clock step; the final head preserves that production behavior.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Clock corrections can trigger redundant plugin discovery, preview downloads, and CI-detail fetches, or retain stale results beyond their intended windows.
Reason: The maintainer-authored direction repairs the existing freshness contract with negligible complexity and no new user-facing controls.

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
Reviewed head: caaa2a532be32371629f7664d44297b29944c084

Before merge

None.

Findings

None.

Agent review details

How this fits together

Gateway 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]
Loading

Technical review

Best 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

  • Codex plugin metadata freshness keeps the original intent (9d4610c: Bound discovery while allowing settled negative catalog results to expire as upstream catalogs refresh; later cleanup removed unused private clock injection.)
  • Link-preview cache keeps the original intent (021fd34: Provide bounded anonymous public-page previews with scoped caching and network guards.)
  • Session CI check details keeps the original intent (fd86e04: Load detailed CI jobs on demand while binding responses to the session, PR, and commit; later enterprise work retained host and credential isolation.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 9d4610c adds extensions/codex/src/app-server/plugin-metadata-cache.ts:71 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 9d4610cbd102; files: extensions/codex/src/app-server/plugin-metadata-cache.ts)

PR surface

Source +4, Tests 0, Docs +9. Total +13 across 8 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 12 8 +4
Tests 3 3 3 0
Docs 2 9 0 +9
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 24 11 +13

Review metrics

Metric Value Why it matters
Production versus test LOC Production +12/-8; tests +3/-3 The small production increase consists of existing clock-helper imports, explanatory comments, and formatting; existing expiry coverage is retained without test growth.

Labels

Label changes:

  • add P2: Host clock corrections can cause unnecessary upstream requests or stale cache results, with limited blast radius and no demonstrated outage.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Host clock corrections can cause unnecessary upstream requests or stale cache results, with limited blast radius and no demonstrated outage.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 2, 2026, 9:30 PM ET / November 3, 2026, 02:30 UTC.

@obviyus
obviyus merged commit 022e70a into main Nov 3, 2026
152 checks passed
@obviyus

obviyus commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in 022e70a. Thanks @wangmiao0668000666. These caches now expire by elapsed time across clock changes.

@wangmiao0668000666

Copy link
Copy Markdown
Contributor

Hi @obviyus — following up on this sweep: it absorbed #191575 and #191577 but excluded #191576 (the session branch-PR cache in control-ui-session-prs.ts), which still keeps all five Date.now() reads on main.

#191576 is now rebased onto latest main (f4b1e4729d2), CI is fully green (including checks-node-changed-compact-large-13, after I fixed the retention-fixture P2 — the 61s wall-clock step now also advances the mocked performance.now() elapsed clock so the 5-minute rate-limit backoff stays alive). Same elapsed-time shape as this PR (#190894/#190997). Happy to fold it in or add whatever proof you'd like — just didn't want it to slip through as the one remaining same-shape cache window.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 3, 2026
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]>
obviyus added a commit that referenced this pull request Nov 3, 2026
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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 4, 2026
…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]>
wangmiao0668000666 added a commit to wangmiao0668000666/openclaw that referenced this pull request Nov 5, 2026
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).
wangmiao0668000666 added a commit to wangmiao0668000666/openclaw that referenced this pull request Nov 5, 2026
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).
wangmiao0668000666 added a commit to wangmiao0668000666/openclaw that referenced this pull request Nov 6, 2026
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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: codex gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants