Repository navigation
feat(index): require --replace to overwrite a usable index - #318
Conversation
|
Warning Review limit reachedYou'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. View limit details
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. |
There was a problem hiding this comment.
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.
| /// 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() | ||
| } |
There was a problem hiding this comment.
🟡 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.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
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
| 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. |
There was a problem hiding this comment.
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>
| Run `vera index . --replace` to rebuild a keyword-only index with embeddings. | |
| Run `vera index . --replace` to rebuild with embeddings. |
| 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() |
There was a problem hiding this comment.
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>
| 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) |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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 reviewStatus: partial — no accepted findings, 1 unconfirmed
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 |
There was a problem hiding this comment.
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
Prevents
vera indexfrom accidentally overwriting an existing usable index unless--replaceis passed.Summary
--replacetovera indexand refuse to overwrite an existing usable index by default, pointing users tovera updatefor incremental refreshes and--replacefor full rebuilds.vera_core::indexing::usable_index_exists/ensure_replaceablebefore CLI provider setup (and again underIndexLockinpipeline.rs), recovering any pending.vera.olddirectory first during preflight sovera updateand search prompts continue to work.--replacefor stray.vera/directories, corrupt/missingmetadata.dbor Tantivybm25/state, interrupted updates (index_complete = "0"), old format versions, and retired character-cap chunking configs.--dry-run,vera setup/vera setup --index, and internal callers (vera-mcp,vera-eval), and adjust failed API--replacecheckpoint hints to suggestvera index --replacewhen a usable index still exists on disk.docs/andskills/vera/SKILL.md, and add unit and CLI integration tests.Verification
cargo fmt --all -- --checkcargo clippy --locked --workspace --all-targets -- -D warningscargo test --locked --workspace(1,770 passed, 0 failed, 63 ignored)RUSTDOCFLAGS="-D warnings" cargo doc --locked --workspace --no-depscargo deny --locked check,cargo machete,cargo auditSummary by cubic
Makes
vera indexrefuse to overwrite an existing usable index unless--replaceis passed, so a working index is no longer destroyed by an accidental rebuild. Usevera updateto refresh changed files, orvera index . --replacefor a deliberate full rebuild.Behavior
.vera/directories, corrupt or missingmetadata.db/bm25/state, interrupted updates, old format versions, and retired chunking configs still rebuild without--replace.--dry-run,vera setup, and internal callers (vera-mcp,vera-eval) on their previous overwrite behavior..vera.olddirectory during preflight before refusing, sovera updateand search prompts continue to work.vera index --replacein the resume hint when a usable index still exists on disk.docs/andskills/vera/SKILL.mdand adds unit and CLI integration tests.Written for commit 648cdef. Summary will update on new commits.