Repository navigation
perf(state): skip identity refreshes for content-only events - #183348
Conversation
|
🦞👀 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. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
|
Codex review: needs maintainer review before merge. What this changesThe PR forwards filesystem event types so three identity owners can skip content-only notifications, and extends the existing benchmark to measure sustained workloads. Example: Linux reports a named change event for openclaw-agent.sqlite during an agent turn.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR makes a measured, narrowly scoped optimization, and review found no actionable introduced defect. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherNative directory notifications enter the shared observer, which delivers invalidations to auth-file, session-source, database-validation, and other consumers; each consumer owns its retained facts. flowchart TD
A[Native directory events] --> B[Shared directory observer]
B --> C[Auth file identity owner]
B --> D[Session source owner]
B --> E[Database validation owner]
B --> F[Content sensitive consumers]
C --> G[Existing admission and effect checks]
E --> G
Technical reviewBest possible solution: Retain the small owner-local event filter and existing invalidation safeguards, with the benchmark supporting only the measured filesystem-work reduction. Do we have a high-confidence way to reproduce the issue? Source inspection shows named content events reaching identity stat checks on current main; the PR reports matching base-failing regressions and built-Gateway measurements, which were not rerun during this read-only review. Is this the best way to solve the issue? The change uses the smallest existing runtime boundary: preserve event classification in the observer and let identity owners skip irrelevant work while content-sensitive consumers continue receiving notifications. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 5d973f1079e4. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +11, Tests +86, Other +396. Total +493 across 11 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 October 25, 2026, 2:51 AM ET / 06:51 UTC. |
What Problem This Solves
Concurrent agent turns repeatedly stat unchanged agent database identities when SQLite emits ordinary content-change notifications.
User Impact
Reduces filesystem work during busy Gateway sessions when native watchers report named
changeevents, while retaining database replacement/deletion detection and existing write-admission checks. No configuration or migration is needed.Why This Change Was Made
The shared directory observer discarded the native event type. Identity/presence consumers therefore treated named content writes like possible file replacement. Forward that existing event fact and let the three identity owners skip named
changenotifications. Rename/unlink, nameless events, watcher recovery, and the existing periodic reconciliation still refresh identities.The observers already watch state directories and necessary ancestors, and their owners already coalesce refreshes. Content-sensitive consumers still need every notification, so filtering stays with the identity owners. This adds no cache, timer, or second invalidation owner. Runtime code grows by 11 lines to preserve and consume the event classification; no existing lifecycle mechanism becomes redundant. The non-test delta is +407 lines: +11 runtime and +396 benchmark tooling. The larger tooling change supplies the required fixed-duration workload, verified real tool results, synchronized starts, main-isolate profiling, and filesystem counters in the existing benchmark CLI. Tests add 86 net lines.
Evidence
Two concurrent, counterbalanced Linux pairs used Node 26.12.1 and the built base/candidate artifacts. Each side had 16 interleaved virtual CPUs and an isolated native Linux filesystem; each admission window lasted 600 seconds plus drain. The measured base was
fdad53b1bc1d66d98a11da12fb633a75f8285ecb; the runtime patch remained byte-for-byte identical after rebasing onto current main.The small, consistent result is fewer filesystem calls: database stats/turn fell 1.14%, and all measured stat calls/turn fell 1.39%. This does not establish a whole-Gateway CPU speedup. A separate 600-second main-isolate allocation pair was essentially flat: 159.43→159.23 MiB/s (−0.12%), or 168.52→167.15 MB per verified turn (−0.81%). This single sampled pair is context, not a claim of a broad allocation improvement.
Paired timing, work counts, and memory
Relative changes are the mean of per-pair relative changes; absolute changes are the mean paired differences. CPU/turn and GC/turn normalize the whole mixed workload, including fixed-rate probes. Final RSS rose 1.03%; final heap and sampled peak RSS were roughly neutral. Observed heap growth differed (+53.91 MiB mean); these unforced snapshots can reflect GC phase and do not establish a retention improvement. Exact loop p95 was not collected.
All 885/852 and 949/975 admitted turns were verified, with matching provider/tool accounting and successful recorded probes. Start skews were 59.331 and 26.364 ms. No diagnostic samples were dropped. Each run also recorded one worker-reservation error aggregate without its cause; no failed turn or probe was visible, but the aggregate does not establish why that operation failed.
Total GC p95 was 29.182→31.870 ms (n=4527/4462) and 20.734→20.606 ms (n=4806/4911); total GC p99 was 88.574→87.038 and 76.798→73.726 ms with the same counts. Major-GC and incremental-GC percentile samples were too few for tail conclusions. No untraced decision metric crossed the predeclared rejection thresholds; no additional control run was required by those results.
Allocation scope and residual cost
The main-only capture included collected objects at a 32 KiB sampling interval, ran for 614.906/614.658 seconds, verified 610/614 turns, and had clean exits and no collector loss. The targeted stats subtree below owned-directory callbacks recorded 3,353,976 sampled bytes on base and none on candidate; zero sampled bytes is not proof of zero allocation. The broader observer subtree increased from 398.89 to 437.72 MB (0.619→0.679 MiB/s), chiefly path resolution under
isPathInside. Native deliveries also increased from 96.63 to 101.38/s. This fixture did not reproduce the original production allocation family's size, and this PR does not claim that broader cost was removed.The initial allocation attempt failed before any measured load because worker profiling could not resolve a source-module import under native Node. The new fixed-duration mode now explicitly captures the requested main isolate and omits worker-manifest metadata. A paired real-Gateway heap smoke passed before the full capture was repeated; no runtime code or untraced workload changed for that repair.
Platform and fixture limits
Native macOS probes reported content writes as
rename, so this optimization does not activate for that event stream. Four earlier sequential Mac windows on a busy shared host had essentially flat database stats/turn (+0.20%), CPU/turn +13.14%, GC/min +23.33%, loop p99 +58.20 ms, and list p99 +0.11 ms on the paired absolute mean. Those uncontrolled timings remain inconclusive and are not evidence of a Mac performance improvement. Linux native events in the measured workload were over 99.96% named content changes.History probes hit their bounded 2,050-sample budget roughly halfway through each window; list/search/subscription churn continued throughout. The fixture uses one agent database and short tool-result markers, so it does not quantify benefits from a larger database catalog or production-sized tool payloads. The Mac and Linux evidence are not combined into one performance estimate.
The built local Gateway workload uses synthetic state only: 10,000 sessions (mostly archived subagent inventory), 40 plugins, 36 concurrent mock-provider turns executing read/grep tools in managed worktrees, and 64 WebSocket clients with list/search/sidebar/history churn. Each admission window lasts 600 seconds, followed by draining. Timing/GC runs are untraced; sampled allocation is measured separately. Filesystem counters cover the main thread and native watcher-host deliveries, not worker-thread stat calls. This fixture uses one agent database, does not seed persisted dashboard boards, and returns short tool-result markers after reading/grepping the fixture files. Allocation rates use the profiler capture duration.
git diff --checkpassed.