Skip to content

perf(sqlite): reuse generated memory schema facts - #174141

Merged
steipete merged 5 commits into
mainfrom
dbasync/memschema
Oct 16, 2026
Merged

steipete merged 5 commits into
mainfrom
dbasync/memschema

Conversation

@steipete

@steipete steipete commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Memory admission reconstructs known schemas in scratch SQLite databases and reapplies already-created STRICT DDL when an index is first opened. This performs unnecessary SQL during first-use and restart preparation.

User Impact

Reduces static memory-schema admission work while preserving stored data, migrations, row identities, custom cache names, and search results. There is no schema-version change or operator action.

Why This Change Was Made

Memory's static storage fragments now use the shared build-generated SQLite fingerprint catalogs. STRICT migration consumes generated native facts and skips scratch reconstruction and DDL replay when its caller already owns creation and all required tables are STRICT. Ordinary generic callers retain index/trigger repair, and unregistered public custom SQL retains its existing native discovery contract. The old memory-only scratch-catalog implementation is deleted.

Only the static slice is included. FTS/tokenizer selection, vec0 dimensions, rebuild-on-mismatch, engine search admission, and PostgreSQL memory support are unchanged. The files named sqlite-memory-catalogs.{json,ts} in postgres-schema.generated/ are SQLite catalog artifacts from the shared generator; PostgreSQL memory schema remains owned by the separate memory-on-PostgreSQL work.

Removed check: the second storage-shape read inside the synchronous migration transaction. Accepted edge case: an unsupported external writer changing schema between preflight and transaction is no longer rechecked under the single-owner contract. Migration data validation, rollback, and actual write authority remain.

Evidence

The 23 STRICT regressions pass, including rowid/AUTOINCREMENT preservation, rollback, missing-table handling, and ordinary caller index repair. All 43 focused memory/facade tests pass. Final catalog equivalence passes 143 cases; catalog contracts pass 24 cases with one runtime-dependent diagnostic skip. Changed-file type-aware lint, formatting and diff checks pass. Two isolated Codex review rounds are complete (implementation through P2, small lint/test repair through P1), both scoped-clean. Knip has no PR-caused findings after removing the now-unused catalog-reader export; the unchanged media and UI findings are reproduced on main.

pnpm db:postgres:gen and pnpm db:postgres:check pass, with a clean regeneration diff. There are no PostgreSQL DDL changes. The new memory artifacts are SQLite catalogs only; PostgreSQL memory schema belongs to the separate memory-on-PostgreSQL work.

Final-head CI 38893856140 completed: production and selected test types, lint, source contracts/export collisions, PostgreSQL conformance, and architecture checks pass. Madge reports zero cycles. T1 is 0 → 0 in touched runtime owners and 222 → 222 globally; the dialect categories remain 1/18/16 → 1/18/16. The assertion-safety shrink check fails only on untouched src/media/media-facts.ts (14 < 16), whose source, scanner and baseline row match main; its dependent CI gate is also red. The failure is inherited from the tested main base; current main has since corrected that row from 16 to 14, and the conflict-free final merge includes the correction. The inherited-only landing exception applies to the prior CI result. Knip's remaining unused exports (readRuntimePromptImageOrder and UI renderActivityGroup) are also demonstrated on main; no new export finding remains.

The required published-driver update cell passed at the original static candidate. Later commits only repair lint/test coverage and remove an unused export, without changing runtime SQL or migration behavior. The separate npm-install acceptance job failed its installed-tree budget (47,651 entries > 47,500); package integrity passed. The overall workflow is not claimed green.

The public SDK comparison covers 155 modules and 3,773 exports: no entry point, exported name, kind, or direct declaration changed. Its 157 reachable-closure deltas all reflect the removal of the unused internal readSqliteSchemaCatalog export from one conservatively included module declaration. That difference is reviewed and accepted.

The P3 search capture preserves all 44 output phases, search SQL, the 10 vector-edge records, and dense-NUL subprocess output byte-for-byte. Its full main stream changes from 968 to 849 execution records: 122 removed schema-admission records and three newly observed records from the existing SQLite runtime/iterator probe. Removing scratch opens delays that probe into the capture's unfiltered publication-open phase; it adds no search work. The admission differences are reviewed separately; full SQL-stream identity is not claimed. The historical 970-record capture used an older base, and its execution-record units differ from harness statement/request counts. Two external capture-audit adaptations account for the current point-delete implementation and that exact runtime probe; negative probes retain the search, vector, output, and runtime gates. Product source and the shared harness were unchanged by those adaptations.

Three alternating harness-v3 pairs completed in M/C/M/C/M/C order on base 186a4ed9808bf5a9cf9d51d5385f2a498de1b640 and candidate 2170eb39241d73735192d56658768e33bdfaccdb, with pinned Node 24.22.0 / SQLite 3.54.0 and unchanged workload/native-image hashes. All six workloads passed 14 turns, cron, compaction, same-state restart, both shutdowns, and cleanup, with zero native SQL/prepare errors or missing causal request coverage. Counts are measured on a busy host; no latency claim.

Memory rows are identical in all three runs per arm. Other rows report median [min–max]; warm rows pool 30 turns per arm. Memory rows count complete worker request envelopes, so they are directly comparable across dispatch timing.

Metric Base Candidate
Initial boot memory admission SQL / requests 0 / 0 0 / 0
First-use live + shadow memory admission SQL / requests 273 / 2 155 / 2
Same-state restart memory admission SQL / requests 13 / 1 13 / 1
Warm causal all-thread SQL 72 [72–78] 72 [72–78]
Warm causal requests 25 [25–27] 25 [25–27]
Warm causal MAIN SQL 0 [0–0] 0 [0–0]
Warm raw all-thread SQL 72 [72–116] 72 [72–104]
Warm raw requests 25 [25–31] 25 [25–31]
Warm raw MAIN SQL 0 [0–13] 0 [0–4]
Whole workload SQL 4114 [4102–4124] 4019 [4011–4032]
Whole workload requests 1080 [1071–1083] 1075 [1074–1081]
Whole workload MAIN SQL 185 [185–186] 185 [185–186]
Raw first-turn SQL 1037 [1003–1038] 888 [877–917]
Raw first-turn requests 157 [150–165] 150 [149–155]
Raw restart boot + connect + first-turn SQL 762 [761–774] 798 [771–808]
Raw restart boot + connect + first-turn requests 229 [226–230] 227 [226–231]

The attributable first-use saving is exactly 118 SQL statements (43.2%) with no request change in every pair: 72 scratch STRICT-schema statements, 32 expected-storage construction/catalog statements, and 14 already-STRICT DDL replays. The ensureMemoryIndexSchema subset falls 250 → 132 SQL. Restart admission stays 13 SQL / 1 request and never rebuilds the schema; this static slice claims no additional restart saving. Warm causal statement/request vectors are byte-for-byte equal across all six runs, and both pooled raw medians are unchanged.

Raw restart SQL rises 762 → 798 (+36) while causal restart-turn work stays exactly 149 SQL / 49 requests / 0 MAIN and memory admission stays 13 SQL / 1 request. In C2/C3, one background transcript-projection publication request falls inside restart: 34 SQL (status tracking/index maintenance, transaction setup, busy-timeout and catalog inspection). The remaining median difference is one primary-key-column read and one legacy ambient-watch sentinel read. These owners are unchanged by this PR. The traces do not establish why projection maintenance falls in that window, so this is disclosed as a timing/trigger attribution limit, not claimed as a restart improvement. Whole-workload SQL and requests both fall. All five tracked shared read families—exact-entry facts, actor hydration, entry-cache snapshots, row facts and watermarks—remain zero during warm turns on both arms; lifecycle counts are retained in the detailed ledger. All 69 observed warm-background source files are byte-identical between base and candidate.

Total diff: +905/−187 lines, including +460/−2 generated catalog output, +139/−50 tests, +50/−2 tooling and +256/−133 production code. The static slice is complete; engine search-admission and computed vec0 work remain held for the PostgreSQL memory integration.

@clawsweeper

clawsweeper Bot commented Oct 16, 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 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-16T11:30:37.133541Z 2170eb3 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.

@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts size: XL labels Oct 16, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 16, 2026
@clawsweeper

clawsweeper Bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR replaces memory schema scratch databases with generated catalogs and skips redundant STRICT schema installation.

Example: Reopen a memory index using the custom cache table embedding_cache.

  • Before: Admission reconstructs expected schemas in temporary SQLite databases and replays already-installed STRICT DDL.
  • After: Admission adapts generated catalog facts to embedding_cache and skips DDL replay when all required tables are already STRICT.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The implementation and native SQLite contract tests support the approach, but completed upgrade evidence and full CI failure attribution are still outstanding.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; focused SQLite tests and generator checks are reported, but its published-driver update cell and boot/restart measurements remain pending, leaving stored-data upgrade compatibility unverified.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Opening or preparing a memory index performs redundant SQLite schema work.
Reason: The maintainer-authored change extends an existing optimization through its intended owner without introducing user settings or changing the persisted representation.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep open: this maintainer-authored PR provides a useful, focused optimization, and source review found no discrete introduced correctness or security defect.

