#996·qmd

embed: a failed vector insert leaves a content_vectors row that is never re-embedded

Author: ParkerRexCreated Sep 26, 2026Updated Sep 26, 2026

Impact

If the vectors_vec insert fails during qmd embed, the chunk keeps its content_vectors row but has no vector. The pending-work query counts only content_vectors, so later qmd embed runs never pick that document up again. The chunk stays missing from vector search until qmd embed -f.

Repro on main @ 04e4dbd

typescript
const store = createStore(tmpPath);
store.ensureVecTable(3);
store.insertEmbedding("abc", 0, 0, new Float32Array([1, 2, 3, 4]), "m", new Date().toISOString());
// throws "Dimension mismatch ..."
store.db.prepare("SELECT COUNT(*) AS n FROM content_vectors").get(); // { n: 1 }
store.db.prepare("SELECT COUNT(*) AS n FROM vectors_vec").get();     // { n: 0 }

Cause

insertEmbedding (src/store.ts:4498-4522) runs three autocommit statements: INSERT OR REPLACE INTO content_vectors, then DELETE FROM vectors_vec, then INSERT INTO vectors_vec. The first commits before the vector write is tried. The ordering was chosen in #445 so a crash between statements would not re-select the hash; that is also what makes the gap permanent. removeIncompleteEmbeddings only catches hashes with fewer chunk rows than expected, so it does not see this.

To be honest about scope: the crash window between two statements is tiny. The realistic triggers are a failed vector insert (dimension mismatch, SQLITE_FULL, I/O error), which the embed loop catches and records as a chunk failure while the bookkeeping row stays behind.

Suggested fix

Run the three statements in one db.transaction(...), inside the existing withLazyContentVectorMigration wrapper so a column-repair retry still works. Keep DELETE + INSERT for vec0 (#598). Side effect: one WAL commit per chunk instead of three.

A PR with a test follows.