Skip to content

Add explicit backed-up embedding index rebuild - #119

Open
blast-hardcheese wants to merge 7 commits into
mainfrom
feat/explicit-embedding-rebuild
Open

blast-hardcheese wants to merge 7 commits into
mainfrom
feat/explicit-embedding-rebuild

Conversation

@blast-hardcheese

@blast-hardcheese blast-hardcheese commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to Preserve embedding indexes and report coverage health, released in 0.54.2. Based on main 528566c; no version bump or release.

Adds kin embed rebuild for deliberate replacement of all derived vectors using the configured identity. Preview includes the selected database, stored/target fingerprints, eligible count and estimated tokens/cost. Confirmation defaults to no; unattended runs require --yes. Credential/backend checks and an approved paid readiness probe precede destruction. Provider defaults and user configuration are unchanged; ordinary indexing/search still refuse incompatible identities and recommend restoring matching configuration first. All clients of a shared graph must resolve the same identity after rebuilding.

A validated whole-database SQLite backup is mandatory and reported before reset. Each rebuild retains its copy outside normal snapshot rotation until the operator manually deletes it. The writer lock and SQLite reservation protect backup/reset. Pause writing clients during approval/preflight, including access-time writes. Reset atomically replaces derived vectors, checkpoints and the queue, invalidating only the target model's active grounding calibration. Nodes, edges, FTS, history, other calibrations and calibration history remain intact. Semantic search is interrupted; this is not an atomic index switchover.

Rebuild stages the full selected set without the ordinary enqueue cap and uses the existing drain lifecycle. Matching quarantine survives; new terminal input rejections remain tracked; transient failures remain queued. Successful vectors/checkpoints survive failures.

Rebuild result Exit Contract
ok 0 Selected work completed; late arrivals can remain queued with a resume hint
completed_with_quarantine 0 Reset committed, queue empty, and only quarantined inputs remain unembedded; inspect kin embed status, do not re-run rebuild for this
failed, persistence_error, unavailable, refused, cancelled 1 Selected work remains pending/deferred, transiently failed, is unknown, or was not authorized

completed_with_quarantine is Devon's explicit exit-code decision for both pre-existing and newly diagnosed quarantine. JSON retains quarantined, coverage_complete, queue_pending and failed-attempt counts; incomplete coverage is not operation failure in this state. The text plainly reports that the index was replaced and how many quarantined inputs were not embedded. Failed-attempt count can be positive for newly quarantined inputs even with exit0.

After a committed reset, interruption prints the backup, readable pending count and recovery command to stderr, then re-raises. Pre-reset interrupts give no resume advice. Recovery uses kin embed drain --max-jobs N --time-budget inf with N equal to the pending queue size, including already-fresh entries, so the backlog can be visited in one pass. If the count is unknown, inspect status first; the command uses a deliberately large sys.maxsize job bound. Use the same graph/config selection. Do not repeat rebuild to resume. New arrivals after a queue snapshot may require another drain. README covers restoration and its effect on later graph edits.

Verbose rebuilds report visited-entry/embedded counts during the pass on stderr, including with --json; normal-return JSON stdout stays one document. Ordinary drain output and fresh-entry job-cap accounting are unchanged. Public vector interfaces provide locking, validation, planning, probing, queue snapshots/staging and optional progress notification; snapshots exposes its root. Existing private lock/root names remain compatibility aliases.

Known follow-ups (not implemented here):

  • Approval is conservative: any write, including access touches, invalidates approval, potentially after a charged probe. Narrowing it to database/stored/target identity needs separate review.
  • Already-fresh queued entries still consume drain's max_jobs; change that accounting separately. Current recovery guidance sizes the cap to the full queue.
  • Keep queue primitives in vectors.py and approval/backup/reset/completion orchestration in embedding_rebuild.py. A cleaner module/typed-interface seam is a future refactor, not a vectors.py restructuring here.
  • Rebuild-backup rotation controls remain deferred; copies require manual deletion.

Validation at 70b9bce0899e852a09ef71154c52a71a03eb4ee7:

  • 4,994 passed, 4 skipped, 286 subtests passed (Python3.13.15 / Node24.21.0).
  • 36 rebuild CLI + 27 health cases passed separately using real temporary SQLite and fake providers. Covers existing/new quarantine in text and JSON, mixed transient failures, the 12-node seventh-request interrupt with six retained vectors and one-pass/no-repayment recovery, pre-reset interrupts, intermediate verbose stderr progress, JSON purity, late arrivals, Voyage contextual fingerprints, rollback, credentials, backup and calibration safety. New regressions were authored inline; original19 were independently authored. Sim critiques are advisory, not Jeremy's human approval.
  • Policy and git diff --check passed. Current common-footguns taxonomy reverified; affected completion/cancellation/durability/output boundaries reviewed. Existing knowledge records preserved.
  • Hosted test passed on this head (run); Proof was skipped; covering post-fix Adapt validation has not been posted. Human review remains required; readiness is not claimed.
  • Historical inline threads are resolved. Prior Adapt summary fixes have commit-specific replies. No merge/release, user config changes, live reindex or child agents.

Diff against main: 10 files, 1,279 additions / 19 deletions. Latest repair: 5 files, +263/-26. Head: 70b9bce0899e852a09ef71154c52a71a03eb4ee7.

Base automatically changed from fix/preserve-embedding-index-and-report-coverage to main November 13, 2026 03:23
@blast-hardcheese
blast-hardcheese force-pushed the feat/explicit-embedding-rebuild branch from 2b1c45d to 59afdf5 Compare November 13, 2026 19:12
@blast-hardcheese
blast-hardcheese marked this pull request as ready for review November 13, 2026 19:20

@adaptcom adaptcom Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confidence Score: 4/5

Summary

Adds explicitly confirmed, backed-up kin embed rebuild with fail-closed preflight, transactional reset and drain-based resume. Deferred-with-pending now fails and unknown-queue storage faults keep recovery guidance; 55 rebuild/health and 232 related tests pass locally.

Important Files Changed

File Overview
src/kindex/embedding_rebuild.py Rebuild flow; deferred+pending now failed, unknown-pending failures get resume and message
src/kindex/vectors.py Public rebuild interfaces: validate, plan, probe, stage queue; lock alias
src/kindex/cli.py embed rebuild subcommand, confirm prompt, output, cancelled exits 1
src/kindex/snapshots.py Public default_state_root; keep accepts None
src/kindex/embedding_health.py Mismatch guidance now points to kin embed rebuild
tests/test_embedding_rebuild.py 28 CLI cases incl. deferred-edit exit and storage-fault recovery
tests/test_kindex_embedding_health.py Updated doctor message assertions
README.md Rebuild procedure, quiescence requirement, restore guidance
CHANGELOG.md Unreleased Added entry
.kin/knowledge.json Two concept records for calibration invalidation and JSON output

Findings

  • src/kindex/embedding_rebuild.py:110 — Deferred-to-failed sets no message, so text output reads "failed; 1 embedded, 0 failed" with no reason; add a message with deferred_reason and pending count.

Reviewed 528566c...bd8e384 · ↻ Re-run review · View in Adapt

Comment thread src/kindex/embedding_rebuild.py Resolved
Comment thread src/kindex/embedding_rebuild.py Resolved
Comment thread src/kindex/embedding_rebuild.py Resolved
Comment thread src/kindex/cli.py Resolved
@blast-hardcheese

Copy link
Copy Markdown
Collaborator Author

Addressed both new findings in the updated Adapt review, published in bd8e384c4b118771d7fe55b32e4f82ca5809d6b5.

  • Deferred work exits 0: verified with a real second-connection node edit during the fake provider request. Rebuild now maps deferred with pending work to failed, retains deferred_reason and the queue, and exits 1. The CLI regression then drains only the remaining node and reaches complete coverage.
  • Unknown pending count loses recovery guidance: verified by a SQLite authorizer fault in the real drain, producing its outer persistence_error / pending=None result after reset committed. Rebuild now distinguishes unknown from known zero: it reports the backup and kin embed drain, and tells the operator to inspect kin embed status before resuming. The test verifies the durable backup/queue and successful recovery once the storage fault is removed.

Known-empty completed/rolled-back and quarantine-only cases still receive no misleading resume hint. Ordinary drain/reindex behavior is unchanged.

Validation: 4,986 passed, 4 skipped, 286 subtests passed; separately 28 rebuild + 27 embedding-health cases passed. git diff --check and project policy check passed. Hosted validation is running on the published head.

@blast-hardcheese

Copy link
Copy Markdown
Collaborator Author

Verified and addressed the latest deferred-message finding in the updated Adapt review, published as 945ac381e40074d729c874fcab8a07dcb636b483.

The human-readable result now explains Embedding work deferred: input_changed; pending nodes: 1. rather than leaving “failed; 1 embedded, 0 failed” unexplained. JSON receives the same message alongside the existing reason/count fields. Quarantine guidance is appended when applicable, preserving both diagnostics. Status, attempt counts and queued work are unchanged.

The real concurrent-edit CLI regression failed before the fix in both text and JSON modes and now passes in both, including successful later drain. Validation: 29 rebuild + 27 health cases passed; full suite 4,987 passed, 4 skipped, 286 subtests passed; git diff --check and policy check passed. Hosted validation is running on the new head.

@blast-hardcheese

Copy link
Copy Markdown
Collaborator Author

Published the three fresh independent-audit fixes in 70b9bce0899e852a09ef71154c52a71a03eb4ee7:

  1. Quarantine-only completion: per Devon's explicit decision, a committed replacement with an empty queue and only quarantined inputs left now returns completed_with_quarantine / exit0. Text says the index was replaced, gives the unembedded quarantine count, points to status and says not to re-run rebuild. JSON retains quarantine, coverage and attempt counts. Both existing and newly created quarantine pass in text/JSON; mixed transient failure still exits1. Late-arrival behavior remains as explicitly checked by the audit.
  2. Interrupt recovery: a real 12-node/seventh-document KeyboardInterrupt repro now prints committed-reset/backup/pending/full-backlog resume guidance and re-raises. Six vectors survive; the printed count-sized --max-jobs 12 --time-budget inf command finishes the other six in one pass with no repayment for fresh vectors. Pre-reset probe/backup interrupts preserve the index and give no resume hint. JSON/text resume values use full-backlog flags; unknown counts use a large job bound and status inspection. Fresh entries consuming drain's cap remains a documented follow-up.
  3. Verbose progress: rebuild now reports visited/embedded counts during the pass on stderr, including JSON mode. A provider-time observation verifies progress exists before completion while stdout remains a single JSON document. Ordinary drain output is unchanged.

All three findings were verified before changing implementation; none declined. 36 rebuild + 27 health cases passed; full suite 4,994 passed, 4 skipped, 286 subtests passed. README and PR body document the result/exit contract and follow-ups. Hosted validation is running. Sim remains advisory, not Jeremy's human approval. No merge or release.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant