Skip to content

refactor(core): save the index rebuilt at open through index_sync - #1809

Merged
ajianaz merged 1 commit into
developfrom
refactor/index-sync-open-time-persist-1758
Nov 26, 2026
Merged

ajianaz merged 1 commit into
developfrom
refactor/index-sync-open-time-persist-1758

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

What

The index that is rebuilt from SQLite at open is now saved through index_sync::persist_rebuilt instead of index.save().ok(): the standard bounded retry, a warning when it still fails, and the open is not failed.

Why

#1758 lists four places that still "lock the index directly" although index_sync is meant to be the one place for the persist and retry policy. Audit of the four, against develop:

  • consolidate.rs:161 (remove_ids), operations/write.rs:493 (upsert) and lib.rs:830 (remove_from_index, remove_ids) already call index_sync. What they do themselves is take the write lock, which the module header says its caller holds (&mut impl IndexWriter), the same as every other caller. Nothing to route there, so nothing changes.
  • lib.rs:1151 is the real exception: the open-time migration (SQLite has vectors, the index file is empty or gone) called index.save().ok(). One attempt, the error dropped. This PR fixes that one.

Behaviour change, small and only on failure: a failing save is retried up to the standard 3 attempts (200 ms apart) and logs a warning, where it used to be dropped silently. A save that works behaves as before. If it still fails the open succeeds, as before: SQLite holds every vector and the next open rebuilds the index.

How

index_sync::persist_rebuilt(&mut impl IndexWriter, &SyncPolicy) -> bool wraps persist and logs instead of returning the error. finish_open_full calls it after index.build(...).

Not changed on purpose: the three lock-poison policies of the other sites differ (consolidate.rs returns an error, write.rs reports it in the outcome, remove_from_index returns silently). Unifying them is a behaviour change and is left for a decision of its own.

Testing

  • cargo test --workspace passes
  • cargo fmt --all -- --check passes
  • cargo clippy --workspace --all-targets -- -D warnings passes
  • Cora review run locally (cora review --base origin/develop)
  • Manual smoke-test of the affected feature

The index open path is feature-dependent, so it was also run on the other backends: cargo check -p uteke-core --no-default-features --features vecq, cargo test -p uteke-core --features "usearch,vecq" --lib vector_engine, and the new store test with --no-default-features --features "onnx,vecq".

New tests:

  • persist_rebuilt_saves_once_when_the_save_works, persist_rebuilt_retries_a_transient_save_failure and persist_rebuilt_gives_up_after_the_policy_attempts_without_failing, on the existing FakeIndex (the failing-writer adapter the issue asks for).
  • a_missing_index_file_is_rebuilt_and_saved_at_open: a store whose index file is deleted gets it back with the rebuilt entry at open, before any shutdown. The file is created empty when the index is built, so the test compares sizes (0 against 3328 bytes). Checked red with the persist_rebuilt call disabled, green with it.

Mutation gate on the diff (owner rule 2026-08-19), cargo mutants -p uteke-core --in-diff: 3 mutants, 2 caught, 1 unviable (does not compile), 0 missed.

Related Issues

Closes #1758

Checklist

  • Branch name follows convention (fix/, feat/, docs/, chore/, refactor/, test/, perf/, security/)
  • Branch is from develop
  • Commit messages follow Conventional Commits
  • No secrets or credentials committed
  • One logical change per PR (no mixed concerns)

)

The open-time migration (SQLite has vectors, the index file is empty or gone)
saved the rebuilt index with `index.save().ok()`: one attempt, the error
dropped. It now goes through `index_sync::persist_rebuilt`: the standard
bounded retry, a warning when it still fails, and the open itself is not
failed (SQLite holds every vector, the next open rebuilds again).

The other three sites named in #1758 already call index_sync (remove_ids and
upsert); what they do themselves is take the write lock the module expects its
caller to hold, so nothing changes there.

Tests: persist_rebuilt saves once, retries a transient failure and gives up
after the policy's attempts without failing (FakeIndex), and a store whose
index file is gone gets the rebuilt entry written at open, before shutdown.
@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit 34f5bfe into develop Nov 26, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(core): route the four remaining direct index locks through index_sync

1 participant