Repository navigation
perf(workers): bound resident database and transcript heaps - #169110
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 caps shared SQLite and foreground transcript worker pools and adds per-script live and sampled worker counts. Example: A Node Gateway reports 64 available CPUs.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR provides a focused memory improvement that current main does not contain. The earlier Bun fixture finding is resolved; no actionable patch defect remains, and the reported CI failure is supported as inherited. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherGateway database commands and transcript reads enter existing worker owners, which return settled writes and read results; the worker registry supplies memory samples to the Prometheus exporter. flowchart TD
A[Gateway requests] --> B[Worker sizing owner]
B --> C[SQLite broker]
B --> D[Transcript reader pools]
C --> E[Worker resource registry]
D --> E
E --> F[Prometheus exporter]
Technical reviewBest possible solution: Land the focused sizing and census changes through the native maintainer workflow with the inherited UI failure recorded. Do we have a high-confidence way to reproduce the issue? Current-main sizing permits eight SQLite and foreground transcript workers on a 64-CPU input; the supplied compiled-owner comparison reports the resulting memory difference, but no new execution was performed in this review. Is this the best way to solve the issue? Reducing duplicated isolates in the existing sizing owner addresses the measured cause without adding scheduling machinery, and the exporter reuses the registry's complete fresh-or-missing census. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against ebdc7d54c084. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +17, Tests +24, Docs +9. Total +50 across 9 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 HistoryReviewed October 11, 2026, 10:43 AM ET / 14:43 UTC (Revision 3). |
|
The remaining CI failure is inherited UI typechecking, not a worker-lane regression. Run 38145733548 tested merge
Scoped worker/storage/exporter tests, all 28 core-test type graphs, extension types/tests, and lint passed. The corrected Bun/SQLite family also passed all 33 tests on the isolated Linux rig. The earlier global UI dead-export failure was separately reproduced on unchanged main and remains documented in the PR body. This qualifies for the requested inherited-failure landing exception. No CI rerun, update-branch push, deadcode suppression, or UI change is included. |
…#169110) * perf(workers): bound resident database and transcript heaps * test(workers): align native-close fixture with broker capacity
First-parent upstream 19fe879..0bc7491 (100 commits, including openclaw#169090 entry-writer postimages, openclaw#169201 transcript projection facts, openclaw#169113/openclaw#169107/openclaw#169125 session-actor admission, openclaw#169110 bounded worker heaps, openclaw#169130 inter-session provenance, openclaw#168931 Solid session UI). Conflicts: - session-accessor.sqlite-entry-mutation.ts: openclaw#169090 moved postimage publication into writeSessionEntry and replaced the revision-equality no-op check with postimages.changed. Took upstream's form; kept our recipient-authority advance on visibility narrowing (same transaction, after the write, before the no-op return). - session-accessor.sqlite-entry-store.ts: import union (upstream dropped withProjectedParticipants/SessionEntryWindowFacts imports; ours adds the recipient-authority advance). Overlay vs upstream is now 2 lines. - openclaw-tools.types.ts: import union (our RequestCompactionToolOpts, upstream's SessionsYieldRuntimeClaim). - plugin-sdk-surface-report.mts: upstream raised the budgets to 3672/2133; ours stays +11/+4 on top (3683/2137). - worker-access-inventory.md: regenerated on the merged tree. Auto-merged files that carry continuation overlay (21) keep the overlay byte-for-byte (interdiff of the +/- lines vs upstream before and after). Refs #1475 Co-Authored-By: Claude Opus 5.5 <[email protected]>
What Problem This Solves
High-core Gateways retain repeated copies of database and transcript runtimes after bursts, while aggregate worker-heap metrics hide how many isolates contribute to each script.
Related: #167295.
User Impact
Reduces resident and peak worker memory without changing stored data, schemas, configuration, permissions, or update behavior. Operators can compare per-script live-worker counts with sampled counts and heap bytes, including workers whose samples are unavailable.
Why This Change Was Made
Extend the existing two-worker reader policy to foreground transcript history and search. Cap the shared SQLite broker at two workers instead of scaling up to eight with CPU count. Keep the existing per-database ordering, independent reader lanes, admission, and native cleanup owners; no scheduling or cache layer is added. The SQLite minimum remains two even on small machines.
The exporter adds bounded
scriptseries toopenclaw_worker_countandopenclaw_worker_heap_sampled_count, retaining the existing unlabeled totals. Missing samples count as live workers, and retired script series are removed on the next sample.Production LOC: +17 overall. The sizing policy removes 3 net lines; the explicitly requested live/sample census adds 20 lines to the existing metric owner to account for missing samples and retire stale series. No new module, export, dependency, or configuration option. Two storage lifecycle fixtures now fill the actual broker budget instead of assuming four distinct workers; their retirement, carrier, and blocked-open assertions are preserved.
Evidence
Blacksmith Testbox
tbx_01m4n7pxwjh2a86rxv88z5jz0x, Node 24.19.0, four available CPUs. Both variants use the same synthetic fixture: 2,000 sessions across 20 agent databases, 20 transcripts with 1,000 4-KiB messages each, and 2,000 synthetic catalog models. A 64-CPU sizing override exercises the high-core policy; this is not a native 64-core throughput result. All 20 metadata writes settle before the concurrent 20-session full-transcript reads. Every read verifies its event count and final ID; all writes and the 2,000-entry listing are checked.Five-second idle observations use the production collector without forced GC. The comparison differs only in worker sizing. Build/rig commands:
pnpm build,node --import ./scripts/tsx.mjs .local/lane-760/build-worker-heap-rig.mts, andnode dist/lane-760-worker-heap-rig.mjs --root <fresh-state> --cpus 64.sqlite-store.worker.jssession-transcript.worker.jsprepared-model-catalog.worker.jsPeak transcript-worker population falls from nine to three in this fixture, including the independent projection worker. Post-burst RSS falls by 670 MiB (33%), sampled peak worker heap by 391 MiB (47%), and combined wall time by 2.57x. Five-second idle CPU is 1.2 ms before and 4.1 ms after; there is no additional timer or GC policy.
Separate heap snapshots were analyzed through
scripts/heap-snapshot-diff.mjs. They show substantial loaded-module/loader state in every isolate, not a large retained decoded-transcript cache. The catalog additionally retains its prepared plugin generation. Its source capture belongs to the inventory owner, so idle retirement could reload changed plugin code into an existing publication; that lifetime remains intact. The catalog's roughly 84 MiB does not shrink in this change. Snapshot runs are separate from the unforced comparison above.Validation completed so far:
tbx_01m4n7pxwjh2a86rxv88z5jz0x, both full production builds passed. The paired build/benchmark command exited 0 in 238.6 s; the separate retained-heap analysis exited 0 in 10.1 s.tbx_01m4nbjv55z6qp7p1rdtgqnpjr, the existing native broker test fails on old sizing because three opened stores use three workers instead of the expected two. The candidate's 11 broker tests and all 34 Prometheus service tests pass (39.63 s combined wrapper wall time). The 30 storage/generation lifecycle tests pass (45.54 s wrapper wall time).Rebased changed-file gate and baseline qualification on Blacksmith Testbox
tbx_01m4ncmhevy5kbpk25041d71z7, commit16493f280f5e5c58c1794d7f513956643a87be01: all guards, core types, 28 core-test type graphs, extension types, and extension-test types passed. The gate then failed only on unrelated UI dead exports. The unchanged current-main baseline3a0db8a3a05283c21600bc39e2772bf1432f7d0eindependently fails the samenode --import ./scripts/tsx.mjs scripts/check-deadcode-exports.mtsscan with the same chat exports, includingChatCiAutomation,ChatCiDetails,ChatClawHubCard, and the Solid tool-card/content/outcome hosts. The baseline has additional unrelated findings. No dead-export exception or suppression was added. The remaining native lint plan passed with zero warnings/errors, and all 47 assertions in the four changed test files passed again on that pinned commit. No guard was disabled; the failed global scan remains recorded as an inherited failure.Per-file cost on that Testbox, via
node scripts/run-vitest.mjs <file> --maxWorkers=1(thepnpm testwrapper):src/infra/sqlite-worker-broker.test.tssrc/infra/sqlite-worker-store.generation.test.tssrc/infra/sqlite-worker-store.test.tsextensions/diagnostics-prometheus/src/service.event-loop.test.tsHosted CI: the first head's run 38141089913 found one further stale four-worker expectation in
bun-sqlite-library.worker.test.ts; the fail-fast monitor cancelled the rest. Follow-up commit0d58e6166de7dabdbcdf0493661fd039ac1636f1changes its three admitted-worker expectations to two while retaining the five-worker conservative branch, alias sharing, reopen, and termination assertions. The entire Bun/SQLite family passes on the isolated Linux rig (Node 26.8.1): 33 tests across three files, 96.29 s wrapper wall / 91.48 s Vitest duration including cold worker compilation. The narrowed core-test type graph and final lint pass; the unrelated UI dead-export scan remains the sole local-gate failure. Independent P2 review of this follow-up is scoped-clean. Current-head CI run 38145733548 completed with 49 successful jobs, 8 fail-fast cancellations, and one originating failure: UI production types. The exact tested merge9705fb2a2d4cdd445823a4b91b185ff65acd51edhas main parent38f456226f626dd3868c2a4e754e75bf37b59e68; its entire UI tree, UI tsconfig, package manifest, lockfile, and typecheck wrapper match that parent byte-for-byte. The same six TS2322/TS2717 tab-panel errors reproduce on that untouched parent withnode scripts/run-tsgo.mjs -p tsconfig.ui.json(exit 2). Core and extension production types pass in the hosted job. Security-fast and Security Review passed. The inherited UI failure is retained explicitly for the authorized admin landing; cancelled checks are not counted as successful.The follow-up proof used
nice -n 10 ionice -c3 node scripts/run-vitest.mjs src/infra/bun-sqlite-library.worker.test.ts src/infra/bun-sqlite-library.capabilities.test.ts src/infra/bun-sqlite-close-probe.test.ts --maxWorkers=1, followed by the changed-test gate and its remaining native lint plan. Testbox expiry, an AWS workspace-renewal failure, and a Hetzner dependency-download 504 prevented earlier follow-up attempts from producing a test verdict; those are not passing proof. All performance measurements above remain the original paired Testbox measurements.Limits: synthetic production-owner paths with compiled workers, not a full deployed Gateway or production-memory projection. No live Gateway was accessed. Catalog generation retention is unchanged; the improvement comes from fewer duplicate database/transcript isolates.
The initial changed-file gate found an unrelated pre-existing max-lines suppression in
src/web-search/runtime.test.ts. The branch was rebased onto current main, including existing fixcedb310b3ab1; no unrelated fix was copied into this diff.