Skip to content

codesearch index: incremental sync skips build_index on interrupted DB #93

@v1b3coder

Description

@v1b3coder

Problem

When codesearch index . is cancelled/interrupted mid-way (e.g. timeout during Phase 2), the HNSW vector index is never built — build_index() is intentionally skipped in the cancellation path.

On the next run, codesearch index . (incremental sync) checks file_meta, finds no changed files, and exits early with "Database is up to date!" — without ever calling build_index(). The database remains in a broken state and search fails with:

Error: Index not built. Call build_index() after inserting chunks.

Root cause

In src/index/mod.rs, the cancellation handler skips build_index():

// Handle cancellation: exit quickly without blocking on build_index
if cancelled {
    // Don't call build_index() — it blocks for 10-30 seconds on large datasets.
}

The incremental sync path (perform_incremental_refresh) only calls build_index() per-file during reindexing of changed files. If no files changed (they were already indexed before cancellation), build_index() is never called.

Compare: serve daemon handles this correctly

In src/serve/mod.rs, when opening an existing DB, the serve daemon checks vstore.stats().indexed and auto-calls build_index():

match vstore.stats() {
    Ok(s) if s.total_chunks > 0 && !s.indexed => {
        info!("Building vector index for ...");
        if let Err(e) = vstore.build_index() { ... }
    }
}

Suggested fix

Add the same check to the incremental sync path in codesearch index .: after processing file changes, check if the vector store has chunks but no index, and call build_index() if needed.

The StoreStats.indexed field already exists and is exposed via codesearch stats ("Indexed: ✅ Yes / ❌ No"). The CLI just needs to act on it.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions