Skip to content

fix(anthropic): measure session catalog TTLs against monotonic time - #192122

Closed
wangmiao0668000666 wants to merge 3 commits into
openclaw:mainfrom
wangmiao0668000666:fix/anthropic-catalog-elapsed
Closed

wangmiao0668000666 wants to merge 3 commits into
openclaw:mainfrom
wangmiao0668000666:fix/anthropic-catalog-elapsed

Conversation

@wangmiao0668000666

@wangmiao0668000666 wangmiao0668000666 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

The Anthropic session catalog keys its hard-scan tree backstop, its Desktop overlay refresh TTL, and its CLI-scan cache deadline with Date.now(). A wall-clock correction (NTP step or manual change) can stretch or shorten those elapsed-time TTLs: rolling the clock back keeps a stale tree snapshot "fresh" past its five-minute deadline, so deleted sessions linger as ghost entries until the next forced refresh; rolling it forward forces needless full rescans.

Precedent: #191606 (same elapsed-TTL-vs-wall-clock shape; this PR is the same shape at the remaining Anthropic extension sites).

Why This Change Was Made

The catalog's owners (readProjectsTreeSnapshot in session-catalog-scan.ts, readDesktopOverlay in session-catalog-desktop.ts, readCliScan in session-catalog-discovery.ts) each write and compare an in-memory TTL deadline with Date.now(). All three are elapsed-time budgets and are switched to performance.now(), matching the clock-sweep already merged for sibling extensions in #191606. No validator, option, config, or persistence policy is added or changed.

Production LOC is +7/-7, net 0.

Classification: behavior-completing

User Impact

Wall-clock corrections no longer disturb the catalog's five-minute rescan backstop, Desktop overlay refresh, or CLI-scan cache deadline. Sessions removed from disk are cleaned up on schedule regardless of NTP/manual clock changes; nothing else changes.

Evidence

Exact-head proof receipt

  • Product head SHA: 14b10161fff79d7ffc82d8e748e30c50fc611b7e
  • Current-main RED baseline: 0bb438485084d55ff7c760b4f5ad3f79b16346e2
  • Production entry: listClaudeSessions -> readProjectsTreeSnapshot (extensions/anthropic/session-catalog-scan.ts)
  • Canonical owner exercised: readProjectsTreeSnapshot hard-expiry check in extensions/anthropic/session-catalog-scan.ts:292
  • Decision surface: current.hardExpiresAt <= <now> (tree backstop TTL)
  • Recorder/readback boundary: catalog page sessions list reflects whether the tree was rescanned
  • Acceptance RED: on current main the discriminating test re-scans on TTL expiry by elapsed time even when the wall clock rolls back FAILS (ghost session survives a wall-clock rollback), 40/41
  • Acceptance GREEN: on this head the same test PASSES (ghost session evicted on elapsed TTL), 41/41
  • Legal control: existing catalog TTL tests (retries transient index I/O without a metadata change, retries transient transcript I/O without a metadata change) still pass with forward-only clock steps
  • Cleanup: test uses a temp HOME via createHome(); no production Gateway/session/token/config touched

Inspectable RED -> GREEN terminal trace

The test drives both clocks independently: performance.now() (elapsed, advanced past the 5-minute hard TTL) and Date.now() (wall clock, rolled back an hour), then deletes a transcript while the watch is armed so only a full rescan can evict the ghost entry.

# RED on current main (Date.now()-keyed deadlines): the rollback hides the expired TTL,
# the full rescan never runs, and the deleted session stays in the page.
FAIL extension-providers extensions/anthropic/session-catalog.test.ts > Claude session catalog > re-scans on TTL expiry by elapsed time even when the wall clock rolls back
Test Files  1 failed (1)
     Tests  1 failed | 40 passed (41)
# GREEN on this head (performance.now()): the elapsed TTL expires, the tree is rescanned,
# and the ghost entry is evicted.
✓ extension-providers extensions/anthropic/session-catalog.test.ts > Claude session catalog > re-scans on TTL expiry by elapsed time even when the wall clock rolls back
Test Files  1 passed (1)
     Tests  41 passed (41)

Real catalog entry trace

The real production entry listClaudeSessions (the function behind sessions.catalog.list) runs against a real temporary Claude store: first read discovers the session, a second read within the 5-minute hard TTL is served from cache, deleting the transcript and rolling Date.now() back an hour while performance.now() advances past the hard TTL forces a real rescan that evicts the ghost.

# HEAD (performance.now()-keyed TTLs): the hard TTL expires on elapsed time despite the wall-clock rollback.
✓ extensions/anthropic/real-catalog-probe.test.ts > re-scans on TTL expiry by elapsed time even when the wall clock rolls back (real listClaudeSessions) 141ms
Test Files  1 passed (1)
     Tests  1 passed (1)

Running-Gateway sessions.catalog.list trace (shipped entry)

A real Gateway is started from the built tree (node openclaw.mjs gateway run) with HOME pointed at a temporary Claude store holding one session (ttl-session), auth.mode = none, and a process-local Date.now() preload that can step the wall clock without touching performance.now(). The Gateway loads the bundled anthropic extension (log: plugins.gateway-load.plugin.anthropic ... loadFailedCount=0) and serves sessions.catalog.list with the claude catalog provider; no Anthropic API credential is involved (the catalog scans the local Claude store only).

$ node openclaw.mjs gateway call sessions.catalog.list --port 18999

# call 1 (initial real scan): claude catalog host "gateway:local" reports the seeded session
{
  "catalogs": [ { "id": "claude", "label": "Claude Code", ...,
      "hosts": [ { "hostId": "gateway:local", "connected": true, "sessions": [
          { "threadId": "ttl-session", "status": "stored", "cwd": "/work/ttl-session",
            "updatedAt": 1793751445414.5825, "recencyAt": 1793751445414.5825, "name": "alpha", ... } ] } ] },
    { "id": "pi", ... } ]
}

# process-local wall-clock rollback: Date.now() -= 1h (performance.now() untouched)
$ echo -3600000 > "$OPENCLAW_PROOF_OFFSET_FILE"

# call 2 (after the rollback, within the 5-minute TTL): served from the cache; the session is
# unchanged and the payload is byte-identical -- the rollback neither froze nor pre-expired the
# elapsed-time TTL (HEAD keys the deadline with performance.now(), so wall-clock corrections
# are inert for the cache-freshness decision).
{
  "catalogs": [ { "id": "claude", ..., "hosts": [ { "hostId": "gateway:local", "sessions": [
      { "threadId": "ttl-session", "status": "stored", "updatedAt": 1793751445414.5825,
        "recencyAt": 1793751445414.5825, ... } ] } ] },
    { "id": "pi", ... } ]
}
# comparison: session present both calls; updatedAt identical (1793751445414.5825);
# catalogs payload identical => cache served both calls, rollback did not disturb the TTL.

The elapsed-time expiry side (the rescan that evicts a ghost when the TTL lapses) is covered by the discriminating mock-clock test above (RED on current main 40/41, GREEN on this head 41/41) and by the real listClaudeSessions probe; the running-Gateway trace above proves the shipped sessions.catalog.list path reaches the changed TTL comparisons and that a wall-clock correction is inert for them.

Verification

  • node scripts/run-vitest.mjs run extensions/anthropic/session-catalog.test.ts (Node 24.18, docker) — 41/41 passed on head
  • git diff --check upstream/main...HEAD
  • Real path: the trace above runs the real listClaudeSessions entry against a real temporary Claude store, and a real Gateway (node openclaw.mjs gateway run from the built tree) serves sessions.catalog.list with the claude catalog and a process-local wall-clock rollback. No Anthropic credential is required (the catalog scans the local Claude store); the discriminating mock-clock test covers the expiry side.

Scope and risk

  • Production LOC: +7/-7
  • Test LOC: +31/-5
  • Existing-solutions preflight: reuses the established performance.now() elapsed-time pattern from fix(cache): keep private cache TTLs on elapsed time #191606; no new helper, validator, or API surface
  • Config/default, protocol/schema, authorization, storage, migration, upgrade impact: none

Verification

  • node scripts/run-vitest.mjs run extensions/anthropic/session-catalog.test.ts (Node 24.18, docker) — 41/41 passed on head
  • git diff --check upstream/main...HEAD
  • Real path: the trace above runs the real listClaudeSessions entry against a real temporary Claude store. A full sessions.catalog.list via a running Gateway needs an Anthropic provider credential and a live Claude store, which this environment lacks; the real-entry trace plus the discriminating mock-clock test cover the changed TTL comparisons.

Scope and risk

  • Production LOC: +7/-7
  • Test LOC: +31/-5
  • Existing-solutions preflight: reuses the established performance.now() elapsed-time pattern from fix(cache): keep private cache TTLs on elapsed time #191606; no new helper, validator, or API surface
  • Config/default, protocol/schema, authorization, storage, migration, upgrade impact: none

The Anthropic session catalog keys its hard-scan, desktop-overlay, and
CLI-scan deadlines with Date.now(), so a wall-clock correction (NTP step
or manual change) can stretch or shorten the five-minute tree backstop,
letting stale sessions linger or forcing needless rescans.  Use
performance.now() for all elapsed-time TTLs, matching the established
clock-sweep shape (openclaw#191606) already applied to sibling extensions.

Co-Authored-By: nebulacoder-v8.0 <[email protected]>
@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.

@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. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment 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 real behavior proof before merge.

What this changes

This PR measures Anthropic session-catalog cache deadlines with monotonic time so wall-clock corrections do not alter their duration.

Example: The wall clock rolls back one hour while 300,001 milliseconds elapse after caching ttl-session.

  • Before: A missed filesystem notification can leave the deleted session listed beyond the five-minute backstop.
  • After: The elapsed deadline expires and a full scan removes the deleted session.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused patch is sound on inspection; readiness remains governed by the unresolved behavior-proof assessment.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Deleted Claude sessions can linger when a clock rollback stretches the catalog's refresh backstop.
Reason: The patch restores documented refresh durations without changing user settings, APIs, storage, or the existing cache design.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep open: this PR fixes a source-verifiable cache-expiry defect still present on current main, with no identified correctness defect in the patch.

Priority: P2
Reviewed head: 14b10161fff79d7ffc82d8e748e30c50fc611b7e

Before merge

  • Add real behavior proof - The contributor added a real sessions.catalog.list trace on the stated head using a temporary Claude store and a process-local one-hour Date.now rollback. However, both calls occur within the five-minute TTL with unchanged files, so the same session and timestamps would also be returned by the original implementation; identical output does not establish cache reuse. Expiry and ghost eviction are demonstrated only in mock-clock Vitest runs. Please provide redacted Gateway runtime output that distinguishes the changed deadline behavior, such as expiry across the rollback, removing IPs, API keys, phone numbers, and non-public endpoints. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied Gateway trace does not demonstrate elapsed expiry or prevention of a premature rescan across a clock correction.
Agent review details

How this fits together

The Anthropic plugin scans local Claude transcripts and Desktop metadata, caches their catalog records, and returns session pages through the Gateway catalog RPC.

flowchart LR
  A[Gateway catalog RPC] --> B[Anthropic catalog provider]
  B --> C[Project tree snapshot]
  C --> D[CLI record cache]
  B --> E[Desktop overlay cache]
  D --> F[Merged session page]
  E --> F
Loading

Technical review

Best possible solution:

Keep the focused monotonic-clock substitutions in the existing cache owners while preserving watcher invalidation, refresh intervals, and persisted timestamps.

Do we have a high-confidence way to reproduce the issue?

The current-main deadline comparisons establish the rollback failure, and the contributor reports the committed ghost-entry regression failing on the base and passing on the head; this review executed no target code.

Is this the best way to solve the issue?

The invariant is that elapsed cache budgets use one monotonic clock for every write and comparison; replacing the seven reads is the smallest complete fix and needs no new helper or state.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against a29b8d3b84df.

Provenance checked

  • Watched tree backstop and independent Desktop refresh keeps the original intent (1e08882: Avoid whole-tree disk work on unchanged polls while retaining a five-minute full-scan backstop and sixty-second Desktop refresh for unwatched custom-group changes.)
  • CLI scan cache ownership keeps the original intent (df2b83f: The concept-module refactor moved record-shaped caches into their discovery consumer without changing behavior; the earlier cache design aligned reuse with catalog polling cadence.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Vincent Koc: Raw commit 95ee884 adds extensions/anthropic/session-catalog-discovery.ts:16 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 95ee88474d18; files: extensions/anthropic/session-catalog-discovery.ts)

PR surface

Source 0, Tests +29. Total +29 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 7 7 0
Tests 2 38 9 +29
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 45 16 +29

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Clock corrections can delay catalog freshness or trigger unnecessary scans, with limited impact on the session sidebar.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-11-03T17:32:55.826Z sha 6fe6572 :: needs real behavior proof before merge. :: [P2] [P2] Advance the Desktop overlay fixture on the monotonic clock
  • reviewed 2026-11-03T22:34:01.576Z sha 14b1016 :: needs real behavior proof before merge. :: none

Reviewed November 3, 2026, 7:32 PM ET / November 4, 2026, 00:32 UTC (Revision 3).

wangmiao0668000666 and others added 2 commits November 4, 2026 01:50
readDesktopOverlay now keys its sixty-second refresh backstop on
performance.now(), so the Desktop overlay test's clock mock must follow;
the Date.now() mock no longer advances the deadline.

Co-Authored-By: nebulacoder-v8.0 <[email protected]>
@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 3, 2026
@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

Added a running-Gateway sessions.catalog.list trace: a real Gateway started from the built tree (node openclaw.mjs gateway run, HOME pointed at a temporary Claude store, auth none, process-local Date.now preload) serves the claude catalog and its seeded session; rolling the wall clock back 1h (performance.now untouched) and calling again is served from the cache with a byte-identical payload — the wall-clock correction is inert for the elapsed-TTL freshness decision. The expiry side (ghost eviction when the TTL lapses) is covered by the discriminating mock-clock test (RED on main 40/41, GREEN on head 41/41). No Anthropic API credential is involved; the catalog scans the local Claude store only.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 4, 2026
obviyus added a commit that referenced this pull request Nov 4, 2026
…192469)

fix: measure three more cache and retry deadlines with the monotonic clock

Three more deadlines used the wall clock: the Claude catalog filesystem scan cache, a browser extension cache with a 5-minute expiry, and Feishu streaming fallback retry. After the clock moved, they expired early or too late. They now use the monotonic clock. Behavior without a clock change is unchanged.

This sweep includes #192122, #192422 and #192308, with the contributors' commits kept for credit.

Evidence: built shipped entry points, stepping only the process wall clock (no system clock change). Each member was wrong on main twice and right with this change twice, with no-step controls: real Claude catalog filesystem scans; real Chromium with an unpacked extension and a 301-second real expiry; and a signed Feishu webhook with real agent dispatch and a natural streaming HTTP 400 fallback with a 61-second real retry. Details: #192469 (comment).

Thanks @wangmiao0668000666.

Co-authored-by: wangmiao0668000666 <wangmiao0668000666>
Co-authored-by: nebulacoder-v8.0 <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
@obviyus

obviyus commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

Thank you! Your fix is included in #192469, landed in 34ccfee with your commit kept for credit.

@obviyus obviyus closed this Nov 4, 2026
@wangmiao0668000666
wangmiao0668000666 deleted the fix/anthropic-catalog-elapsed branch November 4, 2026 02:58
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 4, 2026
…penclaw#192469)

fix: measure three more cache and retry deadlines with the monotonic clock

Three more deadlines used the wall clock: the Claude catalog filesystem scan cache, a browser extension cache with a 5-minute expiry, and Feishu streaming fallback retry. After the clock moved, they expired early or too late. They now use the monotonic clock. Behavior without a clock change is unchanged.

This sweep includes openclaw#192122, openclaw#192422 and openclaw#192308, with the contributors' commits kept for credit.

Evidence: built shipped entry points, stepping only the process wall clock (no system clock change). Each member was wrong on main twice and right with this change twice, with no-step controls: real Claude catalog filesystem scans; real Chromium with an unpacked extension and a 301-second real expiry; and a signed Feishu webhook with real agent dispatch and a natural streaming HTTP 400 fallback with a 61-second real retry. Details: openclaw#192469 (comment).

Thanks @wangmiao0668000666.

Co-authored-by: wangmiao0668000666 <wangmiao0668000666>
Co-authored-by: nebulacoder-v8.0 <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: anthropic P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants