Repository navigation
fix(memory): reuse completed embeddings after failed rebuilds - #144404
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: blocked before merge. Reviewed September 10, 2026, 8:02 PM ET / September 11, 2026, 00:02 UTC (Revision 2). ClawSweeper reviewWhat this changesMemory indexing retains completed embeddings across failed rebuilds, bounds the retained cache, clears unpublished cached results during Forget, and preserves structured provider error metadata. Merge readiness⛔ Blocked before merge - 1 item remains The prior cache-cap blocker is resolved, and no remaining blocking defect was found. The recovery improvement remains necessary on current main; the related merged cooldown work does not supersede it. Priority: P2 Review scores
Verification
How this fits togetherMemory Core converts workspace files and session transcripts into searchable text and vector indexes. Its embedding cache avoids repeated provider requests, while shadow databases keep incomplete rebuilds from replacing the published index. flowchart TD
A[Memory files and sessions] --> B[Prepare content chunks]
B --> C{Cached embedding available?}
C -->|Yes| E[Build shadow index]
C -->|No| D[Embedding provider]
D --> F[Validate and retain completed embeddings]
F --> E
E -->|Successful rebuild| G[Publish searchable index]
H[Forget selected sessions] -->|Clear retained embeddings| F
Before merge
Agent review detailsSecurityNone. PR surfaceSource +251, Tests +334, Docs +12, Other 0. Total +597 across 20 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Keep one bounded, durable embedding cache independent of atomic index publication, with source validation and Forget invalidation preserving the documented deletion contract. Do we have a high-confidence way to reproduce the issue? Yes, from source: complete embeddings during a full rebuild, fail before shadow publication, restart, and retry. Current main discards that shadow work; the supplied regressions exercise this order, but were not run in this read-only review. Is this the best way to solve the issue? Yes. Separating reusable provider results from atomic index publication fixes the owning lifecycle without another cache or schema, and the follow-up restores successful-rebuild retention enforcement. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 48b319e240fa. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
@clawsweeper re-review Addressed the successful all-cache-hit rebuild retention finding in b1d2cdc. The new SQLite regression failed with three cache rows at a cap of one, then passed after pruning the canonical cache only after successful publication. Failed-rebuild preservation remains covered. Also corrected the three CI chunk-publication tests to verify both intended contracts: published index tables roll back on failure, while completed embeddings remain cached and are reused without additional provider calls. All 71 focused tests, the complete changed-file gate, and final staged P0–P2 autoreview passed. The PR description now includes these results and existing-database/legacy-schema compatibility boundaries. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Related: #91354, #132708
What Problem This Solves
Fixes an issue where users retrying a failed memory-index rebuild would send successful embedding work to the provider again, even after a manager restart. On a large, quota-limited rebuild, discarding those completed results can repeatedly consume the same allowance without finishing the index.
The generic OpenAI-compatible embedding adapter also discarded structured HTTP status, quota, and retry metadata. Its errors could not fully participate in the bounded retry policy already landed in #134959.
Why This Change Was Made
Keep the published agent database as the canonical embedding-cache owner, separate from atomic shadow-index publication. Persist validated successful inline batches, successful split leaves, and completed per-file/source-wide runtime batches immediately. A later indexing failure can discard the incomplete shadow without discarding reusable embeddings. Remove the full-cache shadow seeding and cache replacement at publication.
Cache writes validate source snapshots and respect provider generations, database lifetime/revisions, workspace locking, and session tombstones. Reserve cache capacity before insertion, enforce the canonical cache cap after successful full rebuilds (including all-cache-hit rebuilds), and reject malformed vectors before retaining them. If separate requests disagree about vector dimensions, invalidate only the ambiguous provider identities so a subsequent retry can recover; retain other providers' caches and the published index. Reuse remains bounded by configured cache retention and compatible provider identity/content hashes.
A nonempty Forget selection now clears the selected agent's entire embedding cache, including unpublished rebuild results that cannot be selected through published chunk provenance. This is the accepted no-schema tradeoff: unrelated published index entries remain searchable, but future indexing may need to regenerate their cached embeddings. Dry runs report the whole-cache count without mutation; empty selections do neither.
The remaining generic adapter fix uses the existing shared HTTP-error owner and redacts reflected request credentials. This branch was rebased after #134959; it does not replace that PR's cooldown profiles, Google RetryInfo parsing, permanent-quota classification, or interactive search budget. The only retry-policy addition here is a completed-batch callback used by the cache owner.
User Impact
This is a partial repair for the linked reports, not a complete quota-management solution. It does not add shared cross-agent quota admission, persist or resume unfinished remote Batch jobs, add Batch support to another provider, explain every rebuild phase, or suppress legitimate upgrade-triggered rebuilds. No new configuration, database schema, or dependency is introduced.
Evidence
maxEntries: 1after a successful cache-only rebuild). Pruning after successful publication fixes it with zero provider requests; the failed-rebuild preservation control remains green.Changes walkthrough
extensions/memory-core/src/memory/manager-embedding-ops.tsextensions/memory-core/src/memory/manager-embedding-cache.tsextensions/memory-core/src/memory/manager-embedding-policy.tsextensions/memory-core/src/memory/manager-sync-ops.tsextensions/memory-core/src/memory/manager-sync-base.tsextensions/memory-core/src/memory/manager-db.tsextensions/memory-core/src/memory-forget.tssrc/plugins/openai-compatible-embedding-provider.tsextensions/memory-core/src/memory/manager.reindex-recovery.test.tsextensions/memory-core/src/memory/manager-memory-source-race.test.tsextensions/memory-core/src/memory/manager-embedding-cache.test.tsextensions/memory-core/src/memory/manager-embedding-policy.test.tsextensions/memory-core/src/memory/manager-chunk-writer.test.tsextensions/memory-core/src/memory/manager-db.test.tsextensions/memory-core/src/memory/manager-sync-yield.test.tsextensions/memory-core/src/memory-forget.test.tssrc/plugins/openai-compatible-embedding-provider.http-error.test.tsdocs/cli/memory.mddocs/concepts/memory-provenance.mdconfig/assertion-safety-baseline.txt