Skip to content

fix: avoid SQLite worker churn in forked Vitest tests - #164801

Merged
steipete merged 2 commits into
mainfrom
fix/sqlite-vitest-child-admission
Oct 4, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/sqlite-vitest-child-admission

Conversation

@steipete

@steipete steipete commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

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_threads environment 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 .mts preloads.

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.

Target Node wall before → after Bun wall before → after Bun/Node before → after Node starts Bun starts
compact.hooks 65.098 → 64.997 s 137.519 → 52.477 s 2.113× → 0.807× 6 → 6 289 → 6
canonical-descendant 118.613 → 118.560 s 264.656 → 93.995 s 2.231× → 0.793× 1 → 1 545 → 1
gateway-methods-isolated 105.056 → 103.053 s 189.199 → 85.300 s 1.801× → 0.828× 38 → 36 319 → 34
gateway-methods 904.027 → 901.569 s 986.377 → 730.575 s 1.091× → 0.810× 424.5 → 429 2,689 → 413
agents-spawn-production-boundary 196.714 → 196.616 s 224.158 → 135.736 s 1.140× → 0.690× 4 → 4 345 → 4
unit-src 378.786 → 377.006 s 342.357 → 343.533 s 0.904× → 0.911× 12 → 12 12 → 12

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.ts and the two authority-change cases in src/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 runtime capability.

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 .mts watch/changed-trigger inventory and its existing assertion; explicit benchmark run selections 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 .mts inventory 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=1 on Node 24/macOS. CI times are from the successful exact-head run:

Existing test file Local wall CI execution
SQLite admission regression 4.56 s 0.001 s (one assertion)
Native preload boundary 6.79 s 0.193 s / 3 cases
jsdom compatibility 6.63 s 0.592 s / 8 cases
Project/config inventory 78.72 s 61.602 s / 489 cases

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.

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.
@clawsweeper

clawsweeper Bot commented Oct 4, 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.

@steipete
steipete marked this pull request as ready for review October 4, 2026 06:29
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: XS labels Oct 4, 2026
@steipete

steipete commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 4, 2026
@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 4, 2026, 2:50 AM ET / 06:50 UTC (Revision 2).

ClawSweeper review

What this changes

Initialize 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
Reviewed head: 8e6f76cf22112688cc430f48d12e04a7425ee1f5

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with relevant real-runtime measurements and no concrete introduced correctness or security finding.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The supplied Linux Node/Bun fork-and-thread runs exercise Vitest’s actual bootstrap and SQLite worker lifecycle; corrected compact-hooks output reports 289 → 6 Bun transcript starts with identical passing assertions. The larger benchmark is unfinished, but the focused after-fix result demonstrates the changed behavior. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The supplied Linux Node/Bun fork-and-thread runs exercise Vitest’s actual bootstrap and SQLite worker lifecycle; corrected compact-hooks output reports 289 → 6 Bun transcript starts with identical passing assertions. The larger benchmark is unfinished, but the focused after-fix result demonstrates the changed behavior. No stored-data contract changes.
Evidence reviewed 7 items Pinned introduced change: The merge-base-to-head diff adds one awaited admission bootstrap, invokes it inside recognized Vitest workers and shared setup, preserves Bun-only parent admission, and registers .mts invalidation paths.
Current-main necessity: Fetched main’s native worker preload has no SQLite admission call, and its shared setup has no admission import. The branch therefore supplies a missing process-local initialization path rather than duplicating an existing supported path.
Existing capability owner preserved: The existing owner memoizes admission, immediately supplies Node’s capability, retains conservative Windows and failed-probe decisions, and keeps captured topology policy immutable. The patch changes invocation timing without modifying this policy, schemas, or persisted state.
Findings None None.
Security None None.

How this fits together

OpenClaw’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
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Tests +13, Docs +4. Total +17 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 9 32 19 +13
Docs 1 4 0 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 36 19 +17

Review metrics

Metric Value Why it matters
Observed Bun worker starts 289 → 6; 87 assertions pass The preliminary real-runtime comparison directly measures the churn this bootstrap repair targets.

Technical review

Best 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.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This repairs bounded test-infrastructure performance without changing application storage behavior.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The supplied Linux Node/Bun fork-and-thread runs exercise Vitest’s actual bootstrap and SQLite worker lifecycle; corrected compact-hooks output reports 289 → 6 Bun transcript starts with identical passing assertions. The larger benchmark is unfinished, but the focused after-fix result demonstrates the changed behavior. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied Linux Node/Bun fork-and-thread runs exercise Vitest’s actual bootstrap and SQLite worker lifecycle; corrected compact-hooks output reports 289 → 6 Bun transcript starts with identical passing assertions. The larger benchmark is unfinished, but the focused after-fix result demonstrates the changed behavior. No stored-data contract changes.

Evidence

What I checked:

  • Pinned introduced change: The merge-base-to-head diff adds one awaited admission bootstrap, invokes it inside recognized Vitest workers and shared setup, preserves Bun-only parent admission, and registers .mts invalidation paths. (test/vitest/vitest.sqlite-preload.mts:1, 8e6f76cf2211)
  • Current-main necessity: Fetched main’s native worker preload has no SQLite admission call, and its shared setup has no admission import. The branch therefore supplies a missing process-local initialization path rather than duplicating an existing supported path. (test/vitest/vitest.jsdom-preload.mts:6, 3052e3b93a0a)
  • Existing capability owner preserved: The existing owner memoizes admission, immediately supplies Node’s capability, retains conservative Windows and failed-probe decisions, and keeps captured topology policy immutable. The patch changes invocation timing without modifying this policy, schemas, or persisted state. (src/infra/bun-sqlite-library.ts:38, 8e6f76cf2211)
  • Runtime behavior evidence: The captured PR body reports Linux x64 runs on Node 24.19.0 and pinned Bun c999. Corrected compact-hooks runs pass the same 87 assertions; Bun transcript starts fall from 289 to 6 and wall time from 137.24 to 52.25 seconds, while Node starts remain 6. These are explicitly single samples, not final medians. Collection-time admission fails on baseline Bun forks and passes after the fix in both pools. (8e6f76cf2211)
  • Re-review continuity: The previous completed review of 52cea38 recorded no findings. The subsequent change restores Bun-only parent initialization for native Node config loading and extends preload invalidation. The supplied body reports the corrected shutdown and project-config suites passing. (test/vitest/vitest.shared.config.ts:31, 8e6f76cf2211)
  • Area history and routing: Available current-main history connects Peter Steinberger to SQLite capability lifecycle work and earlier Vitest SQLite preparation. Deeper blame and some historical blobs could not be inspected because object retrieval returned 403; introduction attribution is therefore not claimed. (src/infra/bun-sqlite-library.ts, fcd59e6bdfdb)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-04T06:34:16.952Z sha 52cea38 :: needs maintainer review before merge. :: none

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.
@steipete

steipete commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete steipete self-assigned this Oct 4, 2026
@steipete
steipete merged commit f4870f5 into main Oct 4, 2026
106 of 110 checks passed
@steipete
steipete deleted the fix/sqlite-vitest-child-admission branch October 4, 2026 14:50
@steipete

steipete commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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.

1 participant