Skip to content

fix(memory): reject query embedding dimension drift - #168465

Merged
steipete merged 2 commits into
mainfrom
fix/w13-q2
Oct 10, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/w13-q2

Conversation

@steipete

Copy link
Copy Markdown
Contributor

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.ts then 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 (from eecaa9da0fb) 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 vectorDims before 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:

  • With a configured fallback provider, the existing fallback takes over.
  • Without one, recall reports that it is unavailable, gives the expected and actual dimensions, and names the rebuild command 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

  • New regressions (shorter and longer query vectors) fail on main and pass with the fix. The configured-fallback and restored-provider cases pass.
  • Stub-backed remote flows pass: empty, huge, Unicode and duplicate indexing; exact batch-limit boundaries and ordering; fallback ranking parity with the decoded path; trigger-skip diagnostics; model reindex; hard-crash recovery; and concurrent CLI writers.
  • 33 owner tests, 234 sibling tests, and all 39 pnpm test:changed tests pass.
  • node scripts/check-changed.mjs passes except for inherited main failures (environment-name budget and unused exports), which reproduce on the clean base.
  • Production +16/−6. The growth is the shared dimension validation; existing error routing is preserved.

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.
@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete marked this pull request as ready for review October 10, 2026 13:46
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: memory-core Extension: memory-core size: S labels Oct 10, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 10, 2026
@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This 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.

  • Before: Fallback vector scoring can return plausible matches from incompatible vectors.
  • After: Search reports the dimension mismatch and provides the agent-specific rebuild command.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Focused owner-boundary regressions support the approach, but runtime results are narrative and the fix leaves a supported path unprotected.
Proof confidence 🦐 gold shrimp (3/6) The task identifies this as maintainer-authored, outside the ordinary contributor proof gate; the body reports stub-backed runtime exercises, while inspectable regressions exercise the real manager with mocked embeddings.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: Memory search can return convincing but meaningless matches after an embedding provider changes dimensions.
Reason: The maintainer-authored direction has clear user value, but supported fallback-only indexes remain exposed.

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
Reviewed head: 953737e3fe3fce2564928d5fd3cc40e95b8a8fd0

Before merge

  • Validate drift when native vector dimension metadata is absent (P2) - The guard skips supported fallback-only indexes. With store.vector.enabled=false, ensureVectorReady returns false, and full rebuild metadata omits vectorDims because manager-sync-ops.ts records it only when native vector support is available. Indexing [1,0,9] and later receiving query [1,0] therefore bypasses this check and reaches createEmbeddingScorer, which returns similarity 1 using the shared prefix. Native-extension load failures produce the same omission. Obtain authoritative stored dimensions independently of sqlite-vec availability and add a regression using an existing index without vectorDims. This is the prior review's unresolved finding.

Findings

  • [P2] Validate drift when native vector dimension metadata is absent — extensions/memory-core/src/memory/manager-search-orchestration.ts:469-470

Tests

  • Missing end-to-end proof: No supplied shipped-entry-point output demonstrates dimension-drift rejection for an existing index built with sqlite-vec disabled or unavailable.
Agent review details

How this fits together

Memory 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]
Loading

Technical review

Best 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:

  • [P2] Validate drift when native vector dimension metadata is absent — extensions/memory-core/src/memory/manager-search-orchestration.ts:469-470
    The guard skips supported fallback-only indexes. With store.vector.enabled=false, ensureVectorReady returns false, and full rebuild metadata omits vectorDims because manager-sync-ops.ts records it only when native vector support is available. Indexing [1,0,9] and later receiving query [1,0] therefore bypasses this check and reaches createEmbeddingScorer, which returns similarity 1 using the shared prefix. Native-extension load failures produce the same omission. Obtain authoritative stored dimensions independently of sqlite-vec availability and add a regression using an existing index without vectorDims. This is the prior review's unresolved finding.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 1d76f57d4be5.

Provenance checked

  • Native-vector admission and retrieval changes intended behavior with a stated reason (f4a45a8: Offload retrieval SQL while preserving ranking and separating native vector capability from writer initialization.)
  • Provider execution and failure routing keeps the original intent (80e08db: Consolidate private provider execution while preserving cancellation, validation order, and existing behavior.)
  • Reindex cooldown regression keeps the original intent (eecaa9d: Back off failed full rebuilds while preserving published recall and queued session publication.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test extensions/memory-core/src/memory/manager-search-orchestration.test.ts --maxWorkers=1
  • pnpm test extensions/memory-core/src/memory/manager-search-vector.test.ts --maxWorkers=1
  • pnpm test extensions/memory-core/src/memory/manager-search-reindex-backoff.test.ts --maxWorkers=1
  • node scripts/check-changed.mjs
  • git diff --check

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit f4a45a8 adds extensions/memory-core/src/memory/manager-search-orchestration.ts:651 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: f4a45a81d798; files: extensions/memory-core/src/memory/manager-search-orchestration.ts)
  • Mehmet Yağız Maktav: Raw commit 70369e9 adds extensions/memory-core/src/memory/manager-search-orchestration.test.ts:127 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 70369e9be6d6; files: extensions/memory-core/src/memory/manager-search-orchestration.test.ts)
  • Mitchell Etzel: Raw commit 1cb9b5a adds extensions/memory-core/src/memory/manager-search-scorer.ts:16 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 1cb9b5aeac88; files: extensions/memory-core/src/memory/manager-search-scorer.ts)

PR surface

Source +10, Tests +46, Docs +5. Total +61 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 16 6 +10
Tests 2 46 0 +46
Docs 1 5 0 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 67 6 +61

Review metrics

Metric Value Why it matters
Production versus test changes Production +16/-6; tests +46/-0 The modest production growth centralizes dimension validation; tests cover rejection, provider recovery, configured fallback, and pending publication after cooldown.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Provider dimension drift can silently degrade memory relevance, with impact limited to affected indexes.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-10T13:51:31.505Z sha 953737e :: needs changes before merge. :: [P2] Validate dimension drift for indexes without native vector metadata

Reviewed October 10, 2026, 9:58 AM ET / 13:58 UTC (Revision 2).

@steipete
steipete merged commit 0a687e8 into main Oct 10, 2026
211 of 220 checks passed
@steipete
steipete deleted the fix/w13-q2 branch October 10, 2026 16:35
@steipete

Copy link
Copy Markdown
Contributor Author

Landed at the exact reviewed head 953737e3fe3fce2564928d5fd3cc40e95b8a8fd0 as 0a687e8.

The only red check on run 38056998400 was check-source-contracts. It failed in lint:tmp:session-accessor-boundary on src/auto-reply/reply/dispatch-from-config.test-support.ts, which reported 6 legacy session call sites. That file is not touched here. Main cleared those call sites in bc8c4d5, after this run, and the guard passes on current main.

Proof for this change:

  • Fresh Codex autoreview found nothing actionable at P2 ("patch is correct", 0.91).
  • The dimension-drift regressions fail on main and pass here.
  • 33 owner tests, 234 sibling tests, and all pnpm test:changed tests passed.
  • Stub-backed remote recall flows passed.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 11, 2026
* 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: memory-core Extension: memory-core P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant