Skip to content

perf(sqlite): reuse admission snapshots across worker requests - #168647

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-sqlite-admission-fact-per-call-20260919
Oct 10, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-sqlite-admission-fact-per-call-20260919

Conversation

@steipete

@steipete steipete commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Worker RPC dispatch scanned every retained SQLite admission, copied each fact map, checked shared validity cells, and built string fingerprints before discovering that nothing had changed. Unchanged reply installation also rebuilt the environment snapshot. This makes ordinary Gateway requests more expensive as more physical databases and writer registrations are admitted.

User Impact

Admission transfer now has constant work between publications, reducing main-thread CPU in long-lived Gateways. First-use validation, shared revocation, writer custody, host-only completeness, and generation-aware retirement remain enforced. No schema, stored-data, permission, configuration, or upgrade/downgrade changes.

Why This Change Was Made

The admission registry prepares snapshots at publication and transfers only changed records. Requests compare one registry revision; weak cursors do not retain old snapshots. Installation of unchanged facts is a no-op. Shared cells invalidate transferred facts immediately. Publication and explicit full captures reclaim remotely retired records, without deleting a newly admitted generation of the same file.

The old capture/fingerprint implementation is removed. Transfer and installation now share one owner in the existing admission-record module; native identity/lifetime handling stays in the admission module, which shrinks by 39 lines. Total production delta is +40 lines (139 added, 99 deleted), excluding tests/support/docs: immutable publications, weak cursor retention, and generation-safe cleanup replace per-call reconstruction. The existing line-growth gate required moving the cohesive registry logic out of the already oversized native module.

Evidence

Same-host before/after on a Linux rig, Node 26, synthetic databases, real task-pool and SQLite broker RPCs. Each cell measures 2,000 calls after 100 warmups; process.threadCpuUsage() measures the host thread.

Admissions Task CPU ms / 1,000 RPCs, before → after Broker CPU ms / 1,000 RPCs, before → after
17 49.91 → 39.52 209.28 → 173.28
129 121.72 → 31.57 308.23 → 155.65
513 399.00 → 30.78 776.48 → 152.00

At 513 records, task CPU improves 13.0× and broker CPU 5.1×. Another 20,000 task RPCs retain exactly 513 admissions in both versions; median CPU per 1,000 calls falls from 400.86 ms to 29.66 ms. Records follow admitted physical databases, not call count. This is worker-boundary and call-count soak evidence, not an end-to-end Gateway load test or a multi-hour production deployment.

The snapshot-reuse regression fails on the original code and passes after the change. It covers stable publications, unchanged installation, changed-record transfer, shared revocation, and retirement. The existing worker regression now also retires and re-admits the same physical file and checks sibling admission IDs agree.

Validation:

  • Linux rig: focused admission/native-schema tests 65 passed; sibling schema, admission, broker-reply, and transfer suites 158 passed; wrapper/eager-import closure tests 20 passed; export-name collision guard passed.
  • Linux rig: staged changed-file gate passed all checks through core and core-test types, including line-cap, schema-worker, formatting, plugin-boundary, and wrapper guards. Core-test type checking took 1,947 s. The dead-export scan then failed on inherited findings; the one new redundant export was removed. Comparing the unchanged base 3050cdc493af8832fe2092045402d35e5fb1fda5 and final candidate confirms 17 identical inherited findings, zero new findings (auth modules, UI test support, and Solid lint tooling).
  • Broad staged lint reports 19 inherited max-line violations. For the touched native admission file, running the same max-lines rule on the original and candidate confirms 757 → 721 counted lines against the existing 700 limit; the shrink-only gate passes. The other reported core lint paths are unchanged. Extension and script lint pass with zero warnings/errors.
  • Test cost: pnpm test src/infra/sqlite-schema-facts.native.test.ts --maxWorkers=1 — 54 passed, 42.92 s Vitest / 47.08 s command wall time on the rig. No new test file, shard, or worker boot was added. The existing file owns the added case.
  • Rebased onto 451903329fee2aa605ee05fa4dc07c1e6f7decc0; all six changed files are byte-identical to the reviewed/tested candidate. Exact-head CI follows on 2238957b8d553630c2b1a3bc7536cb42f4461bf5.
  • Independent isolated Codex review of the final staged diff: clean at P0–P2. Review caught and resolved remote-retirement retention and replacement-generation pruning before publication.

Earlier remote runs: Blacksmith Testbox tbx_01m4kmm5bxwak90a7d7nef1g6n ran the focused tests and original-code regression plus before/after benchmark successfully (62 passed, 3 skipped; 26.60 s Vitest / 28.41 s wrapper), following an initial regression failure corrected in the same scope. Its later gate never started because checkout sync timed out. AWS cbx_3462d14149c9 and Hetzner cbx_3396f1b4d4f6 fallback commands also remained in checkout transfer and were stopped before test execution. All leases were stopped; the final proof used the approved rig fallback.

CI on the exact PR head completed with three inherited failures: check-additional-boundaries, check-lint-core-2, and check-test-types-core-1. Each reports the duplicate helper import at lines 8 and 10 in ui/src/e2e/mobile-sidebar-session-menu.e2e.test.ts. That file has the identical blob in the CI main parent ad2d6022a02d4d087c71cf5dd818f5802ff351b4 and tested merge 1500bdc37d3c40e02e4dbcfbb35018c0ae46c4f4; the error reproduces with the one-file boundary lint on that unchanged parent. All other selected CI jobs passed or were intentionally skipped. The native pre-existing-failure verifier accepted the pinned run, parentage, source identity, scoped tests, and current writer authority. No CI rerun was requested.

Prepare immutable admission publications at the registry owner instead of rebuilding every fact map and cursor fingerprint per RPC. Preserve shared revocation and generation-aware retirement across workers. No schema or persistent-state changes.
@clawsweeper

clawsweeper Bot commented Oct 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 docs Improvements or additions to documentation size: M labels Oct 10, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 10, 2026
@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR prepares SQLite admission snapshots at publication and reuses them across unchanged worker requests.

Example: Reported Linux benchmark with 513 admissions and real task-pool RPCs.

  • Before: Host-thread CPU was 399.00 ms per 1,000 RPCs.
  • After: Host-thread CPU was 30.78 ms per 1,000 RPCs.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A coherent optimization with reported production-boundary measurements and meaningful lifecycle coverage; shipped Gateway execution was not demonstrated.
Proof confidence 🦐 gold shrimp (3/6) The supplied MEMBER classification exempts ordinary contributor proof; the body reports real task-pool and broker RPC measurements through the changed owner, with no whole-Gateway performance claim.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Ordinary Gateway requests consume increasing host-thread CPU as retained database admissions grow.
Reason: The established feature owner proposes a focused optimization with measured boundary savings and unchanged persisted-state contracts.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it addresses admission-transfer overhead still present on main, and no actionable introduced defect was found.

Priority: P2
Reviewed head: 2238957b8d553630c2b1a3bc7536cb42f4461bf5

Before merge

None.

Findings

None.

Agent review details

How this fits together

The process-wide SQLite admission owner receives validated facts and writer registrations and transfers snapshots to workers whose consumers check shared validity cells.

flowchart TD
A[Database admission] --> B[Admission registry]
B --> C[Published snapshots]
C --> D[Task and broker RPCs]
D --> E[Worker installation]
E --> F[Fact consumers]
G[Shared validity cells] --> F
Loading

Technical review

Best possible solution:

Land publication-owned snapshot reuse through the existing admission owner once required CI is resolved or independently qualified for the native inherited-failure exception.

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

Current-main source shows admission-wide reconstruction during unchanged RPC dispatch, supported by the reported comparable boundary measurements; this review executed no target code.

Is this the best way to solve the issue?

Moving reconstruction to publication removes the repeated cost at its existing owner while preserving shared invalidation and generation checks.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Physical admission, revocation, and writer custody keeps the original intent (bb7d32e: Share validated physical-database facts across handles and workers while preserving replacement, corruption, and custody checks.)
  • Capture fingerprints and host completeness changes intended behavior with a stated reason (7517981: Transfer changed records while preserving generation identity and host-certified completeness.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Pinned introduced change: Publication snapshots, revision cursors, and change-aware installation replace per-capture reconstruction in the existing admission owner. (src/infra/sqlite-database-admission-record.ts:310, 2238957b8d55)
  • Current-main overhead remains: Main scans retained admissions, filters and copies fact maps, and constructs fingerprints before recognizing unchanged records. (src/infra/sqlite-database-admission-record.ts:173, de691c1ec3c0)
  • Lifecycle and invalidation preservation: Consumers retain shared retirement, current-cell, and revision checks; cleanup removes only the matching retired generation, and worker installation cannot advance host completeness independently. (src/infra/sqlite-database-admission-record.ts:155, 2238957b8d55)
  • Worker regression coverage: The existing real-worker scenario now retires and re-admits the same physical file, checks sibling admission agreement, and verifies subsequent retirement removes its publication. (src/infra/sqlite-database-admission.worker.test.ts:405, 2238957b8d55)
  • Reported performance evidence: The full body reports comparable Linux task-pool and SQLite broker RPC measurements, a 20,000-call retention check, and a base-failing regression; its claims explicitly stop at the worker boundary. (2238957b8d55)
  • CI attribution remains incomplete: Exact-head annotations identify max-lines warnings and a duplicate declaration in an untouched UI test. Full job logs redirect to a host blocked by the network allowlist, so the test-types failure and complete baseline attribution remain unverified; no CI failure is assigned to this diff. (2238957b8d55)

PR surface

Source +40, Tests +85, Docs +6. Total +131 across 6 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 139 99 +40
Tests 3 85 0 +85
Docs 1 6 0 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 230 99 +131

Review metrics

Metric Value Why it matters
Production versus test growth Production +40 lines; tests and support +85 lines. Production growth replaces per-request reconstruction with publication snapshots; the tests cover reuse, revocation, and generation-safe retirement.

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: A focused performance improvement for long-lived Gateways, without evidence of an urgent outage or data-loss failure.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-10T21:11:00.613Z sha 2238957 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-10T21:21:46.588Z sha 2238957 :: needs changes before merge. :: none

Reviewed October 10, 2026, 5:36 PM ET / 21:36 UTC (Revision 3).

@steipete
steipete marked this pull request as ready for review October 10, 2026 21:15
@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 10, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

The three failing CI jobs are inherited from the CI merge’s main parent:

  • check-additional-boundaries
  • check-lint-core-2
  • check-test-types-core-1

All three report the duplicate createControlUiMockSameOriginGatewayScript import at lines 8 and 10 of ui/src/e2e/mobile-sidebar-session-menu.e2e.test.ts. The file’s blob is identical (d0c49c527dd0170833be8fb3206bc424a82b1d19) in main parent ad2d6022a02d4d087c71cf5dd818f5802ff351b4 and tested merge 1500bdc37d3c40e02e4dbcfbb35018c0ae46c4f4. The same one-file boundary lint reproduces the error on that unchanged main parent in the Linux rig.

The exact PR head is 2238957b8d553630c2b1a3bc7536cb42f4461bf5. All changed Node test jobs, architecture guards, docs, and security checks passed. Independent review is clean; the rig passed 65 focused tests, 158 sibling tests, and 20 closure tests. This qualifies for the authorized pre-existing-failure landing exception; no CI rerun or update-branch was used to chase green.

@steipete
steipete merged commit b4c73df into main Oct 10, 2026
224 of 231 checks passed
@steipete
steipete deleted the steipete/perf-micro-sqlite-admission-fact-per-call-20260919 branch October 10, 2026 21:44
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 11, 2026
…law#168647)

Prepare immutable admission publications at the registry owner instead of rebuilding every fact map and cursor fingerprint per RPC. Preserve shared revocation and generation-aware retirement across workers. No schema or persistent-state changes.
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. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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