Repository navigation
fix: avoid SQLite worker churn in forked Vitest tests - #164801
Conversation
Initialize the existing SQLite capability owner before each Vitest child can capture its worker policy. Keep config-process admission for thread inheritance and share the initializer with native-loader setup. Preserve the real conformance probe and conservative decisions.
|
🦞👀 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. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. Reviewed October 4, 2026, 2:50 AM ET / 06:50 UTC (Revision 2). ClawSweeper reviewWhat this changesInitialize SQLite capabilities before Vitest test collection in forked workers, share the bootstrap with setup fallbacks, and include preload files in test invalidation. Merge readiness✅ Ready for maintainer review This PR remains useful: current main lacks fork-local SQLite admission, and no actionable introduced defect was found. The supplied runtime measurements support the repair; the broader performance comparison remains preliminary. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw’s Vitest bootstrap prepares test processes before database consumers capture their worker lifecycle policy. SQLite admission determines whether those consumers can reuse workers after native resource cleanup. flowchart TD
A[Vitest configuration] --> B[Thread or fork worker]
B --> C[Worker preload or setup fallback]
C --> D[SQLite capability admission]
D --> E[Native close supported]
D --> F[Conservative cleanup]
E --> G[Test database workers]
F --> G
Before mergeNone. Agent review detailsSecurityNone. PR surfaceTests +13, Docs +4. Total +17 across 10 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Complete admission through the existing capability owner before test consumers capture policy, while retaining conservative cleanup and native-loader isolation. Do we have a high-confidence way to reproduce the issue? Yes: source identifies missing fork-local admission before immutable policy capture, and the supplied baseline Bun-fork regression demonstrates that path. This review did not execute it. Is this the best way to solve the issue? Yes: awaiting the existing admission owner at worker bootstrap repairs ordering without creating another policy owner or weakening conservative native-close handling. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 3052e3b93a0a. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
Keep parent SQLite admission Bun-only so native Node config fixtures do not require a runtime source loader. Admit every actual test child through the shared bootstrap, and include .mts bootstrap files in the existing watch and changed-selection inventory.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
Vitest's config-process SQLite admission did not reach Bun OS-fork children, so transcript-worker topology captured a conservative policy and repeatedly recreated workers. Await the existing capability initializer in the shared child bootstrap before collection, retaining real native-close validation, Bun thread inheritance, Node's existing policy, and conservative failure handling. Four before/four after runs on Node 24 and pinned Bun across six targets passed with unchanged before/after outcomes. Bun transcript starts fell 289→6 for compact hooks and 545→1 for canonical descendant; both gateway configs and spawn-production-boundary improved, while unit-src remained stable. All 96 qualifying samples were verified from raw reports and worker traces. Exact-head CI, focused regression coverage, P2 review, and ClawSweeper review passed.
What Problem This Solves
Fixes repeated SQLite transcript-worker starts when Vitest runs tests in OS forks on Bun. Admission completed in the config process, but
worker_threadsenvironment data did not cross the fork boundary. The child captured an undecided conservative policy and repeatedly retired workers.User Impact
Database-heavy test runs reuse admitted workers. This changes test bootstrap only: storage schemas, durability, admission semantics, conservative failure handling, and cache policies are unchanged. Test infrastructure shrinks by one line.
Why This Change Was Made
One shared bootstrap awaits the existing capability initializer before the native Vitest worker loads its runtime or test graph, with a shared-setup fallback for native-loader projects. Bun fork children run the existing real native-close conformance probe locally. Bun threads retain the config process's admitted decision. Node also forks in these configs, but its existing owner already supplies the supported Node capability; measurements confirm it does not have the same missing-admission defect.
Topology decisions are intentionally immutable, so initialization must precede collection rather than run in a later test hook. The collection-time regression now covers forks, and the existing watch/changed inventory includes
.mtspreloads.Evidence
Linux x64, one AWS c7a.4xlarge lease, CPUs 0–7, Node 24.19.0, pinned Bun
1.4.3-canary.1+c999d9cb9. Each target uses four before/four after invocations on each runtime in balanced ABBA order. Individual files use one worker; whole configs use a four-worker ceiling while retaining their pool, isolation, scheduling, and cache policies. Values are medians of complete command wall time and transcript-worker starts.All 96 qualifying runs pass, covering 18,432 file executions and 225,200 case outcomes. Total measured test-command wall cost is 28,475.062 seconds (7.910 hours), excluding setup, CI/review, source transitions, and the separately recorded exploratory/recovery work below. Unit-src remains stable: Node −0.47%, Bun +0.34%; median transcript starts remain 12 on both runtimes.
Outcome verification compares the complete sorted file/case/status inventory before and after, including skips. The five fork targets also match across runtimes. Unit-src retains three pre-existing Bun-only skips: the timeout-resource case in
src/meeting-bot/node-host.test.tsand the two authority-change cases insrc/node-host/pty-command.test.ts. Their source guards are unchanged. Every other cross-runtime unit-src outcome matches, with exact before/after equality within each runtime. Worker counts are reconstructed from native constructor traces; fractional counts in the table are medians of four integer counts.Neither gateway config retains a Bun/Node median above one, so the conditional residual-deficit profile is unnecessary. Compact's Vitest file time, excluding wrapper/startup/collection, falls from 102.530 to 17.651 seconds on Bun; its file-time Bun/Node ratio improves from 3.784× to 0.652×. Node timing/count variation is not attributed to missing admission: its traces already contain the positive
Node runtimecapability.Every invocation uses private mode-0700 HOME/state/temp/cache directories. The first unit-src Node baseline exposed an inherited harness umask of 077: a fixture requested mode 0444 but was created as 0400. That complete failed run is excluded and recorded separately (429.194 seconds; one failure, 7,307 passes, 29 skips). A direct mode reproduction and the unchanged 27-case file passed with normal test-process umask 022 (24.706 seconds), while all private roots remained 0700. All 16 qualifying unit-src samples use that corrected environment uniformly; the 80 fork samples retain their original environment. Source, binary, and tracer bindings match across these separately recorded cohorts. No assertion or product code was changed for this correction.
The measured admission code is byte-identical to the reviewed PR head. The final follow-up adds only
.mtswatch/changed-trigger inventory and its existing assertion; explicit benchmarkrunselections do not use those selectors. An earlier exploratory matrix stopped for the Node config-loader correction below is excluded.The Linux collection-time regression fails on baseline Bun forks and passes on baseline Bun threads; candidate Node and Bun pass in both pools. Existing admission/probe tests pass all 19 cases, including conservative decisions, errors, and cleanup. Node and pinned Bun each pass 12 focused bootstrap/jsdom assertions and 56 native-loader assertions. Changed checks pass, Madge reports zero cycles, and the committed branch is scoped-clean through P2 in Codex autoreview.
Initial CI exposed a native Node config-loader fixture without tsx. Retaining the original Bun-only parent guard fixes that loader boundary while child initialization remains unconditional; the full 21-case shutdown suite passes. The
.mtsinventory assertion reproduced its omission and the corrected 489-case project-config suite passes. Exact-head CI is green: https://github.com/openclaw/openclaw/actions/runs/37183769287. ClawSweeper completed review on the exact head with no findings.Changed-test cost uses
pnpm test <file> --maxWorkers=1on Node 24/macOS. CI times are from the successful exact-head run:The additional inventory membership assertion takes 0.001 seconds in CI and reuses the existing project-selection suite. No new process-launching regression suite was added.