Priority: P2
Reviewed head: 2170eb39241d73735192d56658768e33bdfaccdb

Before merge

  • Complete next step - Classify the exact-head baseline-ratchet failure against its base and resolve any PR-caused failure before landing.
  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

None.

Tests

  • Missing end-to-end proof: The declared published-driver upgrade from v2026.10.4, with retained memory rows, identifiers, settings, and search results across restart, has no completed result in the supplied evidence.
Agent review details

How this fits together

Memory index initialization supplies schema definitions and existing SQLite state to shared admission and migration helpers, which return admitted tables and search availability.

flowchart TD
 A[Memory index initialization] --> B[Storage shape admission]
 C[Generated SQLite catalogs] --> B
 B --> D[Legacy storage migration]
 D --> E[Shared STRICT migration]
 C --> E
 E --> F[Search schema admission]
Loading

Technical review

Best possible solution:

Complete the existing generated-catalog cutover while preserving custom identifiers, generic repair behavior, and stored memory data.

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

Current-main source reconstructs canonical STRICT tables in a scratch database and separately constructs dynamic memory catalogs; no target code was run.

Is this the best way to solve the issue?

Reusing the existing generator is a coherent solution that removes the superseded memory-only owner while retaining native discovery for unregistered custom SQL.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Vincent Koc: Raw commit 681e5a0 adds packages/memory-host-sdk/src/host/memory-schema.ts:349 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 681e5a0f8c47; files: packages/memory-host-sdk/src/host/memory-schema.ts)

PR surface

Source +581, Tests +89, Other +48. Total +718 across 19 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 11 716 135 +581
Tests 5 139 50 +89
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 3 50 2 +48
Total 19 905 187 +718

Review metrics

Metric Value Why it matters
Public SDK option 1 optional field added expectedSchema extends the publicly exported SqliteStrictMigrationOptions without changing required arguments.

Labels

Label changes:

  • add P2: This reduces first-use and restart admission work without an established urgent user-facing failure.
  • add merge-risk: 🚨 compatibility: The shared migration helper and its public SDK options change; existing calls preserve their discovery and repair behavior, and the maintainer-authored direction accepts the additive extension.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: This reduces first-use and restart admission work without an established urgent user-facing failure.
  • merge-risk: 🚨 compatibility: The shared migration helper and its public SDK options change; existing calls preserve their discovery and repair behavior, and the maintainer-authored direction accepts the additive extension.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Provide the completed published-driver upgrade result showing retained memory data and search behavior across restart.

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 execution lanes are retired.

Reviewed October 16, 2026, 7:48 AM ET / 11:48 UTC.

@steipete steipete changed the title improve: reduce memory index schema admission work perf(sqlite): reuse generated memory schema facts Oct 16, 2026
@steipete
steipete merged commit 8a066f0 into main Oct 16, 2026
160 of 163 checks passed
@steipete
steipete deleted the dbasync/memschema branch October 16, 2026 13:57
steipete added a commit that referenced this pull request Oct 16, 2026
PR #174141 intentionally moved static memory admission to the shared
build-generated SQLite catalog registry. The service anchor's lineage
writer retains that registry, including its lazy memory-catalog reader
and JSON URL, in its emitted runtime code. The asset is therefore part
of the runtime closure, not an unused transform emission.

Update the exact artifact inventory while preserving the two-JavaScript-
file boundary and unresolved-import assertions. No runtime change.

On current main the file reproduced the six-versus-five failure with
56 tests passing. After this change all 57 pass with --maxWorkers=1.
Targeted typecheck, lint, format, and independent P2 review pass.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 17, 2026
Use the shared schema fingerprint generator for static memory storage and STRICT admission. Consume generated expected facts instead of rebuilding scratch catalogs and replaying already-current DDL. Preserve migration validation, rollback, row identities and generic custom-SQL admission.

Remove the redundant in-transaction storage-shape read under the single-owner contract. Unsupported external schema changes between preflight and transaction are no longer rechecked.

No schema-version, PostgreSQL DDL or search-semantic changes. Engine search admission and computed vector facts remain outside this static slice.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 17, 2026
PR openclaw#174141 intentionally moved static memory admission to the shared
build-generated SQLite catalog registry. The service anchor's lineage
writer retains that registry, including its lazy memory-catalog reader
and JSON URL, in its emitted runtime code. The asset is therefore part
of the runtime closure, not an unused transform emission.

Update the exact artifact inventory while preserving the two-JavaScript-
file boundary and unresolved-import assertions. No runtime change.

On current main the file reproduced the six-versus-five failure with
56 tests passing. After this change all 57 pass with --maxWorkers=1.
Targeted typecheck, lint, format, and independent P2 review pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant