Repository navigation
perf(memory): reuse generated search schema admission facts - #174438
Conversation
|
🦞👀 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. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: blocked before merge. What this changesThis PR reuses generated SQLite search-schema fingerprints and successful vector-creation receipts during memory admission. Example: Re-admit a memory index containing quartz.md with a three-dimensional vector index.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 1 item remains Keep open: this maintainer-authored PR provides a distinct admission optimization, with no definite code defect found; its explicit coordination hold remains. Priority: P2 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherMemory schema setup and publication workers pass search definitions to the database engine, which admits SQLite derived indexes and returns bound search capabilities. flowchart TD
A[Memory schema owner] --> B[Search admission]
C[Publication worker] --> B
B --> D[Generated SQLite fingerprints]
B --> E[FTS reconciliation]
B --> F[Vector schema receipts]
E --> G[Bound search capabilities]
F --> G
Technical reviewBest possible solution: Keep generated search facts under the existing database-engine owner while preserving canonical memory data and established rebuild behavior. Do we have a high-confidence way to reproduce the issue? Current-main source shows unconditional FTS DDL replay and the separate vector existence check; no target code was run. Is this the best way to solve the issue? The approach fits the existing generated-catalog and physical-database admission owners without introducing a competing cache or changing PostgreSQL definitions. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 60ae44b74559. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +279, Tests +250, Other +31. Total +560 across 18 files. Added test files: 1. View PR surface stats
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 16, 2026, 1:13 PM ET / 17:13 UTC. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0dcdd6c7d3
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| import { ensureMemoryRecallMetadataSchema } from "./memory-schema-recall.js"; | ||
| import { migrateMemoryIndexStorage } from "./memory-schema-storage-migration.js"; | ||
| import { memoryTextSearchSchema } from "./memory-search-schema.js"; | ||
| import { admitStoreSearch } from "./openclaw-runtime-kysely.js"; |
There was a problem hiding this comment.
Keep schema admission off the Kysely dependency graph
Because memory-schema.ts is imported by agent-database bootstrap and Doctor for migration helpers, this static import now evaluates openclaw-runtime-kysely.ts, which reexports kysely-sync; admitStoreSearch also eagerly imports the full search binding graph, including the Kysely-backed SQLite full-text and vector modules. Schema-only startup therefore cold-loads these capabilities even when FTS is disabled. Move the schema-admission operation to a non-Kysely bridge and bind search capabilities only at their actual caller.
AGENTS.md reference: AGENTS.md:L74-L74
Useful? React with 👍 / 👎.
| !matchesSqliteMemorySearchFragment(catalog, { | ||
| kind: "vector", | ||
| tableName: index.table, | ||
| dimensions, | ||
| }) |
There was a problem hiding this comment.
Validate the public vec0 contract instead of private tables
On a cold reopen with a documented custom store.vector.extensionPath, a loadable and query-compatible sqlite-vec build can use a different private shadow-table layout than the bundled 0.1.9 binary used to generate this fingerprint. This whole-catalog comparison then rejects the existing index with “rebuild the derived memory index”; rebuilding with the same configured extension recreates the same private layout, so admission remains permanently broken. Validate the stable vec0 declaration, visible columns, and dimensions instead of generated private shadow tables, or explicitly enforce an extension-version contract.
AGENTS.md reference: AGENTS.md:L57-L57
Useful? React with 👍 / 👎.
|
Reviewed the two later automated suggestions against the source. Both are retained as follow-ups under the maintainer's relaxed landing policy: schema-only imports now eagerly reach the Kysely search capability graph, and vec0 fingerprints can reject a query-compatible custom build whose private shadow-table layout differs from the bundled build. No startup failure, measured latency regression, or affected custom build was demonstrated. The PR body now states both limitations and does not claim universal custom-build compatibility. Separating admission from capability binding and narrowing the custom-layout contract remain follow-ups. Landing still waits for the explicitly required final-head PostgreSQL pass. The job ran; memory/search cases passed, but all three Matrix portability cases hit the shared fixture's stale fresh-root rejection expectation. The confirmation harness pair remains queued under the shared semaphore. |
Project the declared table catalog fields explicitly when canonicalizing custom memory-search table names. Preserve immutable input and all existing fingerprint inputs without the map-spread suppression added by #174438. The existing suppression inventory reproduces 95 vs 94 before this change. All 12 memory-schema cases and three suppression-inventory tests pass.
…#174438) Route memory search admission through the existing engine owner and reuse generated catalog fingerprints, including computed vector dimensions. Preserve tokenizer, result, rebuild, and PostgreSQL behavior. First-use memory admission falls from 155 to 147 statements; cold vector admission adds five catalog statements in the same request, for a net three-statement subsystem saving. Restart and warmed-turn counts do not regress. Preserve the canonical Matrix portability fixture and both sides of the wrapper inventory during integration.
…aw#174689) Project the declared table catalog fields explicitly when canonicalizing custom memory-search table names. Preserve immutable input and all existing fingerprint inputs without the map-spread suppression added by openclaw#174438. The existing suppression inventory reproduces 95 vs 94 before this change. All 12 memory-schema cases and three suppression-inventory tests pass.
…exes (#175555) Related: #144641, #174438 ## What Problem This Solves Memory index admission counted rows of the FTS5 table with `SELECT COUNT(*)`. FTS5 serves that count as a full scan of its `%_content` shadow table. On large stores this added up to about 1.7 s of cold I/O, inside the agent database write transaction. ## User Impact User impact: memory stores with a large full-text index open faster and hold the agent database write lock for less time. Search results, config, schema and stored data do not change. ## Why This Change Was Made The admitted body FTS DDL keeps the default `columnsize=1`, so FTS5 stores one `%_docsize` row per document. The reconcile check now counts `<fts>_docsize`, which gives the same number from a much smaller table (211 pages instead of 20,567 on a 43,490-chunk store). Admission drops and recreates any FTS table with different DDL before the count runs, so the docsize table is always present. The rebuild decision and its repair are unchanged. ## Evidence - Focused test `memory-schema-fts-reconcile.test.ts`: 16/16 pass. The new test checks that the query plan reads `memory_index_chunks_fts_docsize`, not the virtual table, and that the count equals `COUNT(*)` of the FTS table after deletes, re-inserts, edits and empty rows. - Built CLI on this head, isolated state: `openclaw memory index` on 31 memory files gave 31 chunks, 31 docsize rows, 31 content rows. Deleting 12 FTS rows left 19/19. The next `openclaw memory search zebracorn` admission saw the mismatch, rebuilt the index back to 31/31, and returned all 30 matching notes. - Contributor benchmark on two real stores: cold first admission 2,003-2,060 ms to 317-325 ms (43,490 chunks) and 220-230 ms to 72 ms (6,012 chunks). - Hosted CI green and ClawSweeper `ready` on the merged head. Co-authored-by: Ayaan Zaidi <[email protected]>
…exes (openclaw#175555) Related: openclaw#144641, openclaw#174438 ## What Problem This Solves Memory index admission counted rows of the FTS5 table with `SELECT COUNT(*)`. FTS5 serves that count as a full scan of its `%_content` shadow table. On large stores this added up to about 1.7 s of cold I/O, inside the agent database write transaction. ## User Impact User impact: memory stores with a large full-text index open faster and hold the agent database write lock for less time. Search results, config, schema and stored data do not change. ## Why This Change Was Made The admitted body FTS DDL keeps the default `columnsize=1`, so FTS5 stores one `%_docsize` row per document. The reconcile check now counts `<fts>_docsize`, which gives the same number from a much smaller table (211 pages instead of 20,567 on a 43,490-chunk store). Admission drops and recreates any FTS table with different DDL before the count runs, so the docsize table is always present. The rebuild decision and its repair are unchanged. ## Evidence - Focused test `memory-schema-fts-reconcile.test.ts`: 16/16 pass. The new test checks that the query plan reads `memory_index_chunks_fts_docsize`, not the virtual table, and that the count equals `COUNT(*)` of the FTS table after deletes, re-inserts, edits and empty rows. - Built CLI on this head, isolated state: `openclaw memory index` on 31 memory files gave 31 chunks, 31 docsize rows, 31 content rows. Deleting 12 FTS rows left 19/19. The next `openclaw memory search zebracorn` admission saw the mismatch, rebuilt the index back to 31/31, and returned all 30 matching notes. - Contributor benchmark on two real stores: cold first admission 2,003-2,060 ms to 317-325 ms (43,490 chunks) and 220-230 ms to 72 ms (6,012 chunks). - Hosted CI green and ClawSweeper `ready` on the merged head. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Memory search admission repeatedly inspects individual FTS objects and replays already installed DDL. Vector admission also repeats a table-existence read after the memory owner has already read that fact.
User Impact
Memory indexing and search keep their existing tokenizer, search results, and dimension-change rebuild behavior. Admission does less database work. There is no schema-version bump or required user action.
Why This Change Was Made
Route memory's named text and vector extensions through
admitStoreSearch. Add the four FTS variants and one vec0 template to the existing hash-first SQLite catalog generator. Runtime admission compares native catalog facts against those fingerprints; it computes the dimension-dependent vec0 declaration without replaying expected DDL. Successful vector creation publishes its schema receipt directly, and owner DDL invalidates that receipt.FTS body and path admission share one catalog snapshot and savepoint. Matching indexes retain their maintenance triggers without replaying CREATE statements. Existing collision protection, rowid reconciliation, tokenizer rebuilds, and canonical source updates remain covered by regression tests.
Removed work and accepted edge cases:
readMemoryDatabaseFacts().hasVectorTableinstead of querying table existence again. Uncoordinated external writes are outside the single-owner contract.The PostgreSQL memory search definitions and PostgreSQL admission branch are unchanged. The generated memory assets remain SQLite catalog data only; PostgreSQL memory DDL continues to come from its existing owner.
Measurements
Values are median [min–max], with three runs per side; warm rows pool 30 turns per side. Memory admission counts cover the complete worker requests that contain schema admission.
The narrower
ensureMemoryIndexSchemawork falls 132 → 124 statements; its FTS work falls 38 → 30. These are overlapping subsets of the first-use row. Cold vector admission adds five native catalog statements inside the same existing request. Creation and the following publication write are byte-identical. The net measured subsystem change is −3 statements / 0 requests. The vector comparison aligns actual request executions because the new function names tag existing requests that the baseline did not label as vector admission.Raw first-turn medians are 861 [744–895] → 868 [698–920] SQL and 152 [146–158] → 151 [142–153] requests. The combined startup and whole-workload totals decrease. In C2, one 71-statement admission request ran during connect and the remaining 76 during first turn; the other candidate runs performed all 147 during first turn. The combined admission window avoids treating this phase movement as a saving. The SQL-median runs (M1 and C3) differ by −8 memory-schema statements, +12 other background statements, and +3 turn reads. Those three reads (
canonical_ready, quarantineuser_version, and its decision) already occur in baseline M2/M3 and remain within the same 62 turn requests. First-turn causal work stays at median 219 SQL / 62 requests / 0 MAIN. Whole-workload request movement is not attributed to this change.No memory-schema work executes in warm turns. Raw warm background differences come from existing leases, configuration/catalog work, passive WAL checkpoints, and monitoring; raw MAIN outliers are existing state-lease reads. All five monitored shared-read families are zero in every causal warmed turn. Their whole-workload distributions are retained below rather than called identical:
The row-fact increase is in second-session activity, offset at the median by fewer entry-cache snapshot reads. Both row-fact variants occur on both sides (M2 has the higher count; C2 has the lower count). No shared-family warmed increase is hidden in the total.
Evidence
pnpm db:postgres:genpasses. It changes only the SQLite memory catalogs; there are no PostgreSQL DDL changes.pnpm db:postgres:checkalso passes (generator tests, equivalence tests, and canonical/workboard/logbook deterministic verification).ec90dc1ef23dd9c9dd731479b4431d9b082b78d5and candidatea18f1a2c4daa885d880542f43e0503388cc1841d. Pre-integration heade43d20b3045c7dc4f6e9ddca2bc290e5b54ba6bcadds only comments/annotations and wrapper inventory entries; executable source is unchanged. All 84 turns and 12 shutdowns pass; no native SQL/prepare errors, missing dispatch records, or remaining fixture children. Node, SQLite, native-library and harness pins match across all six runs. Independent review checks all 25,864 aggregate distributions against the individual ledgers.admitStoreSearchmoves fromadapters.tstosearch-admission.ts.dist/windows-security-helper.exereferences in the two sealed updater runtimes. All 13 scanner, build, staging, manifest, and lock inputs are identical on this base, candidate, final head, and the main-rule reproduction at07667dcc8f4d. This is reused exact-main-rule evidence over existing generated artifacts, not a fresh main tarball or an executed update. The package/build and handoff staging failure is already routed to its owners. No retry was made.git diff --checkpass. Pre-integration CI passes one43d20b3045c7dc4f6e9ddca2bc290e5b54ba6bc, including PostgreSQL conformance, production/test types, lint, source contracts, Madge, and the T1/dialect/worker ratchets. Knip reproduces exactly the base’s 3 production / 4 full-tree / 0 scripts findings in unchanged agent, Gateway, and Discord files; none are in this change, and the findings are already routed for repair.Database-engine owner clearance is complete. Integration head
0dcdd6c7d3f1e06c980b90099bced2f845e8ee5dmerges main0e16643538c1e41ec0d22990738749d2413055c5; the only conflict was the generator import block, resolved by keeping both client-credential and memory-search imports. Main's database-engine behavior and both wrapper inventory additions are preserved.Published-driver update cell: waived by the maintainer for this forward-only admission change. The inherited Windows-helper packaging blocker above remains documented; this PR does not modify the updater, activation, or Doctor flow. No executed-update claim is made.
Integration proof and review follow-ups
The first integration rerun passes all 193 requested owner cases: search-extension 6, memory fragments 12, agent-port 3, generated/native catalog equivalence 149, and STRICT 23. PostgreSQL generation and check both pass; generation leaves the working tree unchanged, and this slice introduces no PostgreSQL DDL changes.
Integration CI ran PostgreSQL conformance. Its memory/search cases passed, but three Matrix portability cases failed because the fixture expected fresh roots to require legacy repair. While the test-only correction was being reviewed, main landed
682eb8ce748, which seeds actual legacy dedupe rows before expecting refusal. Final headd29e3b5342090a4e740d88acd5449d374128bb36keeps that Matrix test exactly as main, superseding the local correction. The Matrix file is absent from the final PR diff. All port, backup, resume, rollback, retained-byte and startup-refusal assertions remain. The merge also preserves R19's PostgreSQL search changes; no design conflict occurred. Final CI run 38957102456 passes ond29e3b5342090a4e740d88acd5449d374128bb36. PostgreSQL conformance actually ran and passed (job 117163171456); it was not path-skipped. The aggregateopenclaw/ci-gate, production/test types, lint, source contracts, architecture checks, and baseline ratchets all pass. No CI failure override is used. Finalpnpm db:postgres:genandpnpm db:postgres:checkboth pass; generation leaves the tree unchanged and there are no PostgreSQL DDL changes in this PR.The coordinator-requested single M,C confirmation pair completed on main
0e16643538c1e41ec0d22990738749d2413055c5versus integration0dcdd6c7d3f1e06c980b90099bced2f845e8ee5d. All 17 source/generator/generated/test files in the final PR delta are byte-identical to that candidate; only the wrapper inventory incorporates later main entries. The final integration preserves the incoming PostgreSQL behavior, which final CI covers. No extra harness pair was run.All ten causal warm arrays match exactly. Current main's session batching lowers the median from the earlier 70/23; the 67→70 variation is one versus two trajectory-event transaction batches. No memory admission or monitored shared-read family executes in warm turns. Cold vector admission remains 1→6 SQL in the same request; first creation 11→11 and subsequent write 17→17 remain byte-identical. Net attributed subsystem change remains −3 SQL / 0 requests.
All 28 turns and four shutdowns pass, with zero native errors or missing dispatch and matching runtime/library/workload pins. All 34 ledger audit checks pass. The rebase capture again has all 44 outputs byte-identical, the exact same 59 individually reviewed catalog/savepoint differences, and 812 remaining ordered records byte-identical. Its original full-SQL comparator result is preserved; full SQL identity is not claimed.
The raw +62 SQL/+5 requests are retained and reconciled: −3 memory, +34/+1 from one extra restart transcript-projection maintenance request, +12/0 passive WAL checkpoints, +1/0 busy-timeout adjustment, and +18/+4 net unchanged lifecycle maintenance/admission/batching. The last group includes registry maintenance, cron polling/ticks, quarantine health reads, worker placement, and upstream monitoring. Causal first-turn work rises by two existing worker-admission statements (
user_versionand quarantine) in the same request; all warmed causal work is identical. These are source-attributed execution differences, not excluded records or a whole-workload saving claim. No latency claim.Two subsequent automated review suggestions are recorded as follow-ups under the maintainer's relaxed landing policy:
memory-schemaimport graph reaches Kysely through the runtime bridge and search capability binding even for schema-only callers. This defeats the intended lazy cold-path boundary. Separate schema admission from capability binding in a follow-up; no startup failure or measured latency regression is established here.These are acknowledged limitations, not claims of a clean later bot review. They do not change the earlier isolated Codex review result.