Repository navigation
fix(memory): reject query embedding dimension drift - #168465
Conversation
Validate observed query dimensions before native or fallback retrieval. Preserve configured provider fallback and report an explicit reindex action instead of ranking unrelated vector spaces. Cover shorter and longer vectors plus recovery. Focused suites, stub-backed Gateway flows and changed-lane tests passed. Native checks retain independently reproduced baseline environment-count and unused-export failures; all remaining planned checks passed separately.
Append fresh transcript data while the failed full retry is deferred, then verify publication after the deadline. Unchanged chunks reuse embeddings, so an unchanged transcript cannot prove retry execution by counting provider calls. Keep the one-call and cooldown assertions and verify the pending content is indexed.
|
🦞👀 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 changes before merge. What this changesThis PR validates query embedding dimensions before retrieval and repairs a reindex-backoff test fixture. Example: An explicit embedding provider returns a 2-dimensional query against an index recording 4 dimensions.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Partial Merge readiness⛔ Needs changes before merge - 1 item remains Keep open: this PR addresses a real memory-search defect, but the prior finding remains unresolved for indexes built without native vector support. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherMemory Core receives search text, obtains provider embeddings, retrieves candidates from a published SQLite index through native KNN or worker fallback scoring, and returns ranked memory matches. flowchart TD
A[Memory search request] --> B[Published index facts]
B --> C[Query embedding provider]
C --> D[Dimension validation]
D --> E[Native or fallback retrieval]
D --> F[Provider failure routing]
E --> G[Ranked memory matches]
Technical reviewBest possible solution: Validate queries against authoritative stored embedding dimensions independently of sqlite-vec availability, including existing indexes without vectorDims. Do we have a high-confidence way to reproduce the issue? Source establishes a concrete reproduction: build with store.vector.enabled=false, change query dimensions under the same provider identity, and search; absent vectorDims bypasses validation and prefix scoring produces ordinary matches. Is this the best way to solve the issue? The shared query boundary is the right validation owner, but native-vector metadata alone cannot establish dimensional compatibility for all supported indexes. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 1d76f57d4be5. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +10, Tests +46, Docs +5. Total +61 across 4 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes: No label 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 HistoryReview history (1 earlier review cycle)
Reviewed October 10, 2026, 9:58 AM ET / 13:58 UTC (Revision 2). |
|
Landed at the exact reviewed head The only red check on run 38056998400 was Proof for this change:
|
* fix(memory): reject query embedding dimension drift Validate observed query dimensions before native or fallback retrieval. Preserve configured provider fallback and report an explicit reindex action instead of ranking unrelated vector spaces. Cover shorter and longer vectors plus recovery. Focused suites, stub-backed Gateway flows and changed-lane tests passed. Native checks retain independently reproduced baseline environment-count and unused-export failures; all remaining planned checks passed separately. * test(memory): exercise pending work after reindex cooldown Append fresh transcript data while the failed full retry is deferred, then verify publication after the deadline. Unchanged chunks reuse embeddings, so an unchanged transcript cannot prove retry execution by counting provider calls. Keep the one-call and cooldown assertions and verify the pending content is indexed.
What Problem This Solves
Memory recall could silently return wrong results after an embedding provider's dimension count changed. Two typical triggers are a provider swapping the model behind the same name, and a provider that truncates. Dimensions were checked only when choosing native KNN. The fallback vector scorer in
extensions/memory-core/src/memory/manager-search-orchestration.tsthen compared the new query vector against differently sized stored vectors and returned normal-looking hits.Reproduced with a stub embedding server: index at three dimensions, switch the stub to two, then search. On main this returned 20 ordinary hits with no warning. The scorer path came in with
f4a45a81d79.Separately,
manager-search-reindex-backoff.test.ts(fromeecaa9da0fb) fails on main. It expected a new embedding call for unchanged content, but chunk reuse correctly skips that call.Why This Change Was Made
The query path now validates the query embedding's length against the index's recorded
vectorDimsbefore any vector scoring. The KNN-only check is removed in favor of this single owner check.A mismatch is raised through the existing memory embedding operation error, so it goes through the same routing as other provider failures:
openclaw memory index --force --agent <id>.The backoff test now appends genuinely pending content and keeps its zero-before/one-after embedding-call assertions. It also checks that the content is published after the cooldown.
User Impact
After an embedding model or dimension change, memory search fails visibly with a fix instead of returning plausible but meaningless matches.
Evidence
pnpm test:changedtests pass.node scripts/check-changed.mjspasses except for inherited main failures (environment-name budget and unused exports), which reproduce on the clean base.