Skip to content

fix(index): safely seed nested worktree indexes - #178

Draft
aeneasr wants to merge 3 commits into
mainfrom
aeneasr/review-pr-177
Draft

fix(index): safely seed nested worktree indexes#178
aeneasr wants to merge 3 commits into
mainfrom
aeneasr/review-pr-177

Conversation

@aeneasr

@aeneasr aeneasr commented Jul 27, 2026

Copy link
Copy Markdown
Member

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_path metadata.

Skips donor copies for --force and reports interactive seed status while preserving MCP warnings.

Tests: make test; make lint.

ntotten and others added 3 commits July 27, 2026 17:47
…-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>
@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 93110792-322d-45c9-95f4-0d8e041e3100

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch aeneasr/review-pr-177

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

Comment @coderabbitai help to get the list of available commands.

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