import type { Check } from '../types.js'; /** * "A memory that exists and can never be recalled" canary for the vec-index * gap #250 fixed (migrations/041-vec-index-retry.sql). Production had 13 of * 18,863 active memories (0.069%) with a committed row but no * `memories_vec` entry — permanently invisible to vector search, with a * green write response every time. #250 added `memories.needs_vec_index` * as a durable REAL-zero/BROKEN-zero marker and a retry path (immediate * `reembed` enqueue on write-time failure + the `cleanup` job's 24h sweep, * see src/pipeline/handlers/cleanup.ts), but deliberately shipped NO doctor * reader — this is that reader. * * ADR-015 rule 6, applied literally: the denominator is * `COUNT(*) WHERE archived = 0` (active memories — archived rows are * excluded from recall by design and from migration 041's own backfill, so * they don't belong in this rate either); the numerator is * `COUNT(*) WHERE archived = 0 AND needs_vec_index = 1`. Both are reported * every run, not just on WARN — "0 of N (0.0%)" is itself the healthy * signal, not silence. * * REAL-zero vs BROKEN-zero (ADR-015 rule 1): a fresh `PRAGMA table_info` * check runs BEFORE the count query. Zero flagged rows on a DB that * predates migration 041 (the column doesn't exist at all) is a * completely different fact than zero flagged rows on a DB where the * column exists and every write has been clean — the two must not render * identically. The former returns `inconclusive: true`; only the latter is * a verified `ok: true`. * * Persistence, named honestly rather than faked: this check has NO way to * tell a row flagged ten minutes ago (normal — the write-time enqueue or * the 24h sweep hasn't reached it yet) from a row that has been stuck for * weeks (the retry path itself is broken — the actual failure this canary * exists to catch). `MemoryRepo.markNeedsVecIndex` does not stamp a * flagged-at time, and `updated_at` is only touched by the SUCCESS path * (`reembedHandler` bumps it when it clears the flag) — there is no column * this check can read to compute an age. * * That admission has a direct consequence for what `0 < orphanCount < * MEANINGFUL_USAGE_THRESHOLD` is allowed to return: NOT `ok: true`. * `src/doctor/types.ts`'s own contract reserves `ok: true` for "verified * healthy" — and this branch explicitly has not verified that; it has * verified the opposite, that it cannot tell in-flight from stuck. The * founding incident this canary exists to catch was 13 orphans out of * 18,863 — below any count-based floor this check could defensibly set — * so treating "few and unaged" as healthy would make this canary blind to * the exact failure that motivated it. `inconclusive: true` is the correct * state for "I looked, I found some, and I genuinely cannot tell you * whether that's fine" — visible to anything alarming on `inconclusive` * counts, without paging anyone on a single transient in-flight row (which * `ok: false` would). Only a floor-crossing count, which is implausible to * be pure simultaneous in-flight noise given the retry design's speed, * earns the harder `ok: false`. A future flagged-at column would let a * follow-up sharpen the small-count branch into a true age-based check — * see the doc comment on `checkAtomValidityExtraction` for the same kind of * denominator caveat named up front instead of hidden. */ export declare function checkVecIndex(dataDir: string, encryptionEnabled: boolean): Check;