Repository navigation
fix(core): verify dedup candidates are live before skipping insert (#1210) - #1211
Merged
Merged
Conversation
…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.
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, andremember_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 — nodeprecated = 0predicate, 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
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.UTEKE_HOME=/tmp/..., never prod):remember → forget → rememberwith identical content creates a second live row; the deprecated row staysdeprecated=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).