Repository navigation
improve(config): cut sync filesystem work on multi-agent config reads - #193841
vyctorbrzezowski merged 1 commit into
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: needs maintainer review before merge. What this changesThis PR limits filesystem case probes to resolved agent directories that share a normalized lowercase path. Example: An isolated macOS Gateway reads configuration for 32 agents with distinct existing directories.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR removes demonstrated filesystem work while preserving directory-collision detection; no actionable introduced defect was found. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherConfiguration loading and validation pass agent directories to the shared collision detector, which resolves filesystem identities and returns conflicting agent groups. flowchart TD
A[CLI config.get] --> B[Gateway config snapshot]
B --> C[Configuration validation]
C --> D[Resolve agent directory identities]
D --> E[Group lowercase candidates]
E --> F[Probe candidate case semantics]
F --> G[Report duplicate directories]
Technical reviewBest possible solution: Retain the focused candidate filter in the existing collision detector and complete normal ready-for-review CI before landing. Do we have a high-confidence way to reproduce the issue? Current-main source unconditionally probes every multi-agent directory, and contributor-supplied base Gateway traces demonstrate the cost; no target code was executed during this read-only review. Is this the best way to solve the issue? The smallest complete fix selects possible collisions inside the existing owner, preserves path resolution and per-candidate probes, and introduces no persistent cache or competing policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against bc47d05a49fb. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +11, Tests +8. Total +19 across 2 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. 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 HistoryReview history (1 earlier review cycle)
Reviewed November 5, 2026, 9:31 PM ET / November 6, 2026, 02:31 UTC (Revision 2). |
findDuplicateAgentDirs ran a sync filesystem case probe for every agent on every config snapshot read. Case folding can only merge paths that are equal ignoring case, so the probe now runs only for agents whose resolved directory matches another agent's when lowercased. The set of reported collisions is unchanged. At 32 agents this removes 192 lstat, 96 stat and 64 readdir calls per readConfigFileSnapshot with missing agent directories. In an isolated Gateway with 32 existing agent directories, each config.get that misses the response cache drops from 514 lstat and 64 readdir to 322 lstat and 0 readdir. The fs identity test now asserts that missing case variants are reported as one directory exactly when the volume is case-insensitive, the only case where the probe decides the result.
8012096 to
3dcd2ce
Compare
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
Thanks, @etzelm, for removing unnecessary case-sensitivity probes while preserving agent-directory collision checks. |
…nclaw#193841) Group resolved agent directory paths by their lowercase form before checking filesystem case sensitivity. Only potential collision groups run the existing per-path probe, while alias resolution and collision ordering remain unchanged. Strengthen the existing filesystem-identity test for missing case variants and probe cleanup.
Closes #193840
What Problem This Solves
Fixes: config reads, writes and reloads on multi-agent Gateways block the event loop on filesystem work that grows with agent count.
User Impact
User impact: multi-agent Gateways spend less sync I/O on every config snapshot read (
config.get, config writes, reloads and startup); the measured paths are theconfig.getcache miss and the watcher's re-read. At 32 agents each config snapshot read makes 192 fewerlstat, up to 96 fewerstatand 64 fewerreaddircalls. Duplicate agent directory detection reports the same collisions as before. There is no config or behavior change.Why This Change Was Made
Case folding can only merge two directories whose resolved paths are equal ignoring case.
findDuplicateAgentDirsnow resolves all agent directories first and runsisPathCaseInsensitiveonly for agents whose lowercased path matches another agent's. Every other agent keeps its resolved path as its key, and no folded key can equal that key, so the reported collision groups and their order are unchanged. Candidates still get the same per-path probe as before, which keeps the case-sensitive volume fix from #105402 intact.This removes the probe calls instead of caching them, so there is no new cache key to invalidate. I considered a per-volume memo and rejected it. Case sensitivity can differ between directories on the same device (Linux casefold, Windows per-directory case sensitivity), so a
devkey could change answers.Evidence
Isolated Gateway,
config.getthrough the shipped CLISeparate
pnpm builds of base14d9d554and this change, on the same Mac Studio (APFS, case-insensitive). Each run starts its ownopenclaw gateway runwith a temporaryHOME, state dir and config, a loopback port andauth: none. It is not the live Gateway. The config has 32 agents with distinct existingagentDirs andgateway.reload.mode: "off". A preload hook (NODE_OPTIONS=--import fs-count.mjs) counts syncfscalls in every thread of the Gateway process. The CLI processes are not counted. Each sample is oneopenclaw gateway call config.get --port <port> --json.config.getcaches its response per config revision while the config watcher is live, and the watcher stays live withreload.mode: "off". A repeated call on an unchanged file is therefore a cache hit. Each repeated sample is an edit cycle instead: rewrite the config (rename agenta0), wait 1.5 s, then callconfig.get. Every call returned the edited name, so each one was a cache miss.Four rounds in the order base, fix, base, fix, 10 edit cycles per run. Mean sync fs calls in the Gateway process:
config.getafter an edit (cache miss)config.getafter startconfig.get(5 calls)Each cache miss loses 192
lstatand 64readdir, and so does the watcher's re-read after each edit. These are the same per-read deltas thatprobe.mjsin the linked issue measures for existing directories. Per-calllstatwas 514 to 518 on base and 322 to 326 on the fix in every sample. The remaininglstatcalls come from path prefix resolution, which symlink alias detection still needs. Background timers add up to about 40existsSynccalls in some windows on both builds, including idle ones, so they are left out of the table.One fix run (round 2) stopped at the harness self-check
config.get missed the edit: the watcher had not seen the edit within 1.5 s while another job loaded the host. Round 4 replaces it. All other runs completed. Not measured:reload.mode: "hybrid"(a hot reload mixes reload work into each sample, sooffkeeps samples comparable) and a Linux or case-sensitive volume end to end (theagent-dirs.fs-identity.test.tscase-sensitive arm covers that branch).Genuine aliases are still rejected
In the same Gateway runs, the config was then rewritten to the 32 agents plus one alias pair, and
config.getandopenclaw config validatewere run. The output is byte-identical between base and fix in every completed round:Only the first and conflict lines of each message are shown. The rest is the fixed help text.
<tmp>is the run's temporary directory.One full run per build (redacted)
Commands and scripts
The
### run N ...headers and trailingexit 0lines in the log above come from a small wrapper around this loop that echoes the run label and exit status.fs-count.mjs:e2e-gateway.mjs:In-process counts per
readConfigFileSnapshotEarlier
pnpm builds ofee00ba6band this change onee00ba6bwere measured withprobe.mjsfrom the linked issue (60 reads per run, base, fix, base, fix).src/config/agent-dirs.tsis identical inee00ba6band14d9d554. This also covers missing directories, where each probe adds 3statcalls:Tests
src/config/agent-dirs.test.tsare removed. That file is unchanged from base, and the test-line allocation file is gone.src/config/agent-dirs.fs-identity.test.ts: the existing "missing directories" test now also asserts the result. Missing case variants (FutureState,futurestate) are reported as one directory exactly when the volume is case-insensitive (detected with a realmkdirandstat), and kept apart otherwise. It still checks that nothing is created or left behind. This is the only path where the fix's candidate filter decides the result. Existing case variants already resolve to their on-disk spelling, so they collide without folding. Mutation check: with folding disabled (false ? folded : resolved) the test is red on APFS (expected [] to deeply equal [ { …(2) } ]). With the fix it is green.pnpm test src/config/agent-dirs.test.ts src/config/agent-dirs.fs-identity.test.ts --maxWorkers=1: 2 files, 9 passed, 31.3 s wall. The changed file alone: 5 passed, 8.1 s wall (vitest 5.3 s).check-test-lines-ratchet.mts --base origin/main: OK, slack 21, no allocation.check-max-lines-ratchet.mts --base origin/main: OK. The baseline is unchanged.pnpm check:changed: exit 1, 414 s. 33 of 35 lanes pass, including typecheck core and core tests, lint, format, import cycles and the line-cap ratchet.Pre-existing gate failures (in files this PR does not touch; both fail the same way on base
14d9d554):changelog attributions: 26 "Thanks @steipete" lines inCHANGELOG/records/2026.11.1.md.scripts/check-changelog-attributions.mtsexits 1 on base.dead export scan: unusedsetSourceConfiginsrc/gateway/talk/handlers/catalog.test-support.ts.pnpm deadcode:exportsexits 1 on base.