Repository navigation
fix(memory): rebuild reuses cached embeddings instead of evicting them first - #182968
Conversation
Defer embedding-cache eviction while full memory indexing is staged so new misses cannot evict cached vectors that later batches still need. Trim after publication or discard, including failure and suspended-rebuild shutdown. Incremental writes keep their existing per-commit capacity bound. Also capture SQL while native test statements are live, preserving the cache capacity assertions on Node after statement finalization. Fixes #182886 Thanks @etzelm for the reproduction and provider-input counts.
|
🦞👀 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: needs maintainer review before merge. What this changesThis PR preserves cached embeddings throughout full memory rebuilds and trims excess cache rows after publication or discard. Example: A rebuild needs 12 vectors, with 8 cached and 4 missing in a cache at capacity.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it addresses the current rebuild eviction cascade with a focused change, and no actionable defect was found. Exact-head PostgreSQL CI remains pending. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe memory-core indexing manager reads source chunks and cached vectors, requests missing embeddings, and atomically publishes a replacement search index while retaining the published database as the cache owner. flowchart LR
A[Memory and session sources] --> B[Rebuild manager]
C[Published embedding cache] --> B
B --> D[Embedding provider]
D --> C
B --> E[Shadow index]
E --> F[Atomic publication]
F --> G[Existing cache pruning]
G --> C
Technical reviewBest possible solution: Retain reusable vectors until the existing rebuild owner finishes or discards its work, then apply the existing cache cap. Do we have a high-confidence way to reproduce the issue? Current-main cache reads leave timestamps unchanged while miss writes evict unread hits; the reporter supplies CLI counts and the PR reports base-failing manager regressions, but this review ran no target code. Is this the best way to solve the issue? The patch addresses eviction at its existing lifecycle owner without a cache snapshot, extra corpus pass, schema change, or competing policy path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 0f6631638b2e. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +16, Tests +136, Docs +6. Total +158 across 8 files. Added test files: 1. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
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 24, 2026, 6:28 PM ET / 22:28 UTC. |
…m first (openclaw#182968) At the embedding cache cap, a full memory rebuild evicted cached vectors it had not read yet to make room for each miss, then re-embedded them too, so the rebuild after database port could send every chunk to the provider. Memory Core now defers eviction while a rebuild consumes cached vectors and trims to the cap on publication or discard, including failure and shutdown; incremental writes keep their capacity bound. Live SQLite and PostgreSQL rebuilds embed only the misses (4 instead of 12) and finish at the 50,000-row cap. Fixes openclaw#182886. Thanks @etzelm.
Fixes #182886. Thanks @etzelm for the reproduction and provider-input counts.
What Problem This Solves
Full memory rebuilds at the embedding-cache cap evict cached vectors before later rebuild batches read them, turning a few misses into provider calls for the whole index. Forced indexing and the rebuild after an agent database-engine port share this path.
User Impact
Rebuilds reuse cached vectors and embed only the misses. The cache may temporarily grow by newly generated vectors during a rebuild; publication, failure, and abandonment trim it back to the existing cap. Suspended background rebuilds retain their vectors until resumption or discard. A process interruption can leave excess rows until the next synchronization prunes them. Incremental writes retain their per-commit capacity bound. No configuration, schema, or dependency changes.
Why This Change Was Made
The existing rebuild owner tracks pending cache cleanup alongside its staged index. Generated-cache writes defer eviction while that rebuild exists, and the same pruning owner handles SQLite and PostgreSQL cleanup. This avoids another corpus pass or holding a full vector-cache snapshot in JavaScript. Failed rebuilds preserve the published index and retain generated vectors under the normal cache policy.
The separate PostgreSQL query-plan issue #182808 already has PR #182821; this PR leaves its eviction query unchanged. A bounded nearby test repair captures SQL while native statements are live, preserving existing cache-capacity assertions after Node finalizes those statements.
Evidence
Acceptance: with 8 reusable vectors and 4 missing vectors in a cache at capacity, embed exactly 4 inputs, keep all 12 indexed chunks, and settle back to the cap. Cover both populated and empty published indexes, plus failed publication and suspended shutdown.
dc3a0a6a3d7a: the original manager regressions sent 12 inputs instead of 4, for both populated and empty published indexes. The extracted focused suite passes both cases, failure cleanup, and incremental commit bounds: 4 tests, 9.55s of test time. These need the real manager/cache/publication composition; cache-helper tests alone miss the cascade.memory index --forceembedded exactly 4 inputs, published 12 chunks, and finished with 50,000 cache rows.memory index --force, with the same 50,000-row/8-hit/4-miss fixture and an empty derived index: exactly 4 inputs, 12 chunks, and 50,000 cache rows afterward.StatementSync.sourceSQLafter disposal; after repairing that observer, 19/19 passed in 10.20s wall time (0.2s tests). Query counts, query plans, storage, and rollback assertions remain intact. Together these cover 93 distinct passing cases.run-tsgo, oxlint, oxfmt, Madge (0 cycles), andgit diff --checkpass. Isolated Codex review found no actionable P0–P2 issues.All product invocations used isolated HOME/state, distinct service profiles, and synthetic data. PostgreSQL uses a disposable local UTF8 PostgreSQL 17 database with the documented search extensions. A remote attempt failed authentication before returning a lease; no remote proof is claimed.
The full
database portattempt stopped during preparation: the fresh server initially lackedunaccent, and the retained manifest then refused resume/rollback with “observed changed source data; required captured original SQLite image.” No engine switch or successful port is claimed. Captures remain intact. PostgreSQL cache proof uses a fresh PostgreSQL-backed CLI rebuild with an empty derived index instead.The full
check:changedSQLite-inventory step was omitted under the campaign's local gate budget; PR CI is the broad proof. CI seconds are not yet available. Diff: production +25/-9, tests +194/-58 (including moving the existing capacity case), docs +9/-3.