Skip to content

improve(update): reduce inventory latency for large runtimes - #166741

Merged
vincentkoc merged 3 commits into
mainfrom
perf/runtime-retention-profile-20261007
Oct 8, 2026
Merged

vincentkoc merged 3 commits into
mainfrom
perf/runtime-retention-profile-20261007

Conversation

@hannesrudolph

@hannesrudolph hannesrudolph commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

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 874f475e244f5e0480367dd1f9d2113198f84592 adds 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 (tree a923db27d50fe82229fc2eb0afc592fcc15606b4).

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.

Runtime / limit Before → after wall time Before → after peak RSS Before → after process CPU
Node / unrestricted, two-run mean 6.89 → 6.35 s 551.6 → 554.8 MiB 15.94 → 14.51 s
Node / 1 GiB 8.45 → 8.60 s 447.0 → 364.8 MiB 19.97 → 12.29 s
OpenClaw Bun / unrestricted, two-run mean 7.46 → 4.98 s 613.7 → 534.6 MiB 18.27 → 6.29 s
OpenClaw Bun / 1 GiB 7.87 → 5.33 s 635.4 → 538.8 MiB 19.37 → 6.74 s

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.

  • Reproduction: with the original two production files restored, nine of the ten new regression cases fail: constrained/unknown-resource admission and forbidden eager imports. All ten pass with this repair.
  • 24 distinct focused tests pass, covering real workers, native/portable copying, identity replacement, lifecycle drain/retirement, and resource admission. The ten new cases with --maxWorkers=1 take 28.84 s including compiled-worker preparation (58.61 process CPU seconds); test bodies take under one second.
  • Scoped six-file type-aware lint passes (7.07 s); core and infra-test type graphs pass (126.33 s); formatting and diff checks pass.
  • Full candidate pnpm build passes (375.01 s, peak build-process RSS 8.33 GiB).
  • Published 2026.9.8 → source candidate b494c3968e3c236901d5666d2366e2682b32a09f passes via scripts/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.
  • Candidate tarball SHA-256: 411d7e27943d2c9ff50c232a5018e4eb6d60cc90088f5efa9ed24b0c50859e7e; canonical package inventory/import-graph checks pass.
  • Resource and byte-inventory proof, committed-head checks, build, package and published-driver proof. Provider: Blacksmith Testbox; wrapper exit status is authoritative for delegated commands, and both task leases were stopped after completion.

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 5077ad4f99aa0677d089818aeda4f68ce347f16f to original head 880c3e12ce66a021f9689d5726ea3068b75bdb15, 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.

@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 7, 2026
@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 8, 2026, 4:33 AM ET / 08:33 UTC (Revision 3).

ClawSweeper review

What this changes

The branch parallelizes large update inventories within available CPU and memory capacity and avoids loading state-inspection modules into file workers.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Useful, focused performance work with resource-qualified admission, preserved integrity, and relevant real execution and upgrade evidence.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Recorded Linux production-owner inventory runs exercise 131,075 files with verified digests under unrestricted and 1 GiB/no-swap conditions; the published 2026.9.8 CLI transaction verifies candidate activation, readiness, and session preservation. Evidence is bound to b494c39, whose production code is unchanged at the reviewed head. No stored-data contract changes; final-head macOS and Windows performance remain unmeasured.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes
User problem: Updates with large runtime or plugin inventories spend substantial time hashing files, and unconditional worker concurrency adds memory pressure.
Reason: The measured improvement is useful and stays within the existing updater architecture. The recorded maintainer decision resolves resource admission without adding configuration or changing update semantics.

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
Reviewed head: 874f475e244f5e0480367dd1f9d2113198f84592

Before merge

None.

Findings

None.

Agent review details

How this fits together

Before 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]
Loading

Technical review

Best 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

Testing

Proof path: shipped entry point. Added test files: 5.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 75779e3 adds src/infra/update-candidate-plugin-tree.ts:186 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 75779e39d6bc; files: src/infra/update-candidate-plugin-tree.ts)
  • Hannes Rudolph: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • vincentkoc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

PR surface

Source +141, Tests +400. Total +541 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 3 176 35 +141
Tests 5 405 5 +400
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 581 40 +541

Review metrics

Metric Value Why it matters
Production versus test growth production +141 net lines; tests +400 net lines Production growth establishes bounded hashing admission and lifecycle handling; test growth covers resource refusal, integrity, and settlement.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P2: This is a bounded update performance improvement with measured large-inventory benefits.
  • merge-risk: 🚨 availability: Additional workers consume memory; the recorded maintainer decision accepts resource-aware admission, supported by constrained-host measurements, without promising a total RSS cap.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-07T21:02:09.455Z sha 880c3e1 :: blocked before merge. :: none
  • reviewed 2026-10-07T22:13:10.859Z sha 880c3e1 :: blocked before merge. :: none

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.
@vincentkoc vincentkoc self-assigned this Oct 8, 2026
@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

Please review exact head b494c3968e3c236901d5666d2366e2682b32a09f. The resource-policy decision is resolved in favor of CPU/memory-aware admission, with in-process hashing when additional workers cannot be qualified. Both requested validations now pass: the matched 1 GiB/no-swap inventory comparison and the published 2026.9.8 updater-to-candidate transaction. The PR body records complete timings, byte verification, exact build identity, and the limitation that unrestricted Linux Node RSS did not decrease.

@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@vincentkoc
vincentkoc marked this pull request as ready for review October 8, 2026 08:22
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Oct 8, 2026
@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

Please review exact head 874f475e244f5e0480367dd1f9d2113198f84592. Since the prior request, the only change is one required mock-isolation explanation on the diagnostics rejection mock. The repository scanner reproduces the prior failure and passes the corrected text. Production files and test behavior are unchanged from measured repair b494c3968e3c236901d5666d2366e2682b32a09f; all resource, byte-integrity and published-driver evidence remains explicitly bound to that commit in the PR body. This supersedes the prior requested head.

@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Oct 8, 2026
@vincentkoc
vincentkoc merged commit f686ee6 into main Oct 8, 2026
124 checks passed
@vincentkoc
vincentkoc deleted the perf/runtime-retention-profile-20261007 branch October 8, 2026 08:38
@vincentkoc

Copy link
Copy Markdown
Member

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 9, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants