Repository navigation
perf(sqlite): reuse admitted schema catalog facts - #166102
Conversation
Carry index names and trigger definitions in the existing admitted catalog snapshot. Reuse those facts for canonical session validation and first-use schema installation, removing separate committed-schema caches while preserving foreign changes, rollback, reopen, and dynamic authorizer checks.
Keep schema facts collected under synchronous read admission after data-only transaction settlement. Unmanaged snapshots and sibling schema publications observed in a transaction still expire, and the next operation still checks foreign commits. Cover warm worker commands after lazy schema installation.
|
🦞👀 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: blocked before merge. Reviewed October 6, 2026, 12:46 PM ET / 16:46 UTC (Revision 4). ClawSweeper reviewWhat this changesReuse connection-owned SQLite catalog facts for schema validation and lazy installation, and release retained metadata when database handles close or are replaced. Warning SQLite table change This PR modifies persisted SQLite tables in Merge readiness⛔ Blocked before merge - 1 item remains The PR remains useful and has no actionable correctness or security findings. The previous migration-proof blocker is inapplicable because persisted schemas and formats are unchanged. Likely related people: steipete, with high-confidence routing from merged SQLite ownership work. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw’s SQLite admission layer validates database handles before session and worker operations consume them. Its connection-owned facts let those operations avoid repeated catalog scans while preserving freshness and cleanup. flowchart TD
A[Agent and worker operations] --> B[Database admission]
B --> C[Connection catalog facts]
C --> D[Canonical validation]
C --> E[Required objects present]
E -->|Yes| F[Execute operation]
E -->|No| G[Existing installation transaction]
G --> F
H[Schema changes or handle disposal] --> C
Before merge
Agent review detailsSecurityNone. PR surfaceSource +53, Tests +168, Docs +14. Total +235 across 18 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Keep schema reuse and invalidation with the existing connection owner, preserving native checks and unchanged persisted contracts. Do we have a high-confidence way to reproduce the issue? Not applicable as a user bug report; source inspection confirms redundant catalog work, and the recorded isolated workload measures its reduction. Is this the best way to solve the issue? Yes. Reusing the admitted catalog and removing caller-maintained flags keeps freshness and cleanup under one existing owner without changing storage formats. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 817706084620. 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
History |
|
ClawSweeper's exact-head review completed for Landing is still investigating CI's Doctor scale-test worker OOM; it has not been classified as inherited or waived. |
Merge main to integrate the session reader and admission optimizations. Retire cached metadata with its native connection so closed handles cannot retain expanded catalog facts throughout large archive batches. The existing Doctor scale regression passes five Linux Bun replays after failing all five on the original PR head.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
* perf(sqlite): reuse admitted catalog facts across schema owners Carry index names and trigger definitions in the existing admitted catalog snapshot. Reuse those facts for canonical session validation and first-use schema installation, removing separate committed-schema caches while preserving foreign changes, rollback, reopen, and dynamic authorizer checks. * perf(sqlite): retain admitted facts across managed transactions Keep schema facts collected under synchronous read admission after data-only transaction settlement. Unmanaged snapshots and sibling schema publications observed in a transaction still expire, and the next operation still checks foreign commits. Cover warm worker commands after lazy schema installation. * fix(sqlite): attach schema query rationale to guarded call * fix(sqlite): break the agent schema admission loop Reuse settled native preparation and unchanged admitted schema facts. Keep explicit host readmission, startup journal checks, and schema receipt revocation for observed foreign DDL. Skip covered standing-intent DDL instead of repeating post-commit structural scans. Addresses repeated schema preparation attributed to #165680; builds on the schema-fact owner in #166102. Schemas, stored bytes, and update behavior are unchanged. * fix(sqlite): avoid shadowing preparation options * test(sdk): preserve released agent preparation call forms * test(sessions): preserve canonical leases after reconcile shutdown
* perf(sqlite): reuse admitted catalog facts across schema owners Carry index names and trigger definitions in the existing admitted catalog snapshot. Reuse those facts for canonical session validation and first-use schema installation, removing separate committed-schema caches while preserving foreign changes, rollback, reopen, and dynamic authorizer checks. * perf(sqlite): retain admitted facts across managed transactions Keep schema facts collected under synchronous read admission after data-only transaction settlement. Unmanaged snapshots and sibling schema publications observed in a transaction still expire, and the next operation still checks foreign commits. Cover warm worker commands after lazy schema installation. * fix(sqlite): attach schema query rationale to guarded call
…#166253) * perf(sqlite): reuse admitted catalog facts across schema owners Carry index names and trigger definitions in the existing admitted catalog snapshot. Reuse those facts for canonical session validation and first-use schema installation, removing separate committed-schema caches while preserving foreign changes, rollback, reopen, and dynamic authorizer checks. * perf(sqlite): retain admitted facts across managed transactions Keep schema facts collected under synchronous read admission after data-only transaction settlement. Unmanaged snapshots and sibling schema publications observed in a transaction still expire, and the next operation still checks foreign commits. Cover warm worker commands after lazy schema installation. * fix(sqlite): attach schema query rationale to guarded call * fix(sqlite): break the agent schema admission loop Reuse settled native preparation and unchanged admitted schema facts. Keep explicit host readmission, startup journal checks, and schema receipt revocation for observed foreign DDL. Skip covered standing-intent DDL instead of repeating post-commit structural scans. Addresses repeated schema preparation attributed to openclaw#165680; builds on the schema-fact owner in openclaw#166102. Schemas, stored bytes, and update behavior are unchanged. * fix(sqlite): avoid shadowing preparation options * test(sdk): preserve released agent preparation call forms * test(sessions): preserve canonical leases after reconcile shutdown
What Problem This Solves
Agent operations repeatedly scan canonical trigger definitions and execute first-use schema DDL even when the connection already has admitted schema facts. Separate caller-maintained committed flags duplicate the schema owner's lifecycle and can miss rollback, foreign DDL, and handle replacement.
Solution
Collect index names and trigger definitions in the existing admitted catalog snapshot, consume that snapshot for canonical validation, and use it to decide whether the complete outbox, participant, archive, and node-turn object groups exist. Remove the superseded committed-flag bookkeeping. Retire admitted metadata on native database disposal so closed readers release their catalog references immediately. Facts gathered in managed operations survive ordinary data-only transaction settlement; DDL, rollback, snapshot retirement, and explicit schema publication still invalidate them.
Build on the landed cold-admission owner (#165680). Carry the new facts through its worker receipt transfer and advance local derived-fact revisions when a retained handle adopts a changed schema. The integration regression reproduced stale owner-column availability before that repair.
Impact
Fewer SQLite statements without a new cache, worker service, schema, index, retention policy, durability change, or released SDK contract. Foreign commits remain visible on the next unpinned use; active snapshots, transaction admission, current authority, FIFO, and accepted-write settlement retain their existing owners. Raw maintenance and dynamic-authorizer handles retain native checks. No configuration or update migration is required.
Production: +155 / −102 / net +53 lines, 12 production files; 18 files total. No new
OPENCLAW_*names. This is one bounded contribution to the SQL-efficiency campaign; remaining statements still exceed its overall target.Evidence
Same restored counting harness and fixed synthetic workload, three fresh runs per revision on the same isolated Linux host (8 vCPU, Node 24.21.0); ten warmed turns per run. Source:
7b9405e22d7b0bbbdde1537c2a566521bed425aa→1a2d1b11cbd61532e17444d69ba1bf9dd40b10b9. Both sides include cold admission. The remote candidate SHA and all 17 changed-file hashes were verified, and the harness hashes match. These are execution counts, not uninstrumented latency measurements.Warmed ranges: 3,179.3–3,182.9 → 3,096.8–3,115.4. Compaction is effectively unchanged. All six runs completed 13 top-level turns, the native child, control-plane RPCs, cron, committed compaction, and graceful shutdown. No SQL failures or fixture children remained. Main/worker calibration on both revisions: eight native calls, two prepares, seven executed statements, zero failures. CPU idle before each run was 99.2–100%.
Targeted and retained probes per warmed turn
The broader catalog row includes the two catalog classes above. Residual canonical scans initialize the process-local comparison schema. Target-owner CREATE statements on the first turn fall 38 → 37; their warmed count is zero on both revisions. The remaining warmed CREATE work mostly belongs to standing-intent initialization. The outbox regression independently proves no redundant DDL/catalog reads on newly admitted existing schemas or after first-use installation.
pnpm test <files> --maxWorkers=1, 726.28 s wall on the loaded Mac. Three sibling files added 45 passing tests in 128.43 s remotely. Total: 170 focused tests across nine files.--maxWorkers=1.node scripts/check-changed.mjs: 2,063.87 s, passed formatting, policy guards, core typechecking and all 27 test graphs, then stopped at the inherited dead-export findings detailed below. All nine subsequent selected checks were run separately and passed; typed lint reports zero warnings/errors.pnpm deadcode:knip: passed, 54.26 s. Madge: zero cycles, 34.03 s. Runtime import cycles: zero, 19.49 s. Database-worker ratchet: passed, 5.25 s; static T1 846 → 846. No newOPENCLAW_*names.indexesandtriggersto the unreleased cold-admission receipt'sSqliteSchemaFacts. It changes 131 reachable declaration fingerprints, with zero direct SDK export signature or entrypoint changes. Reviewed digest53ad4c98; acknowledged run: 274.85 s. The integrity-verified published2026.9.8tarball has 504 declaration files; none containsSqliteSchemaFactsor an import of that module, so the released SDK contract is unchanged.2026.9.8→ exact candidate1a2d1b11cbd61532e17444d69ba1bf9dd40b10b9; phasefinished, readiness HTTP 200, running version verified, durable history preserved, incognito cleared, service replacement verified.The slower existing outbox and worker-admission suites exercise native worker transport, schema repair/reopening, integrity refusal, and write settlement. Their assertions were extended without adding new per-test Gateway boots or timers. New column-adoption coverage is a native foreign-commit/adoption regression. CI seconds are not available before PR creation.
The adoption and transfer regressions failed for their intended reasons before the fixes. Earlier red controls also demonstrated redundant canonical catalog reads, redundant admitted outbox DDL, and catalog rescans after lazy installation. Existing boundary assertions retain zero host catalog/integrity scans during worker admission. New/changed coverage includes foreign commits, pinned snapshots, local DDL, rollback, eviction/reopening, schema repair, receipt transfer, and dynamic authorizers.
No new/extracted wrapper module or runtime owner cutover was introduced. Import/build-closure tests are included explicitly. Column probes remain native because unqualified SQLite table lookup can select TEMP objects and excludes generated columns; parsing main-schema SQL would not preserve that contract. TEMP generation reads remain data-mutation witnesses.
Known inherited check failure:
node scripts/check-changed.mjs --base 7b9405e22d7b0bbbdde1537c2a566521bed425aa --head 1a2d1b11cbd61532e17444d69ba1bf9dd40b10b9passed core typechecking and all 27 test graphs, then failed the dead-export scan on two untouched exports:OUTBOUND_GREETING_FALLBACK_MSinextensions/voice-call/src/webhook/realtime-call-session-control.tsandloadManifestModelCataloginsrc/agents/model-catalog.runtime.ts. The exact same production/full-tree findings reproduce on the pinned base after its QA build (94.49 s). The failure is retained in the evidence; the checks selected after that failure are run separately without disabling the export guard.The first fresh VM lacked ripgrep, then exhausted its
/tmpuser quota. Completed proof was preserved; unfinished checks moved to a fresh disk-backed checkout of the same SHA.Overlap: cold admission is integrated; related wave work includes #165552, #165885, #165895, #165890, #165901, #165859, #165894, #165904, and #165921. The umbrella design draft #162433 is not adopted. This PR keeps its changes within schema-fact ownership; the other SQL-efficiency lanes retain their own query, transaction, and session-cache changes.
Landing integration and CI repair
Integrated the landed session-reader and admission-envelope siblings through a merge commit,
6db8c8314268e0c34a3b90b9b44b95467597cdda, based on main05179a73d12b46bfc3208d26b939d0bd467d6ca7. No rebase or schema-contract change was needed.The original CI attempt exposed a PR-caused worker OOM in
src/commands/doctor-session-canonical-keys.scale.test.ts; its aggregate gate failed and fail-fast canceled 54 sibling jobs. This was not treated as inherited or flaky. With the file run singly under pinned Linux Bun and--maxWorkers=1, the original PR failed 5/5, its merge base passed 5/5, and the exact CI main parent passed 5/5.The admitted-metadata WeakMap retained each closed reader's expanded catalog while reader WeakRefs kept those keys alive through the archive worker's microtask drain. Synchronous diagnostics captured 8,192 empty materializations, balanced reader closes, and sampled peak worker heap of 579,598,972 bytes before the OOM. The repair deletes the cache entry through the existing native close/replacement callback. The same instrumented flow passed with sampled peak heap 159,021,730 bytes. Five uninstrumented replays of the original head plus only this repair all passed (wrapper wall times 52, 36, 30, 43, 43 s), preserving the test's 12,000 removals and 200,000 transcript events. No test assertion, memory limit, runtime scheduling, or admission check was changed. The callback performs no SQL.
Final integrated local proof: 154 tests across 10 files passed in 715.41 s after main integration; 63 targeted metadata/archive/import tests across five files passed in 285.59 s after the repair. Both invocations used
--maxWorkers=1. Core typechecking passed after integration and again on the final repair (15.39 s); all 27 core-test typecheck graphs passed (828.43 s); Madge found zero cycles (126.29 s). Fresh Codex P2 autoreview of the final staged tree is scoped-clean. The integrated SDK comparison passed in 985.21 s, with reviewed digest 45aa2a77: the same two unreleased catalog fields affect 131 reachable fingerprints, with zero direct export signature or entrypoint changes. Earlier package/update evidence remains explicitly tied to its recorded head.The original body-format check was also repaired by using the required problem heading; its replacement check passed. The earlier ClawSweeper exact-head review had no actionable code/security finding; its generic stored-model checklist was satisfied by the existing unchanged-DDL and published-driver evidence. A fresh review is requested for the replacement head.
The shared-harness statement comparison above remains 3,180.0 → 3,114.1 warmed all-thread statements on its recorded revisions. The disposal repair adds zero SQL; it changes cache cleanup only. This lane is a bounded reduction toward the campaign target, not a claim that the overall workload is below 500 statements.
CI follow-up
b12b0a23cc8bc5578c6712c6c1682b07d4d32a50fixes the Kysely guard's recognition of the existing raw-schema rationale: formatting had placed its comment inside a ternary, detached from the call. The rationale now sits on the guarded call.pnpm lint:kyselypassed (544.19 s) and fresh P2 autoreview is scoped-clean. The correction emits byte-identical JavaScript, so the runtime and integrated SDK proof remains applicable. The preceding CI attempt had only that guard root failure plus its aggregate failure; 53 jobs were canceled. Final-head CI attempt 37493768427 passed: 76 successful jobs, 24 skipped, no failures or cancellations, including the enforced CI gate and corrected architecture guard. ClawSweeper completed the final head at 2026-10-06 16:17 UTC with no actionable correctness/security findings; its detailed verdict explicitly confirms that the generic migration-proof warning is inapplicable to these unchanged persisted schemas and formats. Neither PR-caused failure uses an inherited-failure exception.