Skip to content

perf(sqlite): avoid schema writes on warm store use - #170658

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-ddl-on-use-audit-20260919
Oct 13, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-ddl-on-use-audit-20260919

Conversation

@steipete

@steipete steipete commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Related: #170470, #170548, #170598

What Problem This Solves

Repeated schema preparation can revoke an active tool caller's retained profile authority even when SQLite's CREATE IF NOT EXISTS changes nothing. This completes the audit of persistent DDL on use across core, packages, and bundled plugins after the cron and shared-state additive fixes.

User Impact

Existing stores can prepare their tables without revoking retained caller authority. Missing objects still install transactionally, existing historical column/constraint repairs remain, and imported memory rows retain their provenance backfill. There are no schema SQL, stored-shape, version, retention, permission, upgrade, or downgrade changes.

Why This Change Was Made

Use the existing schema-fact owner and createSqliteSchemaEnsurer for the remaining additive stores, including the first use of a warm native handle. Standalone update/Windows lease owners create only a missing table within their existing ownership boundaries. Retained wrapper readiness now follows the schema owner’s facts instead of an irrevocable per-handle flag, preserving admission/post-commit timing while invalidating on schema change or rollback. The Board constraint repair still validates the canonical/recognized historical definition; retired memory triggers still drop when present.

Audit inventory and previous DDL frequency
Owner Previous frequency Outcome
src/node-host/node-worker-launch-store.kernel.ts Base schema once per handle; boot table on each new boot-bound claim; container/cleanup/process-scope tables on each applicable start Five schema ensurers; base handle cache removed; existing index included
src/skills/library/store.ts First publish/upload on each native handle, including initialized files Four-table schema ensurer; admission callbacks preserved
src/gateway/worker-environments/store-schema.ts Environment-store preparation once per handle Both companions and attachment index covered
src/gateway/worker-environments/placement-move-intent.ts First move read/write per handle Table ensure uses schema facts; missing-column migrations retained
src/state/openclaw-agent-goal-operations-schema.ts First typed goal operation per handle Table/index ensurer replaces handle cache
src/state/openclaw-agent-board-schema.ts Board store's first use per handle, and migration preflight Additive table/index DDL skipped on warm schema; definition consumes admitted facts
src/state/openclaw-state-db-existing-write.ts First subset admission on each one-shot update-ledger handle Validated catalog admitted before conditional additive installation
src/infra/update-managed-service-handoff-database.ts Every writable unbound private lease access (acquire/update/release) Missing-table-only creation; identity-bound path unchanged
src/gateway/worker-environments/workspace-quiescence-scripts.ts Every Windows shared-host acquire/renew/release Missing-table check inside existing writer transaction
src/audit/execution-owner-lifecycle-binding-store.ts Every helper invocation; current bundled caller already checked table existence Exported helper now enforces the same missing-object boundary
packages/memory-host-sdk/src/host/memory-schema-provenance.ts Every full shadow reindex publication, plus initialization No redundant table creation or retired-trigger drop; backfill remains
packages/memory-host-sdk/src/memory-entry-origins.ts Every direct helper invocation; bundled worker already guarded Helper now uses the schema owner

