Skip to content

feat(index): require --replace to overwrite a usable index - #318

Merged
lemon07r merged 2 commits into
masterfrom
feat/index-replace
Nov 18, 2026
Merged

lemon07r merged 2 commits into
masterfrom
feat/index-replace

Conversation

@lemon07r

@lemon07r lemon07r commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Prevents vera index from accidentally overwriting an existing usable index unless --replace is passed.

Summary

  • Add --replace to vera index and refuse to overwrite an existing usable index by default, pointing users to vera update for incremental refreshes and --replace for full rebuilds.
  • Check replaceability in vera_core::indexing::usable_index_exists / ensure_replaceable before CLI provider setup (and again under IndexLock in pipeline.rs), recovering any pending .vera.old directory first during preflight so vera update and search prompts continue to work.
  • Keep rebuilds automatic without --replace for stray .vera/ directories, corrupt/missing metadata.db or Tantivy bm25/ state, interrupted updates (index_complete = "0"), old format versions, and retired character-cap chunking configs.
  • Preserve overwrite behavior for --dry-run, vera setup / vera setup --index, and internal callers (vera-mcp, vera-eval), and adjust failed API --replace checkpoint hints to suggest vera index --replace when a usable index still exists on disk.
  • Update docs/ and skills/vera/SKILL.md, and add unit and CLI integration tests.

Verification

  • cargo fmt --all -- --check
  • cargo clippy --locked --workspace --all-targets -- -D warnings
  • cargo test --locked --workspace (1,770 passed, 0 failed, 63 ignored)
  • RUSTDOCFLAGS="-D warnings" cargo doc --locked --workspace --no-deps
  • cargo deny --locked check, cargo machete, cargo audit

Devin Review


Summary by cubic

Makes vera index refuse to overwrite an existing usable index unless --replace is passed, so a working index is no longer destroyed by an accidental rebuild. Use vera update to refresh changed files, or vera index . --replace for a deliberate full rebuild.

Behavior

  • Refuses only when the existing index is complete, current-format, and healthy; stray .vera/ directories, corrupt or missing metadata.db / bm25/ state, interrupted updates, old format versions, and retired chunking configs still rebuild without --replace.
  • Leaves --dry-run, vera setup, and internal callers (vera-mcp, vera-eval) on their previous overwrite behavior.
  • Recovers a pending .vera.old directory during preflight before refusing, so vera update and search prompts continue to work.
  • Failed API builds now suggest vera index --replace in the resume hint when a usable index still exists on disk.
  • Updates docs/ and skills/vera/SKILL.md and adds unit and CLI integration tests.

Written for commit 648cdef. Summary will update on new commits.

View guided diff Turn on auto-fix

Copilot AI balanced review requested due to automatic review settings November 18, 2026 09:37
@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 37 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 994d274 and 648cdef.

Files selected for processing: 16

  • crates/vera-cli/src/cli.rs
  • crates/vera-cli/src/commands/index.rs
  • crates/vera-cli/src/commands/setup.rs
  • crates/vera-cli/src/main.rs
  • crates/vera-cli/tests/full_text_only.rs
  • crates/vera-cli/tests/index_replace.rs
  • crates/vera-core/src/indexing/mod.rs
  • crates/vera-core/src/indexing/pipeline.rs
  • crates/vera-core/src/indexing/pipeline_tests.rs
  • crates/vera-core/src/storage/bm25.rs
  • docs/features.md
  • docs/llama-cpp-setup.md
  • docs/models.md
  • docs/supported-languages.md
  • docs/troubleshooting.md
  • skills/vera/SKILL.md
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

Devin Review

Comment thread crates/vera-core/src/storage/bm25.rs Outdated
Comment on lines +71 to +74
/// Whether `index_dir` contains a Tantivy index whose metadata opens cleanly.
pub(crate) fn is_valid_dir(index_dir: &Path) -> bool {
index_dir.join("meta.json").is_file() && Index::open_in_dir(index_dir).is_ok()
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Broken keyword indexes block automatic rebuilds

With a missing Tantivy segment, is_valid_dir accepts intact metadata and blocks rebuilding without --replace. Bm25Index::open creates a reader that fails on that missing segment. Keyword search remains broken despite the index being classified as usable.

Learn more

Tantivy separates opening index metadata from opening the segment readers used for search. Index::open_in_dir can succeed when a segment referenced by meta.json is missing. The normal Bm25Index::open then fails while constructing its reader. usable_index_exists_inner treats the metadata-only check as sufficient and prevents an automatic rebuild.

Example: Build a keyword-only index containing a source file, then delete a referenced .term or .idx segment file while retaining meta.json and metadata.db. Search fails, but vera index . --full-text-only refuses to rebuild until --replace is supplied.

Recommended fix: Validate that a search reader opens successfully, including registering the configured tokenizer, rather than checking only Index::open_in_dir. Add a regression test that removes a referenced segment file and verifies rebuilding without --replace.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

4 issues found across 16 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="docs/features.md">

<violation number="1" location="docs/features.md:156">
P2: This command does not rebuild a keyword-only index: without `--full-text-only`, `--replace` rebuilds the embedded index. Change the sentence to say it rebuilds with embeddings, or include `--full-text-only` and remove that phrase.</violation>
</file>

<file name="crates/vera-core/src/storage/bm25.rs">

<violation number="1" location="crates/vera-core/src/storage/bm25.rs:73">
P2: This validation only opens Tantivy’s metadata and does not verify that the referenced search segments can be read. A damaged BM25 index can therefore be classified as usable, causing `vera index` to refuse the automatic rebuild and leaving search broken; create an `IndexReader` (or reuse `Bm25Index::open`) in this check so missing or corrupt segment data returns false.</violation>
</file>

<file name="crates/vera-core/src/indexing/mod.rs">

<violation number="1" location="crates/vera-core/src/indexing/mod.rs:80">
P2: `usable_index_exists_inner` never validates `vectors.db`, so an embedded index with missing vector data is classified as usable and `vera index` refuses the automatic rebuild. Validate the vector store for non-full-text indexes, while keeping the full-text-only exception.</violation>

<violation number="2" location="crates/vera-core/src/indexing/mod.rs:108">
P3: The preflight skips `.vera.old` recovery whenever `.vera` exists, so a stale backup can survive indefinitely because the usable-index refusal runs before pipeline cleanup. Recover or remove `.vera.old` under the lock before refusing.</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread docs/features.md
Build a keyword (BM25) index without configuring or loading an embedding model. Grep, structural queries, references, and overview work exactly as with an embedded index. Search ranks by keyword match only, so queries that describe behavior in plain words find less than they would with embeddings. `vera update` and watch mode keep the index keyword-only.

Run `vera index .` without the flag to rebuild with embeddings.
Run `vera index . --replace` to rebuild a keyword-only index with embeddings.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: This command does not rebuild a keyword-only index: without --full-text-only, --replace rebuilds the embedded index. Change the sentence to say it rebuilds with embeddings, or include --full-text-only and remove that phrase.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At docs/features.md, line 156:

<comment>This command does not rebuild a keyword-only index: without `--full-text-only`, `--replace` rebuilds the embedded index. Change the sentence to say it rebuilds with embeddings, or include `--full-text-only` and remove that phrase.</comment>

<file context>
@@ -147,13 +153,13 @@ vera index . --full-text-only
 Build a keyword (BM25) index without configuring or loading an embedding model. Grep, structural queries, references, and overview work exactly as with an embedded index. Search ranks by keyword match only, so queries that describe behavior in plain words find less than they would with embeddings. `vera update` and watch mode keep the index keyword-only.
 
-Run `vera index .` without the flag to rebuild with embeddings.
+Run `vera index . --replace` to rebuild a keyword-only index with embeddings.
 
 ### Symbol-aware chunks
</file context>
Suggested change
Run `vera index . --replace` to rebuild a keyword-only index with embeddings.
Run `vera index . --replace` to rebuild with embeddings.

Comment thread crates/vera-core/src/storage/bm25.rs Outdated
impl Bm25Index {
/// Whether `index_dir` contains a Tantivy index whose metadata opens cleanly.
pub(crate) fn is_valid_dir(index_dir: &Path) -> bool {
index_dir.join("meta.json").is_file() && Index::open_in_dir(index_dir).is_ok()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: This validation only opens Tantivy’s metadata and does not verify that the referenced search segments can be read. A damaged BM25 index can therefore be classified as usable, causing vera index to refuse the automatic rebuild and leaving search broken; create an IndexReader (or reuse Bm25Index::open) in this check so missing or corrupt segment data returns false.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At crates/vera-core/src/storage/bm25.rs, line 73:

<comment>This validation only opens Tantivy’s metadata and does not verify that the referenced search segments can be read. A damaged BM25 index can therefore be classified as usable, causing `vera index` to refuse the automatic rebuild and leaving search broken; create an `IndexReader` (or reuse `Bm25Index::open`) in this check so missing or corrupt segment data returns false.</comment>

<file context>
@@ -68,6 +68,11 @@ fn register_stemmed_tokenizer(index: &Index) {
 impl Bm25Index {
+    /// Whether `index_dir` contains a Tantivy index whose metadata opens cleanly.
+    pub(crate) fn is_valid_dir(index_dir: &Path) -> bool {
+        index_dir.join("meta.json").is_file() && Index::open_in_dir(index_dir).is_ok()
+    }
+
</file context>
Suggested change
index_dir.join("meta.json").is_file() && Index::open_in_dir(index_dir).is_ok()
index_dir.join("meta.json").is_file() && Self::open(index_dir).is_ok()

} else {
freshness::ensure_index_complete_with_store(&idx_dir, &store).is_ok()
};
freshness::index_format_is_current(&store)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: usable_index_exists_inner never validates vectors.db, so an embedded index with missing vector data is classified as usable and vera index refuses the automatic rebuild. Validate the vector store for non-full-text indexes, while keeping the full-text-only exception.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At crates/vera-core/src/indexing/mod.rs, line 80:

<comment>`usable_index_exists_inner` never validates `vectors.db`, so an embedded index with missing vector data is classified as usable and `vera index` refuses the automatic rebuild. Validate the vector store for non-full-text indexes, while keeping the full-text-only exception.</comment>

<file context>
@@ -37,6 +38,89 @@ pub fn index_exists(root: &std::path::Path) -> bool {
+    } else {
+        freshness::ensure_index_complete_with_store(&idx_dir, &store).is_ok()
+    };
+    freshness::index_format_is_current(&store)
+        && complete
+        && freshness::ensure_index_chunking_compatible(&store, repo_root).is_ok()
</file context>

if !replace_existing && !lock_held {
let idx_dir = index_dir(repo_root);
let old_dir = pipeline::sibling_index_dir(&idx_dir, "old");
if !idx_dir.exists()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P3: The preflight skips .vera.old recovery whenever .vera exists, so a stale backup can survive indefinitely because the usable-index refusal runs before pipeline cleanup. Recover or remove .vera.old under the lock before refusing.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At crates/vera-core/src/indexing/mod.rs, line 108:

<comment>The preflight skips `.vera.old` recovery whenever `.vera` exists, so a stale backup can survive indefinitely because the usable-index refusal runs before pipeline cleanup. Recover or remove `.vera.old` under the lock before refusing.</comment>

<file context>
@@ -37,6 +38,89 @@ pub fn index_exists(root: &std::path::Path) -> bool {
+    if !replace_existing && !lock_held {
+        let idx_dir = index_dir(repo_root);
+        let old_dir = pipeline::sibling_index_dir(&idx_dir, "old");
+        if !idx_dir.exists()
+            && old_dir.exists()
+            && let Ok(Some(_guard)) = lock::IndexLock::try_acquire_for_index_dir(&idx_dir)
</file context>

@revera-lr7

revera-lr7 Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Revera review

Status: partial — no accepted findings, 1 unconfirmed

Review incomplete: one or more validations were inconclusive. Absence of findings is not evidence the change is clean; rerun or inspect the parts listed as not checked.

Checked: Reviewed all changed CLI, core indexing/BM25, test, and documentation code; traced overwrite checks through locking/recovery, provider initialization, setup/internal wrappers, checkpoint hints, and the unchanged search auto-index caller.

Timing: total 133s · index 27s · lanes 105s · validation 1.4s (p50 1.4s, p95 1.4s, first candidate at 132s) · 1 phase(s) incomplete · 1 phase(s) skipped

revera · strategy baseline · models: investigator=factory/gpt-6.1-sol@high

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1 existing issue remains and no new issues found across 16 files

Requires human review: Auto-approval blocked because this review re-detected 1 unresolved issue already reported by Cubic.

View guided diff | Turn on auto-fix | Re-trigger cubic

@lemon07r
lemon07r merged commit 0bd7a4f into master Nov 18, 2026
16 checks passed
@lemon07r
lemon07r deleted the feat/index-replace branch November 18, 2026 09:49
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.

2 participants