Skip to content

fix(anthropic): retry unavailable catalog watch on elapsed time - #192144

Closed
wangmiao0668000666 wants to merge 5 commits into
openclaw:mainfrom
wangmiao0668000666:fix/anthropic-catalog-tree-watch
Closed

wangmiao0668000666 wants to merge 5 commits into
openclaw:mainfrom
wangmiao0668000666:fix/anthropic-catalog-tree-watch

Conversation

@wangmiao0668000666

@wangmiao0668000666 wangmiao0668000666 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

The Anthropic catalog's createDirtyDirectoryWatch arms its restart backoff with Date.now(). When a watch becomes unavailable (health callback or start failure), it records retryAt = Date.now() + 5_000 and only restarts once Date.now() >= retryAt. A wall-clock correction can distort that elapsed-time budget: rolling the clock back keeps an unavailable watch un-retried indefinitely (every catalog read degrades to a full rescan), while a forward step retries early and churns subscriptions.

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

Why This Change Was Made

The tree-watch owner (createDirtyDirectoryWatch in session-catalog-tree-watch.ts) writes and compares a single in-memory retry deadline with Date.now() in three spots (health-callback, start-catch, and the takeDirty re-check). The deadline is an elapsed-time budget and is 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 +2/-2, net 0.

Classification: behavior-completing

User Impact

A wall-clock correction no longer postpones or accelerates watch restart after an unavailable/failed filesystem watch. The five-second retry backoff fires on schedule regardless of NTP/manual clock changes; recovered coverage is re-established as before.

Evidence

Exact-head proof receipt

  • Product head SHA: a6135571c9927fabe906cfd1c334a3b346f8be51
  • Current-main RED baseline: 0bb438485084d55ff7c760b4f5ad3f79b16346e2
  • Production entry: createDirtyDirectoryWatch (extensions/anthropic/session-catalog-tree-watch.ts)
  • Canonical owner exercised: takeDirty retry check in session-catalog-tree-watch.ts:75
  • Decision surface: performance.now() >= retryAt (watch restart backoff)
  • Recorder/readback boundary: observation.watch call count (retry re-attaches the subscription)
  • Acceptance RED: on current main the discriminating test retries an unavailable watch on elapsed time even when the wall clock rolls back FAILS (rollback keeps the watch un-retried), 2/3
  • Acceptance GREEN: on this head the same test PASSES (elapsed retry fires on schedule), 3/3
  • Legal control: existing invalidates catalog reads at depth 2/3 and recovers lost coverage tests still pass with forward-only clock steps
  • Cleanup: test uses a temp directory via useAutoCleanupTempDirTracker; no production Gateway/session/token/config touched

Inspectable RED -> GREEN terminal trace

The test drives both clocks independently: performance.now() (elapsed, advanced past the 5s retry window) and Date.now() (wall clock, rolled back an hour), with a watch that reports unavailable, and asserts the retry re-attaches the subscription only when the elapsed deadline has passed.

# RED on current main (Date.now()-keyed retryAt): the rollback hides the expired deadline,
# the retry never re-attaches, and the watch stays unavailable.
× extension-providers extensions/anthropic/session-catalog-tree-watch.test.ts > retries an unavailable watch on elapsed time even when the wall clock rolls back
Test Files  1 failed (1)
     Tests  1 failed (3)
# GREEN on this head (performance.now()): the elapsed retry deadline expires and the
# subscription is re-attached.
✓ extension-providers extensions/anthropic/session-catalog-tree-watch.test.ts > retries an unavailable watch on elapsed time even when the wall clock rolls back
Test Files  1 passed (1)
     Tests  3 passed (3)

Real-subscription recovery trace

A real filesystem subscription drives the same unavailable->recover path (no mock): createDirtyDirectoryWatch watches a real directory, removing the root makes the real fs-safe watch report unavailable, a one-hour backward Date.now() step does not postpone the elapsed retry, and the rebuilt root re-attaches coverage.

# HEAD (performance.now()): the elapsed retry fires on schedule despite the wall-clock rollback.
[+1201ms] attach#1 dirty="all"
[+2406ms] root removed (real unavailable)
[+2409ms] root rebuilt; Date.now rolled back 1h
[+8016ms] poll0: "all"
[+9018ms] poll1: "all"
[+10019ms] poll2: {}          # takeDirty returns an empty Set: the watch re-attached

takeDirty() returning an empty Set (instead of the blanket "all") proves the subscription recovered coverage after the elapsed retry deadline — a real watcher, real file system, real invalidation, no mock.

Verification

  • node scripts/run-vitest.mjs run extensions/anthropic/session-catalog-tree-watch.test.ts (Node 24.18, docker) — 3/3 passed on head
  • git diff --check upstream/main...HEAD
  • Real path: the trace above exercises a real filesystem subscription (root removal drives a genuine unavailable health, rebuild re-attaches coverage after the elapsed deadline). The wall-clock rollback is applied only in-process to Date.now(); the host/system clock is untouched.

Scope and risk

  • Production LOC: +2/-2
  • Test LOC: +39/-2
  • 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

@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 maintainer review before merge.

What this changes

Measures Anthropic catalog watcher retry deadlines with monotonic elapsed time instead of wall-clock time.

Example: An unavailable catalog watcher encounters a one-hour clock rollback.

  • Before: The five-second retry can be delayed by approximately an hour, causing repeated full catalog scans.
  • After: The next catalog read after five elapsed seconds can restart the watcher.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, correct repair with real-subscription recovery evidence and successful current-head checks; proof exercises the production owner in process.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The supplied Docker trace exercises createDirtyDirectoryWatch with a real fs-safe filesystem subscription, genuine root-loss unavailability, root restoration, and a process-local one-hour wall-clock rollback; coverage recovers after the elapsed retry window, supporting the internal recovery change without requiring a live model or channel.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: After a clock correction, unavailable catalog watchers can retry too early or remain degraded beyond their intended five-second backoff.
Reason: The change restores an existing duration contract without changing configuration, persistence, public APIs, or subscription ownership.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current-main retry defect with a focused change; no actionable correctness or security findings remain.

Priority: P2
Reviewed head: 15bccea4a8976eac7dfebebe37059a136aa0105c

Before merge

None.

Findings

None.

Agent review details

How this fits together

Claude CLI and Desktop catalog readers consume dirty-directory information from a shared watcher owner, which manages fs-safe subscriptions and requests full scans while coverage is unavailable.

flowchart LR
  A[CLI catalog reader] --> C[Dirty directory watcher]
  B[Desktop catalog reader] --> C
  C --> D[Elapsed retry deadline]
  C --> E[fs-safe subscription]
  E --> F[Filesystem changes]
  C --> G[Dirty names or full scan]
Loading

Technical review

Best possible solution:

Keep the existing watcher owner and use performance.now consistently for its process-local retry deadline.

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

Current-main source establishes the wall-clock-sensitive retry path, and the contributor supplies discriminating base-failure/candidate-success output; no target code was executed during this review.

Is this the best way to solve the issue?

This is the smallest complete repair: both deadline producers and their comparison use the same monotonic clock, with one distinct rollback regression and no new production machinery.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Anthropic catalog watcher recovery keeps the original intent (fcdd870: The fs-safe migration retained conservative full scans during unavailable coverage and restart recovery while consolidating transport ownership.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source 0, Tests +39, Other +2. Total +41 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 3 3 0
Tests 1 40 1 +39
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 3 45 4 +41

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit 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: Clock corrections can delay watcher recovery and increase filesystem scanning, while conservative full scans preserve catalog correctness.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit 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.

History

Review history (3 earlier review cycles)
  • reviewed 2026-11-03T18:17:52.214Z sha 3ed9b5180079cfc9edf1f99b9515ab9da2546359 :: needs real behavior proof before merge. :: [P2] Complete the mocked watcher subscription and health contracts
  • reviewed 2026-11-03T22:33:08.038Z sha a6135571c9927fabe906cfd1c334a3b346f8be51 :: needs maintainer review before merge. :: none
  • reviewed 2026-11-04T03:07:14.202Z sha 48709a16e624ef62de8ac3265dd24279e69b201e :: needs maintainer review before merge. :: none

Reviewed November 5, 2026, 8:21 AM ET / 13:21 UTC (Revision 4).

@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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed 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. 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
wangmiao0668000666 force-pushed the fix/anthropic-catalog-tree-watch branch from a613557 to 48709a1 Compare November 4, 2026 02:41
@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Rebased onto 22f8b256e5f (includes the #192469 sweep, which lowered main's test-line total). checks-fast-baseline-ratchets now passes and all CI checks are green on head 48709a16e62. No content changes — production diff is unchanged (3 Date.now() → performance.now() in session-catalog-tree-watch.ts).

@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. 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 4, 2026
@wangmiao0668000666
wangmiao0668000666 force-pushed the fix/anthropic-catalog-tree-watch branch from 48709a1 to 2371ffd Compare November 4, 2026 03:25
@clawsweeper clawsweeper Bot removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Nov 5, 2026
@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Updated the branch via GitHub update-branch to merge the latest main (head 15bccea4a897). This raises the test-lines ceiling so the +39 net delta is absorbed — checks-fast-baseline-ratchets now passes and all CI checks are green. Production diff unchanged: 3 Date.now() → performance.now() in session-catalog-tree-watch.ts.

@clawsweeper

clawsweeper Bot commented Nov 5, 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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary 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. labels Nov 5, 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).
The main-line fs-safe WatchSubscription requires setScopes and
Symbol.asyncDispose, and WatchHealth requires mode and directories.
Fill the mock so check-test-types passes.
@wangmiao0668000666
wangmiao0668000666 force-pushed the fix/anthropic-catalog-tree-watch branch from 15bccea to 6b4e6e8 Compare November 6, 2026 08:08
@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

Closing to free PR queue capacity (author has >20 active PRs per barnacle policy). This fix remains valid; can be reopened/resubmitted once queue is under the limit.

@wangmiao0668000666
wangmiao0668000666 deleted the fix/anthropic-catalog-tree-watch branch November 15, 2026 02:27
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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary 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.

1 participant