Skip to content

fix(core): verify dedup candidates are live before skipping insert (#1210) - #1211

Merged
ajianaz merged 1 commit into
developfrom
fix/dedup-deprecated-check-1210
Sep 9, 2026
Merged

ajianaz merged 1 commit into
developfrom
fix/dedup-deprecated-check-1210

Conversation

@ajianaz

@ajianaz ajianaz commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

What

check_duplicate() (the #442 semantic dedup, cosine ≥ 0.95) now verifies each candidate hit against SQLite before returning it: candidates whose row is missing (hard-deleted) or soft-deleted (deprecated = 1) are skipped, and dedup falls through to a normal insert. A store read error also skips the candidate — dedup never fires on an unreliable read.

Adds one regression test (test_dedup_skips_deprecated_stale_index_entry, ONNX-ignored per repo convention for embedder-dependent tests) that poisons the vector index with a deprecated row's embedding — simulating the index↔SQLite desync observed on a long-running server — and asserts the rewrite produces a fresh live row instead of the deprecated ghost id.

Why

Fixes the production incident in #1210: on a long-running server whose vector index went stale relative to SQLite, remember() with near-identical content "succeeded" while writing zero new rows — it returned the deprecated row's id, and remember_in_room() then linked rooms to an invisible ghost row. Four write attempts in production all reported success and stored nothing.

Root cause: check_duplicate() filtered dedup candidates only by namespace — no deprecated = 0 predicate, unlike every recall query in the codebase. A stale index entry for a soft-deleted row therefore still satisfied dedup. The verification happens at the point of acceptance (not in the namespace id-set query) so it also covers callers that dedup without a namespace filter.

Fixing at this layer protects both call sites (remember() and the import pipeline) and keeps behavior conservative: soft-deleted means forgotten, so a rewrite legitimately creates a new memory.

Testing

  • New regression test proven red→green: fails on unfixed code with exactly the production symptom (assert_ne! on ghost id, exit 101), passes with the fix.
  • cargo test -p uteke-core --lib dedup -- --include-ignored: 12/12 pass (11 pre-existing dedup tests unchanged + the new one).
  • cargo test -p uteke-core --lib (full suite, default profile): green — 560 passed, 0 failed, 33 ignored.
  • cargo clippy -p uteke-core --all-targets: zero warnings. cargo fmt --check: clean.
  • Manual E2E on an isolated store (UTEKE_HOME=/tmp/..., never prod): remember → forget → remember with identical content creates a second live row; the deprecated row stays deprecated=1 (verified via read-only SQLite), matching the unit test at the CLI level.

Addresses #1210 (the issue stays open for post-merge validation before closing).

…1210)

check_duplicate() filtered candidates by namespace only, so a stale
vector-index entry for a soft-deleted (deprecated) row could satisfy
dedup: remember() returned the deprecated id, wrote nothing, and
remember_in_room() linked rooms to the invisible ghost row.

Now every candidate above the threshold is verified against SQLite:
missing or deprecated rows are skipped (fall through to insert), and a
store read error also skips the candidate. The regression test poisons
the index with a deprecated row's vector and asserts the rewrite
creates a fresh live row.

Addresses #1210.
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit 5300c88 into develop Sep 9, 2026
16 checks passed
@ajianaz
ajianaz deleted the fix/dedup-deprecated-check-1210 branch September 9, 2026 04:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant