Skip to content

fix(serve): skip the redundant tail build_index on the adopt path - #359

Merged
flupkede merged 2 commits into
developfrom
fix/serve-no-double-hnsw-on-adopt
Oct 20, 2026
Merged

flupkede merged 2 commits into
developfrom
fix/serve-no-double-hnsw-on-adopt

Conversation

@flupkede

Copy link
Copy Markdown
Owner

Problem

Follow-up to #357, from its audit ledger (audit/audit.md, Design finding): on the POST /repos adoption path the add-repo task tail re-acquired a job permit and called build_index() again after perform_incremental_refresh_with_stores had already completed.

Why it is redundant on adopt

The incremental refresh already rebuilds the HNSW graph once after its last batch, under the same process-wide job gate (src/index/manager.rs, build the HNSW index once, after every batch has been inserted). When nothing changed it leaves the existing valid graph untouched. The tail build is load-bearing only on the force path — force_reindex_with_stores builds no HNSW internally.

Fix

Wrap the tail permit-acquire + build_index() in if !adopt_existing. The pre-restart_fsw liveness re-check stays on both paths; the cancellation-aware permit semantics on the force path are unchanged.

Tests

The adopt e2e (add_repo_handler_adopts_existing_index_instead_of_rebuilding) and the other add_repo_handler_* tests pass unchanged — the observable difference is work done, not resulting state, which is the equivalence this fix must preserve. clippy -D warnings and cargo fmt --check clean; pre-push QC gate green.

POST /repos adoption runs perform_incremental_refresh_with_stores, which
already rebuilds the HNSW once after its last batch under the job gate
(manager.rs), and leaves the existing valid graph untouched when nothing
changed. The add-repo task tail then re-acquired a permit and called
build_index() again - a second full graph build per adopted registration,
serialized behind the process-wide job gate, for an identical result.
That tail is load-bearing only on the force path (force_reindex builds no
HNSW internally), so it now runs only there.

Closes the Design finding from the PR #357 audit ledger (audit/audit.md).

No dedicated test: the observable difference is work done, not resulting
state - the adopt e2e (chunk/file survival) passes unchanged, which is
exactly the equivalence this fix must preserve.
@flupkede
flupkede merged commit 9ef2925 into develop Oct 20, 2026
7 checks passed
@flupkede
flupkede deleted the fix/serve-no-double-hnsw-on-adopt branch October 22, 2026 11:29
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.

1 participant