Repository navigation
perf: Claude Code catalog refresh no longer re-scans the projects tree on every poll - #136222
Conversation
…it per poll `sessions.catalog.list` took >1s in hundreds of requests per day (max 60s) on an IOPS-saturated Gateway host. The Claude provider re-read the whole `~/.claude/projects` tree on every poll to compute a freshness stamp (readdir + stat of every direct child), and any active Claude session changed that stamp so every poll also reran the assembled scan with a realpath + stat per candidate; the Desktop 60s TTL forced CLI rescans too. Measured warm poll on a 1.2k-project tree: ~7.2k stats, 1.2k readdirs, 1.5k realpaths with zero file parsing. The provider now owns freshness with a directory watch (`session-catalog-tree-watch.ts`): one recursive fs.watch on macOS and Windows, root plus per-project-directory watches on Linux (Node's Linux recursive watch watches every file), nonpersistent, degrading to a full read on watcher failure with a 5s reattach. A watch vouches for coverage only once it has been attached for 250ms and polled, because libuv starts the FSEvents stream asynchronously and drops writes in that window. The projects tree snapshot is kept per root and re-stats only dirty directories; its lstat signatures (mtime/size/ino) replace the per-candidate realpath + stat during discovery; CLI records are keyed by tree stamp; the Desktop overlay refreshes on its own watch or backstop without invalidating CLI records; Desktop custom groups cache on the LevelDB listing signature; merged results are memoized on identity. Gateway side, the list cache key no longer carries a per-connection caller id. node.list and node.invoke read only scopes, role, and device id from the caller and the key already carried those plus the profile visibility facts, so a reconnected dashboard (a new client object) now shares the settled enumeration instead of queueing another provider scan behind the admission cap. Warm unchanged poll after: 0 stats, 0 readdirs, 0 realpaths, 0 opens. Docs: docs/providers/anthropic.md describes the watched freshness model.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed September 2, 2026, 6:03 AM ET / 10:03 UTC. ClawSweeper reviewWhat this changesThe PR makes Anthropic’s Claude Code session catalog retain bounded watched filesystem snapshots so unchanged Gateway polls avoid rescanning local project and Desktop session data. Merge readiness✅ Ready for maintainer review No introduced correctness defect was found on the corrected head. The earlier Desktop-refresh and caller-isolation concerns are addressed; this maintainer-authored, protected PR should remain open for normal exact-head CI and maintainer handling. Priority: P2 Review scores
Verification
How this fits togetherThe Anthropic plugin reads local Claude Code and Claude Desktop session metadata into the Gateway session catalog. Gateway handlers then apply each caller’s current visibility rules before returning rows to the Control UI or another catalog client. flowchart LR
A[Claude project files] --> B[Watched plugin snapshot]
F[Desktop session metadata] --> C[Desktop overlay]
B --> D[Combined session records]
C --> D
D --> E[Gateway caller visibility]
E --> G[Catalog response]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +309, Tests +401, Docs +10, Other 0. Total +720 across 10 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Keep filesystem freshness in the Anthropic plugin, preserve the 60-second Desktop overlay refresh for unwatched Local Storage groups, and retain Gateway’s per-caller response partition. Do we have a high-confidence way to reproduce the issue? Not applicable as an issue reproduction. The PR supplies an observed Gateway cold-to-warm timing trace and focused source-visible cache regressions, though this read-only review did not execute them. Is this the best way to solve the issue? Yes. The snapshot belongs in the Anthropic plugin, while Gateway continues to derive the response from current caller facts; this avoids both repeated filesystem work and unsafe cross-caller sharing. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against fc8a452938a0. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
Addressed the rank-up move in 6da97ea: Desktop overlays retain the 60-second refresh, and the existing custom-group test now verifies a normal poll after changing Local Storage. That assertion failed before the correction and passes afterward. The Linux CI Desktop-refresh failure shares this invalidation gap. CI also exposed the gateway caller-partition regression. The generic cross-connection cache change is removed, preserving the unchanged shipped privacy test and external plugin node-policy contract. The Anthropic watched snapshot remains reusable across enumerations. Gateway catalog/privacy tests: 41 passed; Anthropic catalog/watch tests: 74 passed. Fresh autoreview is scoped-clean at P0. No persistent schema or data format changed; the group cache is process-local only. The PR body now records the corrected scope and the local missing-dependency check limitation. @clawsweeper re-review This push changes behavior beyond the Desktop finding by restoring gateway caller isolation. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Merged via squash.
|
…e on every poll (openclaw#136222) * perf(catalog): watch the Claude projects tree instead of re-statting it per poll `sessions.catalog.list` took >1s in hundreds of requests per day (max 60s) on an IOPS-saturated Gateway host. The Claude provider re-read the whole `~/.claude/projects` tree on every poll to compute a freshness stamp (readdir + stat of every direct child), and any active Claude session changed that stamp so every poll also reran the assembled scan with a realpath + stat per candidate; the Desktop 60s TTL forced CLI rescans too. Measured warm poll on a 1.2k-project tree: ~7.2k stats, 1.2k readdirs, 1.5k realpaths with zero file parsing. The provider now owns freshness with a directory watch (`session-catalog-tree-watch.ts`): one recursive fs.watch on macOS and Windows, root plus per-project-directory watches on Linux (Node's Linux recursive watch watches every file), nonpersistent, degrading to a full read on watcher failure with a 5s reattach. A watch vouches for coverage only once it has been attached for 250ms and polled, because libuv starts the FSEvents stream asynchronously and drops writes in that window. The projects tree snapshot is kept per root and re-stats only dirty directories; its lstat signatures (mtime/size/ino) replace the per-candidate realpath + stat during discovery; CLI records are keyed by tree stamp; the Desktop overlay refreshes on its own watch or backstop without invalidating CLI records; Desktop custom groups cache on the LevelDB listing signature; merged results are memoized on identity. Gateway side, the list cache key no longer carries a per-connection caller id. node.list and node.invoke read only scopes, role, and device id from the caller and the key already carried those plus the profile visibility facts, so a reconnected dashboard (a new client object) now shares the settled enumeration instead of queueing another provider scan behind the admission cap. Warm unchanged poll after: 0 stats, 0 readdirs, 0 realpaths, 0 opens. Docs: docs/providers/anthropic.md describes the watched freshness model. * fix(catalog): preserve caller isolation and Desktop refresh bounds
What Problem This Solves
Fixes an issue where operators with large Claude Code histories would see the sessions sidebar's catalog refresh stall for seconds when the Gateway host's disk was busy. On a production Gateway the
sessions.catalog.listRPC exceeded 1s in 518 requests over one day with a 60s maximum, far more than any other method, while the Control UI polls it every 30s (5s while anything changes) and again on every reconnect and tab focus.Why This Change Was Made
The Claude Code catalog provider re-read the whole
~/.claude/projectstree on every poll to decide whether its cache was still valid (a readdir per project directory and a stat of every direct child), and any active Claude session changed that whole-tree stamp, so every poll also reran the assembled scan with a realpath and stat per transcript plus a stat per Claude Desktop metadata file. The provider now owns freshness with a directory watch (recursive on macOS/Windows, root plus per-project-directory on Linux) and keeps an incrementally maintained snapshot whose lstat signatures replace the per-candidate filesystem work; CLI records and the Desktop overlay are cached independently so one does not invalidate the other. A watch vouches for coverage only after a short arming interval because libuv starts the macOS FSEvents stream asynchronously; watcher failure degrades to today's per-poll full read. Gateway enumeration retains its caller partition because external plugin node policies can observe connection identity; the plugin filesystem snapshot is still reusable across those enumerations. Desktop metadata retains its 60-second backstop because custom groups live outside the watched session directory. Non-goals: the separatesessions.github.optionslatency (two uncached GitHub identity probes per call) is tracked as a follow-up.User Impact
The Claude Code group in the sessions sidebar refreshes without touching the disk when nothing changed, and a change re-reads only the affected project directory. Dashboards that reconnect reuse the plugin filesystem snapshot without merging caller-bound provider work. Sessions created or renamed outside OpenClaw still appear on the next refresh; the whole tree is re-read at most every five minutes as a backstop.
Evidence
Warm
listClaudeSessionson a 1.2k-project tree (unsaturated NVMe; production wall time is disk-bound):Regression tests that fail on pre-fix code:
extensions/anthropic/session-catalog.test.ts("serves an unchanged assembled scan without reparsing transcript files" now asserts zero home I/O; "re-stats only the changed project directory on the next poll"; "keeps the CLI records when only the Desktop store changes"). Newsession-catalog-tree-watch.test.tscovers dirty reporting, Linux child-watch lifecycle, and creation-failure fallback.Local proof:
Codex autoreview (two passes on the final diff): scoped-clean, no accepted findings.
Production LOC: +694/-385 (net +309); tests: +476/-75 (net +401); docs: +10. The production growth adds bounded watcher/snapshot lifecycle ownership and separates Desktop invalidation from CLI records; the moved Desktop parsing code is not new capability. A net-neutral TTL-only change would retain whole-tree disk reads or delay freshness for all CLI records.
Original-head live real-flow proof on an isolated dev gateway (
OPENCLAW_STATE_DIRunder a temp dir,CLAUDE_CONFIG_DIRpointing at the real~/.claude, port 18901,OPENCLAW_SKIP_CHANNELS=1), callingopenclaw gateway call sessions.catalog.list --params '{"limitPerHost":40}'from fresh CLI connections; the gateway's own RPC timing lines:The Claude Code group listed the local CLI sessions on every call (Desktop rows are excluded under HOME isolation, as before).
CI and review corrections
The first exact-head CI run (33615118618, head e3bd513) exposed a caller-isolation regression. The generic gateway cache-key optimization is removed: external plugin node policies may observe connection identity, and the existing shipped privacy contract is retained. The unchanged privacy regression failed locally before this correction; both gateway catalog suites then passed (41 tests).
ClawSweeper's rank-up move is accepted: Desktop metadata retains the 60-second refresh because Local Storage groups are outside the session-directory watcher. The existing group test now verifies an ordinary poll after an independent group update, and failed before the correction. CLI records remain independently cached.
No persistent store or schema change: the group map is a bounded process-local cache; the existing external LevelDB format is only read. No changelog or new config option.
Corrected-candidate local proof: gateway catalog + unchanged privacy suites passed 41/41 tests; Anthropic catalog + tree-watch suites passed 74/74 tests. The initial Linux failure in
keeps the CLI records when only the Desktop store changeswas the same overextended Desktop TTL and is addressed by restoring the 60-second bound.Corrections are committed in 6da97ea. Fresh autoreview of the complete corrected candidate: scoped-clean at P0. Local
node scripts/check-changed.mjspassed ratchets, formatting, core and core-test typechecks, then stopped in untouchedextensions/browser/src/browser/chrome-mcp-options.tsbecause this worktree lacks the already-declared@types/yargs-parserinstallation. No dependency or lockfile workaround was applied; exact-head hosted CI is the remaining gate. The original security-fast failure happened during Git history fetch (exit 128, no credentials available to that fetch), before scanning.Related: #127743 tracks the separate stale-while-revalidate product decision for slow external catalogs after cache expiry; this PR reduces Claude provider scan cost and does not claim to close that issue.