Repository navigation
perf(auth): reduce allocations from unrelated file watcher events - #186370
Conversation
Iterate the existing identity map when filtering unrelated file renames. Preserve replacement and legacy-source invalidation without allocating a key snapshot and predicate per event.\n\nOwner replay allocation falls from 249.9 to 64.4 bytes/event across five interleaved pairs; native watcher policy is unchanged.
|
🦞👀 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 changesThis PR replaces a temporary database-key array and predicate with direct map iteration when filtering auth-directory events. Example: A rename event arrives for openclaw-agent.sqlite-wal.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it removes measured allocation waste with a small, behavior-preserving change, and no actionable defect was found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherNative directory events pass through the shared directory observer to the auth file-state owner, which filters irrelevant names and refreshes identity or legacy-source facts for relevant notifications. flowchart LR
A[Native directory event] --> B[Directory watch adapter]
B --> C[Shared directory observer]
C --> D[Auth filename filter]
D --> E[Identity and source refresh]
E --> F[Auth snapshot invalidation]
Technical reviewBest possible solution: Retain the direct iteration in the existing auth owner and land through the normal CI gate. Do we have a high-confidence way to reproduce the issue? Current main visibly expands the identity-map keys and creates a predicate for unrelated rename events; reported replay measurements quantify that cost, but no target code was executed during this read-only review. Is this the best way to solve the issue? Direct iteration is the smallest complete fix: it deletes temporary work at the existing owner while preserving matching, refresh scheduling, and identity checks. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 0a6415bed1d7. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +3, Tests 0, Other +239. Total +242 across 3 files. Added test files: 0. View PR surface stats
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 27, 2026, 7:06 PM ET / 23:06 UTC. |
…claw#186370) Iterate the existing identity map when filtering unrelated file renames. Preserve replacement and legacy-source invalidation without allocating a key snapshot and predicate per event.\n\nOwner replay allocation falls from 249.9 to 64.4 bytes/event across five interleaved pairs; native watcher policy is unchanged.
What Problem This Solves
Auth-file observation allocates a temporary database-key array and predicate for every unrelated directory rename, including SQLite sidecars that it immediately ignores. This is residual work after #183348, #183818, and #184250; all three were ancestors of the profiled build.
User Impact
Lower allocation during directory event churn, with no change to watched paths, notification timing, credential identity checks, or configuration. Native filesystem event counts are unchanged.
Why This Change Was Made
Iterate the existing identity map directly and return at the first exact basename match. Undefined names and legacy auth names retain their refresh path. No cache, invalidation policy, exclusion list, or public API is added. Production delta is +3 lines: the explicit loop removes the temporary snapshot and per-event predicate while preserving matching and early return. Test-line delta is zero.
Evidence
Five interleaved base/candidate pairs, each replaying 256,000 unrelated rename events through 64 real auth owners and the directory-observer callback composition, with one retained database per directory. Native handles are mocked; allocation sampling and untraced CPU/GC runs are separate. Base:
d7acde6ae97e3e95c3ce4b07fb86cd6eb92db7fb.The benchmark's
--allocations --max-owner-bytes-per-event 100regression assertion fails on all five base runs and passes on all five candidate runs. Candidate owner samples span 57.38–72.23 B/event; base spans 242.73–256.56. The semantic test also passes on base; the allocation assertion is the red/green proof. A four-identity sensitivity run before mocking native handle setup measured 383.78→161.75 owner B/event.CPU host one-minute load was 25.9–31.1 (base) and 25.9–30.2 (candidate); a build was concurrently active. The paired CPU deltas were −11.52, −69.45, −7.91, +0.19, and −7.75 ms. Only two minor collections occurred per baseline run; no candidate or major collections occurred in these short windows. Baseline max GC pauses were 0.222/0.360/0.272/0.284/0.271 ms; candidate had none. Loop tails have only 112–386 samples/run and are context only. RSS/heap at the end of these short, non-normalized GC windows averaged 263.0/54.5 MiB base versus 276.1/59.4 MiB candidate; this is not retained-heap proof.
Reproduce the owner workload with:
Focused proof: auth file-state, worker, and owned-directory observation tests (27 passed); the final zero-growth test consolidation also passed (14 tests). Build passed (5m16s); changed-file lint/format passed. Export collision guard and both source-closure test files passed (32 tests). Test-line ceiling is inherited over budget; no baseline was changed and this diff adds zero test lines.
Independent subagent review (autoreview route unavailable): fresh context, complete diff and relevant owners, P2+ scoped clean. Autoreview itself refused the provider route because it did not match the operator configuration; no configuration was changed. The test-only consolidation preserves the reviewed branches.
The explicitly requested fast-path proof is used for this semantics-preserving owner allocation deletion. A bounded isolated Gateway watcher census is recorded below; no ten-minute A/B whole-Gateway performance claim is made. Native onchange allocation remains outside this fix.
The candidate-only, two-minute canonical-harness census used the built Gateway, 10,800 sessions, 40 plugins, 65 clients, mock turns/tools/native subagents and worktree churn. A synthetic 5,000-write/delete burst of an unrelated
watcher-probe.sqlite-journalfile in the observed agent directory delivered 235 rename notifications over the 15.007-second counter interval (940 events/min). These were the only watcher events during that interval; no recursive workspace watcher was implicated. Native event delivery rate is unchanged by this patch and was not measured in a separate base Gateway. The much higher production event incidence was not reproduced on macOS; the owner callback cost is established by the replay above.Candidate census context (not an A/B performance gate): main-thread CPU 10.79%, GC 0.227 s/min, event-loop p99 32.70 ms (5,604 samples), client sessions.list p99 106.26 ms and server handler p99 48.64 ms (265 samples each; below the p99 gating threshold), RSS 2,114 MiB, main heap 526.8 MiB. Eight mock turns completed with eight tool calls/results and twenty committed writes. Allocation rate was not sampled in this timing-only census.
The census ended at host load averages 15.02/20.60/19.67 (1/5/15 minutes). Measurements used the pre-rebase build; the final branch was rebased onto
caf3034ae081with the authored patch unchanged.