Repository navigation
improve(update): reduce inventory latency for large runtimes - #166741
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. Reviewed October 8, 2026, 4:33 AM ET / 08:33 UTC (Revision 3). ClawSweeper reviewWhat this changesThe branch parallelizes large update inventories within available CPU and memory capacity and avoids loading state-inspection modules into file workers. Review scores
ProductKind: Performance · Worth it: Yes Merge readiness✅ Ready for maintainer review This PR remains useful and has no identified blocking defect. The resource-aware repair and recorded update proof resolve the earlier concerns; the final head preserves the measured production code. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherBefore replacing an installation, the updater inventories runtime and plugin files for private validation and retention. This subsystem produces file identities and content hashes used to verify subsequent copies. flowchart TD
A[Runtime and plugin files] --> B[Inventory discovery]
B --> C[Small inventory or insufficient resources]
C -->|Yes| D[In-process hashing]
C -->|No| E[Bounded hash workers]
D --> F[Verified file inventory]
E --> F
F --> G[Guarded private copies]
Technical reviewBest possible solution: Keep the resource-qualified hashing path and existing integrity owner, with performance claims bounded to the measured environments. Do we have a high-confidence way to reproduce the issue? Not applicable as a functional bug reproduction; recorded counterbalanced inventory measurements establish the performance problem and resource tradeoff, without a reviewer-side execution. Is this the best way to solve the issue? Yes. It reuses the existing hash verifier and worker transport while preserving discovery ownership, bounded reads, copy verification, and retirement ordering. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against fc3e09736432. Provenance checked
TestingProof path: shipped entry point. Added test files: 5. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +141, Tests +400. Total +541 across 8 files. 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 History |
Keep the state-inspection module graph out of file worker isolates. Reserve memory and CPU capacity before admitting hash workers, and retain pinned in-process hashing when runtime memory accounting cannot qualify a pool.
|
@clawsweeper re-review Please review exact head |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review Please review exact head |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…w#166741) * improve(update): reduce inventory latency for large runtimes * fix(update): bound inventory hashing by available resources Keep the state-inspection module graph out of file worker isolates. Reserve memory and CPU capacity before admitting hash workers, and retain pinned in-process hashing when runtime memory accounting cannot qualify a pool. * test(update): explain diagnostics mock isolation --------- Co-authored-by: Vincent Koc <[email protected]>
Related: #160693
Related: #166317
What Problem This Solves
Large update inventories spend substantial time hashing runtime and plugin files; an unconditional four-worker pool adds memory pressure on constrained hosts.
User Impact
Large inventories can use parallel hashing within the available CPU and memory budget. Small inventories and hosts that cannot safely admit workers keep the existing in-process hash path.
This limits added worker concurrency, not total updater RSS. The unrestricted Linux Node measurements below showed no RSS reduction. Final-head macOS/APFS and Windows performance remain unmeasured.
Why This Change Was Made
After the first 1,023 files, sample available resources once. Reserve one CPU and half the available memory, budget 256 MiB per worker, and admit at most four workers. Unknown/insufficient capacity uses in-process hashing. The pinned OpenClaw Bun fork reports host memory on Linux even inside a cgroup, so that runtime stays in-process.
File workers no longer eagerly load the subprocess-only state/database inspection modules. The existing four-file read window, pinned-descriptor hashes, lossless identity metadata, stop-and-drain behavior, worker retirement, copy guards, leases, activation, rollback, and exact-version checks remain intact. No new configuration or storage surface.
Evidence
Current head
874f475e244f5e0480367dd1f9d2113198f84592adds only the required mock-isolation explanation to one regression test after the measured repair. Production files and test behavior are unchanged. The exact failed mock-export check was reproduced with the repository scanner on the prior test text and passes on the corrected text using qualified tooling dependencies; formatting and diff checks pass. The build, package, performance and published-driver evidence below remains explicitly bound to the measured commit.Resource repair: original PR head
880c3e12ce66a021f9689d5726ea3068b75bdb15→b494c3968e3c236901d5666d2366e2682b32a09f(treea923db27d50fe82229fc2eb0afc592fcc15606b4).Same isolated Linux Blacksmith Testbox, four available CPUs, 15.4 GiB RAM, Node 24.19.0, OpenClaw Bun 1.4.3-canary.1+667c4ab22 (fork commit
667c4ab22cbf6b101b3376c550b81cabc8c00518). The canonical compiled-worker builder produced both variants from identical dependency inputs.Synthetic inventory: 131,075 files, including 131,072 × 4 KiB deterministic payloads (512 MiB) and three plugin metadata/entry files. Normal runs used two counterbalanced pairs per runtime; constrained runs used one pair per runtime in a kernel-enforced 1 GiB cgroup with no swap.
All 12 cells completed with zero OOM events and swaps. This workload did not reproduce an OOM in the original PR. Capped runs reduced Node RSS 18.4% and Bun RSS 15.2%; Node elapsed time was essentially unchanged. Normal-run timing varied (Node before 5.46–8.33 s, after 5.89–6.82 s), so these small samples are not a broad latency guarantee.
Every before/after inventory matched within its runtime. An additional candidate-only check independently verified every returned digest and size against the source bytes on both runtimes, then confirmed equal canonically sorted inventories. The initial aggregate harness incorrectly required cross-runtime listing order equality; that harness assertion was corrected and verified without repeating the A/B measurements.
--maxWorkers=1take 28.84 s including compiled-worker preparation (58.61 process CPU seconds); test bodies take under one second.pnpm buildpasses (375.01 s, peak build-process RSS 8.33 GiB).b494c3968e3c236901d5666d2366e2682b32a09fpasses viascripts/e2e/published-driver-update-docker.sh: 302.31 s for the cell; the actual update takes 235.04 s. Both packages carry version 2026.9.8; the harness verifies the candidate's exact installed build-info, completed durable run, changed service PID, readyz=200, running version, preserved durable session, and cleared incognito session. This is a same-version candidate update, not a release-version transition.411d7e27943d2c9ff50c232a5018e4eb6d60cc90088f5efa9ed24b0c50859e7e; canonical package inventory/import-graph checks pass.The Linux measurements are component inventory results, not whole-update or downtime projections. The published-driver transaction is isolated synthetic-state proof; no production upgrade or fleet operation is part of this PR.
Original contributor evidence and credit
Hannes Rudolph authored the original hashing implementation. His earlier macOS/APFS comparison bound baseline
5077ad4f99aa0677d089818aeda4f68ce347f16fto original head880c3e12ce66a021f9689d5726ea3068b75bdb15, using 154,695 files / 176,181 planned entries and three counterbalanced inventory pairs per runtime. Node 26.7.0 median inventory time fell 120.313 → 79.156 s while RSS rose 424.4 → 1032.3 MiB; Bun 1.4.3 time fell 110.306 → 65.942 s while RSS rose 1031.4 → 1249.3 MiB. These are historical pre-resource-repair measurements, not final-head macOS proof.The resource repair adds 26 net production lines and 147 test lines. The complete PR adds 141 net production lines and 400 test lines; production growth owns bounded parallel hashing and its admission/lifecycle boundary. Staging and the broader retirement issue remain outside this change.