Skip to content

improve: reduce SQLite snapshot process startup cost - #144022

Merged
steipete merged 2 commits into
mainfrom
codex/perf-snapshot-child-imports
Sep 10, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/perf-snapshot-child-imports

Conversation

@steipete

@steipete steipete commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

SQLite snapshot processes repeatedly load parent-side launch and logging code that they do not use. In the measured update CLI suite, 5,226 synchronous snapshot processes accounted for about 85% of elapsed time, making their cold imports a significant test and command cost.

Why This Change Was Made

Move the existing public snapshot-routing functions into the existing snapshot-source orchestration module. Keep copying, recovery, staging, adoption and the single cleanup registry in their current low-level owner. The child argument stays unchanged and moves to the shared process-entrypoint module; the pure SQLite error predicates move out of transaction logging into the existing diagnostics module.

All callers follow the owning modules. The plugin SDK façade keeps the same export names and types, and the test-only compiled library entry follows its implementation. The actual worker entry, arguments, budgets, copy algorithms, cancellation, process isolation, source preservation and ownership checks are unchanged. Two moved field reads use the existing equivalent object coercer, retiring two assertions without adding baseline allowance.

User Impact

The measured native snapshot child starts faster without changing update, Doctor, database or plugin behavior. No flags, caches, worker pools, schema or persistence changes are introduced. Most of the 47-file diff updates imports; production is +19 net lines for the internal owner boundary, tests/support +4, and assertion baseline -1 row. No test case, assertion or timeout is removed or weakened.

Evidence

  • Real managed compiled-child A/B/A: median 110.752 / 87.944 / 114.255 ms across three native children per leg. The original ledger case passes in every leg. The verified static dependency closure is 67 / 47 / 67 modules, 462,705 / 307,340 / 462,705 bytes.
  • Whole wrapper time is 8.15 / 6.77 / 6.63 seconds, including ordinary build, inspection and cleanup; this does not establish a whole-wrapper or full-CI speedup. Reported whole-command maximum RSS is 2,296,840,192 / 2,306,850,816 / 2,299,084,800 bytes; no memory reduction is claimed.
  • Same Node 24.19.0, pnpm 12.3.4, frozen dependencies, original test source and source-only root layout. The temporary observer forwarded native arguments/options/results unchanged, stayed outside the child graph, and captured files after the child timer. It was removed before correctness checks. Every recorded process exited, generated worker directories were removed by their normal owner, and source/dependency seals matched.
  • 339 focused tests passed: snapshot copy/cancellation/worker behavior, actual SQLite transaction/coordinator and read-only callers, Doctor/Gateway/state ownership, the two source/build artifact cases, and all 16 real subprocess repair/finalize output cases. The Linux-specific live-WAL POSIX lock case passed in CI (194 ms); current-main fresh/expired/retained history rows also passed. The remaining 32 artifact cases were deliberately filtered; no other broad success is implied.

Full pnpm build passed in 240.97 seconds, the correctly scoped pnpm check:changed --base a265abfecad458603578d72395a8dde6f5d3eadc passed, and the built iMessage entrypoint profile passed (98.44 MB peak RSS; no comparative memory claim). The initial CI run exposed an omitted export in the subprocess fixture’s prepared-entrypoint substitute; it now forwards the canonical child marker while preserving prepared worker locations. The existing JSON case failed before that fix, then all 16 process cases passed. A separate documentation expectation failure was repaired upstream in #144037. Independent review has no accepted actionable P0–P2 findings; the fixture follow-up is scoped-clean through P2. Fresh full CI must pass before landing. This is not a live installed-package update or a claim that the eight-minute CI objective is complete.

@clawsweeper

clawsweeper Bot commented Sep 10, 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.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime cli CLI command changes scripts Repository scripts commands Command implementations agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Sep 10, 2026
@steipete
steipete marked this pull request as ready for review September 10, 2026 12:13
@steipete
steipete requested a review from a team as a code owner September 10, 2026 12:13
@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 Sep 10, 2026
@clawsweeper

clawsweeper Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 10, 2026, 9:29 AM ET / 13:29 UTC (Revision 2).

ClawSweeper review

What this changes

Moves SQLite snapshot orchestration and error classification out of the child process’s import path, reducing startup overhead while preserving snapshot behavior and plugin exports.

Merge readiness

✅ Ready for maintainer review

This remains a useful, measured performance improvement absent from inspected main and the latest release. No actionable introduced defect was found, and the follow-up fixture repair preserves the existing validation boundary.

Priority: P2
Reviewed head: 100178478fd3d63ddcfc280169586d94b4e7616b

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, behavior-preserving optimization with relevant native-process measurements and no actionable findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The captured body reports real compiled SQLite snapshot children exercising the original ledger scenario on Node 24.19.0, with lower after-change startup medians and successful results in every A/B/A leg. This directly covers the changed child import boundary; the reported focused tests and build supplement it.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The captured body reports real compiled SQLite snapshot children exercising the original ledger scenario on Node 24.19.0, with lower after-change startup medians and successful results in every A/B/A leg. This directly covers the changed child import boundary; the reported focused tests and build supplement it.
Evidence reviewed 9 items Introduced implementation preserves routing: The complete local merge-base delta moves the async and sync orchestration bodies into sqlite-snapshot-source without changing exclusion checks, cancellation checks, worker modes, staging ownership, or cleanup behavior. Copying and the single cleanup registry remain in sqlite-readonly-location.
Worker and SDK contracts retained: The worker imports the unchanged child marker from runtime-process-entrypoints instead of the parent launcher. The sqlite-runtime façade retains both snapshot export names and signatures; no new plugin API, configuration, schema, or authority contract is introduced.
Equivalent error coercion: The inspected workspace implementation of asOptionalObjectRecord accepts the same non-null object values, including arrays, as the former inline checks. SQLite result-code classification remains unchanged.
Findings None None.
Security None None.

How this fits together

OpenClaw’s update, Doctor, and database readers use private SQLite snapshots to inspect state safely. Parent orchestration selects an existing owner or isolated child process, then returns a snapshot with cleanup ownership.

flowchart TD
  A[Update and database readers] --> B[Snapshot orchestration]
  B --> C{Existing source ownership?}
  C -->|Yes| D[Owner-coordinated snapshot]
  C -->|No| E[Isolated SQLite child]
  D --> F[Private snapshot]
  E --> F
  F --> G[Read and clean up]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +19, Tests +4, Other -1. Total +22 across 47 files.

View PR surface stats
Area Files Added Removed Net
Source 27 177 158 +19
Tests 18 28 24 +4
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 2 1 2 -1
Total 47 206 184 +22

Review metrics

Metric Value Why it matters
Reported native-child startup 110.752 / 87.944 / 114.255 ms A/B/A medians Three native children per leg support a bounded startup improvement, without establishing whole-command speedup.
Production versus test growth Production +19 net lines; tests/support +4 The small production increase supports separating orchestration from the child’s dependency graph.

Technical review

Best possible solution:

Keep parent launch and logging dependencies outside the native snapshot child while retaining the existing isolation, ownership, cleanup, and SDK contracts.

Do we have a high-confidence way to reproduce the issue?

Not applicable as a correctness bug: this is a performance optimization, supported by reported native-child A/B/A measurements and the inspected import graph.

Is this the best way to solve the issue?

Yes. Moving the existing orchestration and pure predicates removes unnecessary child imports without introducing pooling, caching, duplicate snapshot logic, or a new public contract.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against c973fe7e7219.

Labels

Label justifications:

  • P2: This is a measured internal startup improvement with preserved behavior and no demonstrated urgent user regression.
  • 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 (terminal): The captured body reports real compiled SQLite snapshot children exercising the original ledger scenario on Node 24.19.0, with lower after-change startup medians and successful results in every A/B/A leg. This directly covers the changed child import boundary; the reported focused tests and build supplement it.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured body reports real compiled SQLite snapshot children exercising the original ledger scenario on Node 24.19.0, with lower after-change startup medians and successful results in every A/B/A leg. This directly covers the changed child import boundary; the reported focused tests and build supplement it.

Evidence

What I checked:

  • Introduced implementation preserves routing: The complete local merge-base delta moves the async and sync orchestration bodies into sqlite-snapshot-source without changing exclusion checks, cancellation checks, worker modes, staging ownership, or cleanup behavior. Copying and the single cleanup registry remain in sqlite-readonly-location. (src/infra/sqlite-snapshot-source.ts:24, 100178478fd3)
  • Worker and SDK contracts retained: The worker imports the unchanged child marker from runtime-process-entrypoints instead of the parent launcher. The sqlite-runtime façade retains both snapshot export names and signatures; no new plugin API, configuration, schema, or authority contract is introduced. (src/plugin-sdk/sqlite-runtime.ts:23, 100178478fd3)
  • Equivalent error coercion: The inspected workspace implementation of asOptionalObjectRecord accepts the same non-null object values, including arrays, as the former inline checks. SQLite result-code classification remains unchanged. (packages/normalization-core/src/record-coerce.ts:36, 100178478fd3)
  • Previous review and fixture follow-up: The supplied completed review reported no findings. Comparing its reviewed head with this head shows only the fixture change forwarding the canonical child marker while retaining prepared worker locations. The captured body reports that the existing JSON case failed before this correction and all 16 subprocess cases passed afterward. (src/cli/update-finalization-output.test-support.ts:115, 100178478fd3)
  • Native-child performance proof: The complete captured PR body, sourceRevision 5823ea733859b76090d4e1216fc9fe3bcf2c3dc9de4752090c6b248c0c399070, reports a managed compiled-child A/B/A run on Node 24.19.0 with unchanged native arguments and the original ledger case passing in every leg. Median child times were 110.752/87.944/114.255 ms; dependency closures were 67/47/67 modules. The body explicitly excludes whole-update, full-CI, and memory-reduction claims. Its 339 focused tests, build, changed checks, and entrypoint profile are supplemental reported validation, not reviewer-executed checks. (100178478fd3)
  • Still necessary on inspected main: The fetched main worker still imports the child marker from sqlite-readonly-worker, retaining the parent-launch dependency this PR removes. (src/infra/sqlite-readonly-location.worker.ts:7, c973fe7e7219)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • fuller-stack-dev: 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-09-10T12:20:29.407Z sha dc7340c :: needs maintainer review before merge. :: none

@steipete
steipete merged commit 8de89ef into main Sep 10, 2026
185 checks passed
@steipete
steipete deleted the codex/perf-snapshot-child-imports branch September 10, 2026 14:12
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling cli CLI command changes commands Command implementations gateway Gateway runtime maintainer Maintainer-authored PR 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. scripts Repository scripts size: M 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