fix(index): safely seed nested worktree indexes - #178
Draft
aeneasr wants to merge 3 commits into
Draft
Conversation
…-embedding Working in a fresh git worktree of an already-indexed repo re-embedded every file from scratch (~minutes on a local embedder) instead of reusing a sibling worktree's embeddings. Two independent bugs defeated the existing donor-seeding path, and both bite Claude Code's default repo/.claude/worktrees/<name> layout. Bug 1 — donor discovery picked the wrong worktree (internal/config/seed.go). FindDonorIndexBase selected the FIRST `git worktree list` entry containing the project. git lists the main checkout first, so for a worktree nested inside the repo it identified the main checkout as "self", searched for donors at nonexistent <sibling>/.claude/worktrees/<name> paths, and skipped the one real donor (the parent repo's index). Fix: pick the deepest (most specific) containing worktree — the longest matching path, since every match is an ancestor of the project and they form a prefix chain. Bug 2 — the CLI indexer never seeded (cmd/index.go, cmd/seed.go). Seeding only ran in the MCP search handler, but the SessionStart hook spawns `lumen index`, which created the DB first; SeedFromDonor then no-ops because the DB exists, so the hook permanently won the race and forced a full rebuild. Fix: seed from a donor in runIndexer, under the index lock, before the DB is created. Because both the CLI indexer and the MCP handler can now seed the same fresh worktree concurrently, harden SeedFromDonor (internal/index/seed.go) to copy to a unique temp file (os.CreateTemp) and publish via a create-if-absent hard link (os.Link fails on EEXIST). The loser of the race no-ops instead of renaming a fresh copy over a database the winner already opened for writing. Adds unit tests for the nested-worktree layout, concurrent seeding, and the runIndexer seed helper. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- SeedFromDonor: copy into the open temp descriptor instead of closing and re-opening it by name (avoids a Windows sharing violation), defer the descriptor's close, and check the Close error before publishing via os.Link so a short write can't be linked into place. Removes the now-unused copyFile. - cmd/seed_test.go: consolidate the four seedFromDonorIfNew cases into a single table-driven test, per the repo's Go testing guideline. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Seeds new nested-worktree indexes from the deepest indexed sibling for both CLI and MCP paths, avoiding full re-embedding.
Hardens publication with context-aware advisory locking, SQLite WAL checkpointing, a portable rename fallback, bounded temp cleanup, and correct
project_pathmetadata.Skips donor copies for
--forceand reports interactive seed status while preserving MCP warnings.Tests:
make test;make lint.