Skip to content

perf(state): load SQLite command domains without fallback runtime - #172071

Merged
steipete merged 3 commits into
mainfrom
steipete/perf-micro-sqlite-worker-heaps-20260919
Oct 14, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/perf-micro-sqlite-worker-heaps-20260919

Conversation

@steipete

@steipete steipete commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Shared-state SQLite workers load unrelated command modules before serving an operation already owned by the lazy domain registry.

User Impact

Registered operations can execute without retaining the fallback command graph. Results, schemas, worker lifetimes, writer admission, and committed receipts are unchanged. A worker that subsequently needs a fallback command still loads that graph; this is not a claim that every long-lived worker becomes smaller.

Why This Change Was Made

The existing shared-state backend now prepares and executes registered domains directly. The fallback runtime no longer duplicates registry routing or carries its unused admitted-write argument. Specialized worktree, device/restart, plugin-state, and GitHub source preparation keep their precedence. Mixed namespaces still check the exact prepared operation before falling back.

Production TypeScript is net +4 lines. The small conditional preparation helper preserves the transport contract that only an actual module load returns a Promise and triggers a compile-cache flush; warm operations continue returning undefined. No new cache, worker pool, configuration, or schema.

Evidence

  • Production telemetry already has bounded per-script heap labels. The motivating read-only sample reported 361.83 MiB across session-transcript workers and 190.77 MiB across SQLite-store workers. This patch addresses registered shared-state commands; transcript-worker retention remains a follow-up.
  • Regression through real backend preparation/execution: original code fails because it loads the unrelated runtime; changed code passes all six focused import-boundary cases (20.73 s including cold transform; 23.58 s wrapper).
  • Focused updater compatibility, update-run admission, and TUI pointer tests: 42 passed across three files (27.89 s Vitest; 51.42 s wrapper). The published updater proof now uses the backend entry point and still rejects any writable native open.
  • Changed-file oxfmt and scoped repository oxlint passed; git diff --check passed.
  • Review: independent subagent review (autoreview route unavailable). The configured helper refused the requested provider before inference; operator configuration was left unchanged. Clean through P2 after fixing its warm-preparation finding.

Matched synthetic fixture: 5,000 sessions, 6,000 retained runs, 200 approvals, 100 disabled cron jobs, 12 repositories with real worktrees, 1,500 MiB logical transcript text, a 4,641,595,392-byte agent database, and an 11,812,864-byte shared-state database. Node 26.8.2; isolated Linux sandbox on CPUs 64–127, 64 GiB memory cap, nice 10 / idle I/O. No production data or service changes.

Compared 2678c2b50c89c1a5f4bf88bf01ec9f36584a1e74 with 0b270969297d3b480108582b6ab7a4b1ed518cf7. Each fresh process uses the real canonical SQLite worker owner, executes plugins.deferredMigrations.read, verifies the empty result, and retains its lease through fresh per-script heap sampling after the normal worker idle-GC delay. The mixed control additionally executes userPreferences.read for a seeded synthetic profile with empty requested keys and verifies its result, forcing the remaining fallback runtime to load. Three processes per revision for registry-only; six for mixed, including three interleaved baseline/head pairs.

Median metric, MiB Before After
Registry-only SQLite worker heap 78.75 49.57
Registry-only process RSS 377.33 342.21
Mixed SQLite worker heap 78.88 78.86
Mixed process RSS 372.70 375.21

Registry-only retained heap falls 37.0% (29.17 MiB) and median process RSS falls 9.3%. Mixed worker heap is neutral; mixed RSS changes +0.7% with overlapping ranges (base 370.41–374.95 MiB, head 367.47–394.57 MiB). This supports the narrow benefit without claiming a steady-state saving after fallback use.

These are source-loader measurements of the shared-state operation on the production-shaped fixture, not a full Gateway traffic replay. Process RSS includes the compiler/helper isolate; main GC is not forced. The first cold baseline RSS was 492.95 MiB versus 372.29–377.33 MiB in later registry-only baselines; medians and the mixed control avoid presenting that cold-cache outlier as the saving. Native heap samples cover every observed worker; ArrayBuffer breakdown was unavailable. No bundled-runtime or deployed-Gateway RSS reduction is claimed. Largest transcript workers and fully mixed shared-state workers remain follow-ups.

Initial PR CI exposed a missing wrapper inventory entry for the newly static registry import. Added src/state/openclaw-state-worker-registry.ts to the canonical inventory and independently reviewed that correction. Rebased onto main to incorporate its separate existing runtime-process-manifest.ts inventory fix (#172056); git range-diff confirms both lane commits remained patch-identical. The measurements above remain evidence for the unchanged production patch.

Post-rebase focused closure/provisioning run: 36 passed, one skipped, one local timeout. Both closure files passed all 21 tests; provisioning passed 15 cases but its macOS-only materializes full cold/warm PR siblings, then preserves native sparse transitions case exceeded the existing 120-second timeout on the constrained Mac. No assertion failure was reported. This local APFS timing gap remains unresolved; no timeout increase or replay is being presented as a fix. CI owns broader proof.

The corrected-head Labeler workflow (run 38556412118) failed because GitHub returned HTTP 500 for GET /repos/openclaw/openclaw/issues/172071/labels?per_page=100, before any code-dependent action. No workflow or labeler code changed, and the infrastructure failure was not rerun.

The next CI run (38556415279) passed all test shards, typechecks, lint, and architecture guards, but the mock-export ratchet rejected an incidental error-message edit because it fingerprints the existing isolation factory. Restored the original diagnostic without changing the mock behavior, baseline, exceptions, or production code. Independent review was clean; all six import-boundary tests passed again (8.41 s Vitest, 10.57 s wrapper).

Local validation is limited to focused files and changed-file format/lint. PR CI owns broad validation, builds, typecheck, and closure guards. No Testbox/Crabbox lease was allocated.

Final head dd2a4dd60665de4d04007d412232d468e9bb42f1: CI run 38557918712 passed all tests, types, lint, architecture checks, baseline ratchets, and the CI gate. Security and dependency reviews passed. No workflow reruns or inherited-failure exception were used. The synthetic benchmark sandbox was removed and its absence verified. The local macOS APFS timeout noted above remains a separate validation gap.

@clawsweeper

clawsweeper Bot commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review October 14, 2026 11:09
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: S labels Oct 14, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-14T11:28:09.005253Z 8ac0599 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@steipete
steipete force-pushed the steipete/perf-micro-sqlite-worker-heaps-20260919 branch from 0b27096 to 8ac0599 Compare October 14, 2026 11:25
@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Oct 14, 2026
@steipete
steipete merged commit a184f0a into main Oct 14, 2026
143 of 144 checks passed
@steipete
steipete deleted the steipete/perf-micro-sqlite-worker-heaps-20260919 branch October 14, 2026 11:57
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 15, 2026
…enclaw#172071)

* perf(state): load SQLite command domains without fallback runtime

* fix(pr): include state worker registry in wrapper inventory

* test(state): preserve existing import isolation mock
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 scripts Repository scripts size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant