Repository navigation
fix(memory): rebuild never finishes on large indexes after updating - #196378
Conversation
A full memory rebuild, such as the format upgrade after updating from 2026.10.9, reuses each chunk's published vector instead of embedding it again. Two steps of that path held a whole pass in one bounded worker: - Vector reuse asked the read worker for every candidate's vector in one cache.read, up to 50,000 chunks per pass, and the worker decodes each vector into a JavaScript number array, 8 bytes per dimension, inside its 512 MiB heap. - Publication staged every fragment of a source in the SQLite store worker's memory until the source was replaced. A source's fragments carry its vectors as JSON, about 30 KB per 1536-dimension chunk. On an index of 95,884 chunks with 1536-dimension vectors the rebuild failed at the first step with ERR_WORKER_OUT_OF_MEMORY [task=memorySearch.task], and with that step fixed it failed at the second in the SQLite store worker. Each failure starts the rebuild over, so vector search never comes back. The host now reads cached and published vectors in pages of whole hashes, sized to 8 MiB of decoded vectors (682 hashes at 1536 dimensions), and merges the pages. All chunks that share a hash stay in one page, so the published-row agreement check sees the same rows as before. Staged fragments stay in worker memory up to 32 MiB; past that a source's fragments spill to a private temporary file, are read back in order when the source is replaced, and the file is removed when the stage settles. Published rows and vectors are unchanged.
|
🦞👀 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: needs maintainer review before merge. What this changesThis PR pages stored-vector reads and packs staged publication vectors into binary64 arrays to reduce worker heap usage. Example: Rebuild an existing index containing 94,919 chunks with 1,536-dimensional vectors.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR fixes a demonstrated large-index rebuild failure still present on current main. No introduced correctness defect was found; the remaining CI failures have documented reproductions without this diff. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherMemory Core prepares indexed chunks, retrieves reusable vectors through a read worker, and transfers source rows to the existing SQLite publication worker for atomic replacement. flowchart TD
A[Memory index request] --> B[Prepared chunks]
B --> C[Paged vector reads]
C --> D[Publication fragments]
D --> E[Packed worker staging]
E --> F[Atomic source replacement]
F --> G[Hybrid memory search]
Technical reviewBest possible solution: Retain the existing read and publication owners while paging vector retrieval and storing staged vectors compactly without changing atomic replacement or stored bytes. Do we have a high-confidence way to reproduce the issue? The source exposes both whole-pass memory accumulations, and exact-head Docker CLI traces demonstrate base OOM followed by successful candidate rebuilds; this read-only review ran no target code. Is this the best way to solve the issue? The change addresses both demonstrated allocations at their existing owners, keeps same-hash candidates together for ambiguity checks, preserves fragmented-row ordering, and retains transaction admission and session tombstones. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against b06aeb5b8c86. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +72. Total +72 across 3 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. 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 HistoryReview history (5 earlier review cycles)
Reviewed November 12, 2026, 12:03 AM ET / 05:03 UTC (Revision 6). |
Publication staging keeps up to 32 MiB of fragments in worker memory as before. A larger source now overflows into a connection-local TEMP table on the publication worker's own SQLite connection instead of a private file under os.tmpdir(), which root AGENTS.md (no sidecar stores) and lint:tmp:no-random-messaging both reject. The table is read back in ordinal pages and dropped when the publication settles or is discarded.
|
Thanks for the review. Both findings are fixed in 19cfc48:
I reran the proof on the new head. The capped-heap test is red on main and on each half alone, and green with both. The 95,884-chunk CLI rebuild fails on main after 27 s and finishes in 294 s with this change, with identity valid and no worker OOMs. The description has the updated evidence. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…ct ratchet The SQLite dialect ratchet counted the new overflow stage's CREATE TEMP TABLE as temp-schema design debt. Only the SQLite publication backend builds that stage; PostgreSQL publication spools through manager-publication-postgres.ts. Classify temp-schema in manager-publication-stage.ts as engine maintenance, next to the existing Knowledge and PostgreSQL-spool owners, and keep every other construct in that file and the same TEMP table anywhere else counted.
|
The remaining finding is fixed in 36f62ec:
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…table Staged rows are parsed as they arrive and keep their vectors in the stored binary64 encoding, so a large source no longer holds about 20 JSON characters per dimension in the publication worker heap. The single atomic source.replace is unchanged and no table is added.
|
Proof at 5d285b2 (built CLI in Docker, node 24.22.1, no secrets, local stand-in embeddings endpoint). Fixture built on main through the real path: 12 imported session transcripts plus 200 notes, 213 files, 94,919 chunks at 1536 dims. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Maintainer override: the two red changed-extensions bundles in CI run 43152375306 were already red on main. This PR's diff does not cause them. Red jobs:
The same three tests fail without this PR. I ran them in a secretless Docker container (node:24.22.1) with
Bisect on main, running the borrowed-connection and publication-admission files:
The first bad commit is |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…penclaw#196378) fix(memory): let large memory rebuilds finish without running out of worker memory A full memory rebuild ran out of its 512 MiB worker and restarted on every attempt when the index held tens of thousands of embedded chunks, for example after the chunking-format upgrade from 2026.10.9, so vector search never came back and search kept serving the old keyword index. Two steps held a whole pass in one worker. Vector reuse now reads cached embeddings in pages of whole hashes sized to 8 MiB of decoded vectors. The SQLite publication worker now parses each staged row as it arrives and keeps its vector as a Float64Array instead of JSON, turning one row at a time back into a number array at source.replace, which stays one atomic replace. Stored bytes, schema and retention are unchanged, no table is added, and the PostgreSQL path is untouched. Evidence: a 94,919-chunk index at 1536 dimensions built through the real import and memory index paths in a secretless node:24.22.1 container with a stand-in embeddings server. On the PR base and current main, the format-upgrade rebuild and memory index --force ran out of memory after 19-33 s with the read worker near 490 MiB, and a running Gateway retried and failed again while search served the keyword index. With this change both rebuilds finish in 320-415 s with peak worker heaps near 100-110 MiB, no embedding calls, byte-identical stored vectors and vector search hits. A 634-chunk index and an already-rebuilt index behave the same on both. The red changed-extensions bundles are three memory-core integrity tests that fail on main since openclaw#194484: openclaw#196378 (comment). Net 0 test lines. Details: openclaw#196378 (comment). Thanks @garrytan. Co-authored-by: Ayaan Zaidi <[email protected]>
…196378) fix(memory): let large memory rebuilds finish without running out of worker memory A full memory rebuild ran out of its 512 MiB worker and restarted on every attempt when the index held tens of thousands of embedded chunks, for example after the chunking-format upgrade from 2026.10.9, so vector search never came back and search kept serving the old keyword index. Two steps held a whole pass in one worker. Vector reuse now reads cached embeddings in pages of whole hashes sized to 8 MiB of decoded vectors. The SQLite publication worker now parses each staged row as it arrives and keeps its vector as a Float64Array instead of JSON, turning one row at a time back into a number array at source.replace, which stays one atomic replace. Stored bytes, schema and retention are unchanged, no table is added, and the PostgreSQL path is untouched. Evidence: a 94,919-chunk index at 1536 dimensions built through the real import and memory index paths in a secretless node:24.22.1 container with a stand-in embeddings server. On the PR base and current main, the format-upgrade rebuild and memory index --force ran out of memory after 19-33 s with the read worker near 490 MiB, and a running Gateway retried and failed again while search served the keyword index. With this change both rebuilds finish in 320-415 s with peak worker heaps near 100-110 MiB, no embedding calls, byte-identical stored vectors and vector search hits. A 634-chunk index and an already-rebuilt index behave the same on both. The red changed-extensions bundles are three memory-core integrity tests that fail on main since #194484: #196378 (comment). Net 0 test lines. Details: #196378 (comment). Thanks @garrytan. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 3e7fb1b) Release adaptation: page the release branch's existing cache-only reads; do not import newer published-vector fallback, PostgreSQL, or retirement owners. Retain provider identity order, disabled-cache behavior and SQLite publication contracts. Packed staging is unchanged from the source fix. Companion review: 3ea0883 (#195369) is a separate cache-retention change, not required for bounded reads or packed staging; intentionally excluded. No later PR-number follow-ups. Existing transfer/settlement fixtures retain the same protocol. No storage format, schema or retention change. Proof: Node syntax checks and exact production staging-helper value/order, replay and fragmented-tail checks pass. Full owner tests/typecheck remain unrun: isolated worktree has no dependencies; no install authorized. Independent review remains with the parent (worker cannot spawn children). Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vincentkoc <[email protected]> (cherry picked from commit 8d8df0799fba9770b913bdc9be546915c8351a8c)
…196378) fix(memory): let large memory rebuilds finish without running out of worker memory A full memory rebuild ran out of its 512 MiB worker and restarted on every attempt when the index held tens of thousands of embedded chunks, for example after the chunking-format upgrade from 2026.10.9, so vector search never came back and search kept serving the old keyword index. Two steps held a whole pass in one worker. Vector reuse now reads cached embeddings in pages of whole hashes sized to 8 MiB of decoded vectors. The SQLite publication worker now parses each staged row as it arrives and keeps its vector as a Float64Array instead of JSON, turning one row at a time back into a number array at source.replace, which stays one atomic replace. Stored bytes, schema and retention are unchanged, no table is added, and the PostgreSQL path is untouched. Evidence: a 94,919-chunk index at 1536 dimensions built through the real import and memory index paths in a secretless node:24.22.1 container with a stand-in embeddings server. On the PR base and current main, the format-upgrade rebuild and memory index --force ran out of memory after 19-33 s with the read worker near 490 MiB, and a running Gateway retried and failed again while search served the keyword index. With this change both rebuilds finish in 320-415 s with peak worker heaps near 100-110 MiB, no embedding calls, byte-identical stored vectors and vector search hits. A 634-chunk index and an already-rebuilt index behave the same on both. The red changed-extensions bundles are three memory-core integrity tests that fail on main since #194484: #196378 (comment). Net 0 test lines. Details: #196378 (comment). Thanks @garrytan. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 3e7fb1b) Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit 512b5d231bff565381824a8796ccb9417f118ef6) Co-authored-by: vincentkoc <[email protected]>
Related: #195414, #192762
What Problem This Solves
A full memory rebuild runs out of worker memory and starts over on every attempt when the index holds tens of thousands of embedded chunks. One trigger is the chunking-format upgrade after updating. Vector search never comes back, and search keeps serving the old keyword index.
Why This Change Was Made
A rebuild reuses each chunk's published vector, and two steps of that path held a whole pass inside one 512 MiB worker:
collectCachedEmbeddingssent every candidate of a pass in onecache.read: up to 50,000 chunks. The read worker decodes each stored vector into a JavaScript number array, so a full pass at 1536 dimensions is about 600 MB.cache.readnow runs in pages of whole hashes, each sized to 8 MiB of decoded vectors, and the host merges the pages. All chunks that share a hash stay in one page, so the published-row check sees the same rows as before.source.replace, about 20 characters per vector dimension.stage.appendnow parses each sealed row as it arrives and keeps its vector as aFloat64Array, the same binary64 values the index stores, so 8 bytes per dimension outside the JS heap.source.replacereads the rows back in order and turns one vector at a time back into a number array.Nothing else changes: no table, schema, SQL, config, heap limit or retention change, the same single atomic
source.replace, and the PostgreSQL path is untouched. Stored vectors are byte-identical.An earlier revision staged large sources in a connection-local TEMP table. This revision drops that table, its dialect-ratchet classification, the storage-changes doc line, the test-line allocation and the new tests.
Evidence
End to end through the built CLI in Docker (node 24.22.1, no secrets), with a local stand-in OpenAI embeddings endpoint (deterministic 1536-dim vectors). The fixture was built on main through the real path: 12 session transcripts (93,612 events) imported with
openclaw doctor --session-sqlite importplus 200 notes, thenopenclaw memory index, giving 213 files and 94,919 chunks. Each run restores that state, then triggers the rebuild. The worker heap peaks come from an observation-onlyworker.getHeapStatistics()sampler.ERR_WORKER_OUT_OF_MEMORY [task=memorySearch.task]--force--forceRestart loop on main, in a running Gateway (
openclaw gateway run, format upgrade pending, onememory.searchcall opens the index):sync failed (search-identity-repair): ERR_WORKER_OUT_OF_MEMORY [task=memorySearch.task]at 04:04:43, then the retries fail the same way at 04:09:39 and 04:10:46, while search answers "format upgrade rebuild is pending; serving the existing keyword index".On both candidate runs, no embedding request was made during the rebuild, the digest of every (hash, vector) pair is identical before and after, and
openclaw memory searchreturns hybrid hits with vector scores.Controls:
Focused tests in the container:
manager-publication-transfer,manager-publication-print-onceandmanager-publication-settlementpass (29 tests), including oversized rows that span fragments and staged cache vectors of 4,194,305 coordinates.