Already fixed: cron run receipts/runtime authority (#170548), shared-state feature/additive table ensures (#170598). Existing standing-intent and progress-card owners already gate their DDL with admitted objects/columns. Workshop changes, node-worker turns, outbound progress/bindings, standing grants, approval identity companions, project/template registries, execution identity/decision facts, and feature-local schema wrappers already guard installation.

Plugin/package audit: Workboard, logbook, and team reports initialize under schema admission at backend open; memory schema initializes under its published/shadow owner. Memory origin/tombstone callers already check missing tables. Full memory FTS/vector publication deliberately replaces derived structures and must retain its DDL. PostgreSQL bootstrap is outside the SQLite audit.

Excluded by lifecycle: versioned migrations and Doctor/STRICT/index repairs; snapshot restore; package activation/adoption initialization; one-shot legacy proxy-capture and restart-sentinel connection admission; disposable transcript import/archive/history-matching/staging/contract databases; TEMP tracking objects, and explicit planner-statistics refresh after maintenance. These perform initialization, actual schema repair, or deliberate derived-data replacement rather than redundant warm preparation.

Evidence

Native SQL guards cover first and repeated warm audit/goal/Board/memory preparation, real node-worker claim/start persistence, reopened private update lease mutation, and emitted Windows lease renewal/release against real synthetic SQLite. A non-cron regression retains the operator tool source, releases the initiating request, and dispatches first warm skill-library preparation with live transaction/commit authority checks.

Synthetic Linux sandbox measurement on Node 26.8.2, baseline 88e5ae840faa, seven measured rounds after 100 warm-up calls; medians per 1,000 initialized-store preparations (each with an explicit writer transaction):

Preparation Before After Warm DDL calls before → after
Audit binding helper 393.956 ms 4.630 ms 1,000 → 0
Board schema helper 660.308 ms 14.641 ms 1,000 → 0
Memory origin helper 211.411 ms 4.376 ms 1,000 → 0
Memory provenance preparation 612.604 ms 278.278 ms 2,000 → 0

These measure preparation overhead on empty synthetic stores, not end-to-end Gateway latency. Audit/origin bundled callers already guard their helpers; the direct-helper numbers quantify the tightened boundary rather than claim a current production-call speedup. Memory provenance retains its DML backfill and improves 2.20×. The sandbox was deleted after measurement.

Local focused proof: the five-file run passed 84 tests with one existing Bun-qualified skip (package provenance: 3.72 s file wall time; gateway/authority + emitted lease script: 72.95 s combined shard wall time; node launch + update handoff: 169.02 s combined shard wall time). The ten-test state schema guard file passed; the existing subset-writer file's 22 siblings passed, and its new physical-writer DDL guard passed separately after admitting the validated catalog. The schema-contract validator legitimately creates a private scratch database; that DDL is excluded by exact observed database identity, rather than masking physical-store changes. The warm audit-binding guard fails on the unchanged baseline because it observes both repeated CREATE statements. The request-closed skill-library regression also fails on unchanged code because the physical store issues its redundant CREATE block. Its authority-only assertion still passes on this narrower current-main harness; the added native SQL assertion protects the schema/authority boundary before more owners move under retained admission. Final cache-lifecycle checks passed: the request-closed warm library guard, worker-environment companion rollback/retry, and placement legacy-column repair/reopen (3 tests, 140.05 s shard wall time including compiler/import overhead). Broad typecheck, full cron/sqlite-store suites, builds, and e2e belong to PR CI under the requested validation policy; no Testbox/Crabbox lease was allocated.

Changed-file oxfmt, repo lint, and git diff --check passed. Lint initially found the node-kernel line budget and a fixture variable shadow; both were corrected. No new source/test module or public SDK subpath was added; the existing private bridge has two additional re-exports. Export/closure guards and full cron/sqlite-store coverage remain PR CI gates. Final-head PR CI passed: 59 successful jobs, 25 skipped, 717 s run wall time and 10,808 successful-job CI seconds.

Review: fresh-context independent subagent review of the complete 21-file diff and audit inventory returned a clean verdict with no actionable correctness findings. Review covered canonical table/index contracts, schema-fact invalidation and rollback, post-commit readiness, legacy repairs, and the production-path SQL guards. This uses the lead-authorized replacement route; the existing review configuration was preserved.

Production LOC: +180 / -83, net +97 (excluding tests, test support, and docs). Growth names each store’s complete table/index contract, retains historical trigger/column/constraint cleanup, and ties wrapper readiness to the schema owner’s facts while preserving transaction/commit callback timing. The superseded unconditional DDL and goal/base-launch handle caches are removed. No competing schema installer or new configuration surface is added.

Additional exact-head Actions proof: main-tier CI at 5856e0b3eabe1e6859035f2b7281dc90c74f25af includes the complete cron and SQLite-store inventories beyond ordinary bounded PR selection. Dispatched once for the explicitly requested suite coverage, with no Testbox lease. Completed: 136 jobs passed, 10 failed, 13 skipped; Node rows: 69 passed, six failed, one skipped. The full cron and SQLite-store inventories ran; no failed test case is in those suites. This is prior-head supplemental coverage, not a claim that the whole run was green.

CI corrective change: the dialect ratchet rejected the additional cold-handle trigger catalog query. Reused the existing table-contract reader, keeping engine-specific SQL at its owner. The admitted hot path and measurements are unchanged. Focused provenance tests pass (5/5, 2.87 s runner wall), changed-file formatting passes, and the changed-file dialect ratchet passes (engine-maintenance 2 → 2). The independent reviewer also returned a clean verdict on this corrective delta.

Inherited supplemental failures: config-preflight TS2724 reproduces on unchanged main baseline, and is separately repaired by #170619; the stale test import is outside this diff. Deadcode reports the unchanged UI export renderBoardWidgetError, matching scheduled main. Logs fetched once; neither failure will be rerun to seek green.

Final corrective head: da3c521d6c0e927cc79750539cc68664b31d881a. The one-file cold-handle fallback correction passed repo changed-file lint and independent review before commit. Final-head PR CI reruns the changed owners and required gates; supplemental full-suite results from the first head are retained as explicitly scoped prior-head evidence for unchanged cron and store paths.

Final-head required proof: PR CI is successful at da3c521d6c0e927cc79750539cc68664b31d881a; both required aggregate contexts report success. All selected owner tests, compiler, lint, schema/dialect, export and closure gates passed. No CI rerun was requested.

Supplemental attribution: both session metadata assertions reproduced after temporarily removing all 13 lane production changes (baseline 88e5ae840faa, unchanged test, 2 failures, 62.09 s runner wall). The provider auth literal parity failure also reproduced with all lane production changes removed (1 selected failure, 208.33 s runner wall). That focused wrapper automatically invoked an 85.8 s local runtime build, exceeding the requested light-check scope; no further runtime build was invoked. The unchanged baseline remote-catalog file then passed both cases using that already-built baseline runtime (177.64 s runner wall). Its supplemental v1 timeout and following v2 row mismatch are recorded as an unclassified prior-head coverage gap, not a demonstrated lane regression or claimed inherited reproduction. The separate freshness assertion matches scheduled-main evidence above. Candidate source was restored after each baseline run.

Freshness baseline: the same models.list reuses inventory until explicit refresh sibling assertion (expected 0 projection calls, observed 6) fails in scheduled main. No model/catalog source, provider manifest, or test file from these supplemental failures is modified by this lane.

Additional authority comparison: with all lane production files removed, the two selected auth-refresh cases reproduce the timeout/root-work-count failures; the grant-revocation case passes (110.98 s runner wall). On the final candidate, the same three selected cases pass (161.63 s runner wall), including denial of the final write after grant revocation. This verifies the candidate boundary without claiming that a passing replay fixes the broader fixture failures. Both runs reused the existing baseline runtime; no additional runtime build was invoked.

Supplemental mixed-row gaps: the stale config test also fails at runtime with the same private-helper error; the first-head dialect failure is fixed on the final head. Untouched Gateway agent deletion/recreation timeouts, auth-refresh assertions, a sessions-create admission failure, and a channel-reload assertion also appear in the broad run. Auth-refresh failure signatures reproduce on the baseline; the selected candidate auth/grant cases pass. Deletion/reload and remaining catalog/lifecycle failures remain unclassified prior-head evidence gaps; they are not suppressed, not claimed fixed, and no rerun was requested to seek green. Final-head ordinary PR CI is fully successful, so landing uses the normal exact-head guarded squash route without a red-head exception.

@clawsweeper

clawsweeper Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 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 ⚠️ Failed 2026-10-13T05:08:27.209385Z 5856e0b PR opened
ℹ️ 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: L labels Oct 13, 2026
@steipete
steipete merged commit c2074b2 into main Oct 13, 2026
149 of 150 checks passed
@steipete
steipete deleted the steipete/perf-micro-ddl-on-use-audit-20260919 branch October 13, 2026 06:10
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 14, 2026
* perf(sqlite): avoid schema writes on warm store use

* fix(sqlite): reuse the catalog owner for legacy trigger inspection
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 gateway Gateway runtime size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant