Commit bbb6bde
fix(embed): clear embedding on content change — lag means absent not stale; drain queue on shutdown (#418)
The reviewer demonstrated (cap=1 + 400ms fake backend) that a
content-changing UPDATE whose deferred embed job was dropped on queue
overflow kept the PREVIOUS body's embedding: non-NULL, so mimir_embed
batch repair (WHERE embedding IS NULL) never touched it and dense search
served the wrong vector permanently. Even without overflow, the update-lag
window served the old body's vector.
Fix: the content_changed stamp UPDATE in remember's update path now also
sets embedding = NULL, emb_sig = NULL — same transaction that rewrites the
FTS row. Lag/drop now means ABSENT (row out of dense search, keyword still
finds it) instead of STALE, and every dropped job is genuinely
NULL-scan-recoverable, making the documented overflow contract true.
Cleared regardless of backend config: a vector for a body the row no
longer has is wrong in any configuration. Identical re-asserts (gated on
content_changed) still keep their vector.
Also, per review suggestions:
- Shutdown now DRAINS queued jobs instead of skipping them (bounded by the
existing 5s Drop grace, detached past it): CLI one-shot writes get their
embeddings as they did synchronously pre-#393; the shutdown-skip flag is
gone.
- debug_assert against pending-counter underflow at both decrement sites
(saturating_sub no longer masks accounting drift in debug/test builds).
- Overflow warning, code comments, and CHANGELOG updated so every claim
matches the fixed behavior.
Regression test overflow_dropped_update_clears_stale_vector_and_batch_repairs_it
(deterministic via a fake-server accept counter — no sleeps for the
worker-busy window): update under overflow-drop -> embedding is NULL, then
batch embed_entity repairs it with the CURRENT body's vector. Pre-fix
proof at the previous head: FAILED with "a dropped update job must leave
the embedding ABSENT (NULL), not body A's stale vector".
Full default suite 282 passed / 0 failed; lite (--no-default-features)
275 passed / 0 failed.
Co-authored-by: tcconnally <hermes@perseus.observer>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>1 parent 6a940e4 commit bbb6bde
2 files changed
Lines changed: 226 additions & 96 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
33 | 38 | | |
34 | 39 | | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
39 | 59 | | |
40 | 60 | | |
41 | 61 | | |
| |||
107 | 127 | | |
108 | 128 | | |
109 | 129 | | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | 130 | | |
125 | 131 | | |
126 | 132 | | |
| |||
0 commit comments