|
| 1 | +# Repair discovery and writer occupancy |
| 2 | + |
| 3 | +This incremental change depends on the reliability candidate at |
| 4 | +`31da32c06a5ade989608504472e00dfca6f13f94` (PR #203). It changes candidate |
| 5 | +discovery for separate vector indexes. Public entrypoints, repair return fields, |
| 6 | +ranking defaults, schema 18, and transaction-sharing native indexes are unchanged. |
| 7 | + |
| 8 | +## Reproduced problem and acceptance |
| 9 | + |
| 10 | +Repair prioritizes erasure/quarantine cleanup before vector updates. Previously, |
| 11 | +finding one erasure behind 1,000 queued updates acquired SQLite's writer 1,002 |
| 12 | +times: registration, 1,000 skipped updates, and one deletion. An independent |
| 13 | +connection could not finish a write while classification held that reservation. |
| 14 | + |
| 15 | +Discovery now reads 100-row pages containing IDs, generation, canonical existence, |
| 16 | +and provenance/metadata. It avoids memory text and vector payloads. Canonical JSON |
| 17 | +decoding and quarantine rules remain shared with the store. Each page is fetched |
| 18 | +before yielding; no read transaction or reader lease spans publication. The keyset |
| 19 | +advances past the last scanned row even if the page yields no matching candidate. |
| 20 | +The store's canonical workspace predicate applies to the memory join, with temporal |
| 21 | +filtering disabled. Out-of-binding and missing records remain cleanup candidates; |
| 22 | +allowed historical records remain indexable. This matches publication's `get_memory` |
| 23 | +view without exposing another workspace's metadata during discovery. |
| 24 | + |
| 25 | +Classification is a hint. Publication still reserves the writer, verifies the |
| 26 | +selected generation, rereads current canonical existence, eligibility and vector |
| 27 | +identity, applies the provider operation, and acknowledges only that generation. |
| 28 | +Stale hints leave recoverable debt. Once the provider-attempt budget is spent, |
| 29 | +iteration stops before requesting another filtered candidate, including after a |
| 30 | +failed deletion. Otherwise the iterator could scan an irrelevant tail after the |
| 31 | +last permitted attempt. |
| 32 | + |
| 33 | +`tests/test_vector_repair_discovery.py` exercises real sync/store sequences for: |
| 34 | + |
| 35 | +- Erasure and quarantine after 105 and 1,000 queued updates; one deletion needs at |
| 36 | + most two writer reservations, independent of the stable update backlog. |
| 37 | +- An independent writer completing while discovery is deliberately paused. |
| 38 | +- Erasure, same-generation quarantine, vector replacement and restoration between |
| 39 | + discovery and publication, without stale publication or lost repair debt. |
| 40 | +- Canonical decoding of malformed and legacy metadata/provenance. |
| 41 | +- Workspace-bound cleanup, multiple allowed workspaces and retained historical |
| 42 | + canonical records; external cleanup does not erase the canonical memory. |
| 43 | +- Early cleanup, both successful and failing, without scanning newer updates after |
| 44 | + the provider budget is exhausted. |
| 45 | + |
| 46 | +Existing sync and storage tests retain coverage of delayed publication, newer |
| 47 | +generations during provider callbacks, process/restart recovery and native rollback. |
| 48 | + |
| 49 | +## Reproducible measurement |
| 50 | + |
| 51 | +Run the repair-only probe from the checkout being measured: |
| 52 | + |
| 53 | +```sh |
| 54 | +python -m eval.repair_discovery --backlog 1000 --repetition 1 --output repair-1000-1.json |
| 55 | +python -m eval.repair_discovery --backlog 10000 --repetition 1 --output repair-10000-1.json |
| 56 | +``` |
| 57 | + |
| 58 | +For a baseline that predates the driver, run the same driver file with `runpy` from |
| 59 | +the baseline checkout. The imported Engraphis package identifies the measured |
| 60 | +source; every report records that source's revision and file hashes independently |
| 61 | +of the driver hash. Use the same Python/dependencies, machine, storage location and |
| 62 | +driver for both sources. Alternate their order across five independent process |
| 63 | +repetitions per backlog. Retain every raw result, including failures. |
| 64 | +The CLI records failure type and attempted configuration with source/driver identity |
| 65 | +and exits nonzero if setup, repair or verification fails; failed work has no success |
| 66 | +measurement. An unwritable output location or forced process termination requires |
| 67 | +the invoking runner to retain its own exit-status/log record. |
| 68 | + |
| 69 | +The synthetic dataset has fixed 32-dimensional vectors and one erasure after the |
| 70 | +declared update backlog. Bulk setup uses canonical store APIs and queue triggers |
| 71 | +on a disposable file-backed SQLite database. Setup is excluded from timing. The |
| 72 | +measured invocation includes discovery, writer acquisition, synchronous fixture |
| 73 | +publication and pending counts. Writer timing includes commit/release overhead; |
| 74 | +nested acknowledgement does not acquire or count a second reservation. The same |
| 75 | +timing instrumentation applies to both sources. |
| 76 | + |
| 77 | +The adapter makes no network calls. No embedding, recall, tokenizer or answer |
| 78 | +generation is measured. This probe does not establish the 100k operating target, |
| 79 | +mixed-workload contention, semantic quality or a provider latency guarantee. The |
| 80 | +complete-engine protocol and hardware gates remain in |
| 81 | +[ENGINE_CAPACITY_PROTOCOL.md](ENGINE_CAPACITY_PROTOCOL.md). |
| 82 | + |
| 83 | +## Compatibility, backout and next dependencies |
| 84 | + |
| 85 | +There is no new migration, policy, service or default. Backout restores the previous |
| 86 | +discovery implementation while retaining the canonical database, durable queue and |
| 87 | +generation checks. Never delete pending repair work to recover availability. |
| 88 | + |
| 89 | +The following remain separate work: |
| 90 | + |
| 91 | +1. Discovery can scan the whole queue, and repeated calls can repeat that scan. |
| 92 | + Pages bound row count, not metadata bytes or total time. Pending counts also |
| 93 | + traverse the queue. Measure these costs before adding indexed scheduling state. |
| 94 | +2. A permanently failing oldest deletion can consume repeated small attempt |
| 95 | + budgets. Durable fairness/backoff and coordination must preserve cleanup priority |
| 96 | + without acknowledging unapplied work or fabricating canonical generations. |
| 97 | +3. Provider calls still occupy the writer. Moving an arbitrary provider outside it |
| 98 | + lets a delayed old upsert recreate an erased vector, even if acknowledgement is |
| 99 | + rejected. Hard deadlines need an adapter-level cancellation/fencing contract; |
| 100 | + current tests do not prove remote completion safety after a process dies. |
| 101 | +4. Legacy resource imports still perform filesystem/extraction/embedding preparation |
| 102 | + inside a service writer boundary. A prepared batch must preserve whole-batch |
| 103 | + rollback, per-file outcomes, provenance, and caller-owned transactions before |
| 104 | + replacing that path. Removing its transaction decorator alone is insufficient. |
| 105 | + |
| 106 | +An optional background repair worker must coordinate ownership and shut down its |
| 107 | +own connections cleanly. The dependency-light offline library continues to work |
| 108 | +without one. This change does not introduce background scheduling. |
0 commit comments