A removed worktree is resurrected: the MCP server respawns its daemon, which recreates the directory, and provenance then reports the parent repo's HEAD as its head #361

Closed
opened 2026-10-12 20:28:55 +02:00 by buildagent · 1 comment
Member

Observed (0.36.1 / 876b78b5, 2026-10-12)

  1. The MCP server started with 29 worktrees under .claude/worktrees as linked projects (it lists them only at startup, #310).
  2. I removed 22 merged worktrees with git worktree remove after stopping each one's daemon by PID.
  3. The next fan-out call (project_overview) spawned new daemons for three of the removed roots (agent-a0914…, agent-ab2a1…, agent-af2fc…). Each daemon recreated the deleted root directory to hold a fresh .code-index/.
  4. answer_provenance.indexed_trees then reported, for those three:
    • "head":"407c49251ccd","uncommitted_changes":false, which is the primary checkout's HEAD. git -C in a directory holding only .code-index/ walks up to the parent repository.
    • The other 19 removed roots correctly said unavailable: cannot change to …: No such file or directory.

This has happened before: 11 more directories under .claude/worktrees contained only .code-index/, dated 2026-10-04 and 2026-10-10, both earlier worktree cleanups.

Why it matters

  • Wrong provenance: a vanished project reports another repository's HEAD as its own, as a measurement, not as "unavailable".
  • Silent recreation: a daemon spawn creates a directory the user deleted; this needs a test with its mutation run.
  • Cost: it spends a daemon and an index build on a project that no longer exists.

Expected

  • daemon_command / attach-or-spawn refuses to start for a root that does not exist, instead of creating it. Same answer as unavailable, with the reason.
  • indexed_trees derives head only when the root is itself a git worktree top level (git rev-parse --show-toplevel equals the root). Otherwise it reports unavailable, never the parent repo's HEAD.
  • Optional: the linked-project list notices a removed root (relates to #310).

🤖 Generated with Claude Code

## Observed (0.36.1 / 876b78b5, 2026-10-12) 1. The MCP server started with 29 worktrees under `.claude/worktrees` as linked projects (it lists them only at startup, #310). 2. I removed 22 merged worktrees with `git worktree remove` after stopping each one's daemon by PID. 3. The next fan-out call (`project_overview`) spawned new daemons for three of the removed roots (`agent-a0914…`, `agent-ab2a1…`, `agent-af2fc…`). Each daemon **recreated the deleted root directory** to hold a fresh `.code-index/`. 4. `answer_provenance.indexed_trees` then reported, for those three: - `"head":"407c49251ccd","uncommitted_changes":false`, which is the **primary checkout's HEAD**. `git -C` in a directory holding only `.code-index/` walks up to the parent repository. - The other 19 removed roots correctly said `unavailable: cannot change to …: No such file or directory`. This has happened before: 11 more directories under `.claude/worktrees` contained only `.code-index/`, dated 2026-10-04 and 2026-10-10, both earlier worktree cleanups. ## Why it matters - **Wrong provenance:** a vanished project reports another repository's HEAD as its own, as a measurement, not as "unavailable". - **Silent recreation:** a daemon spawn creates a directory the user deleted; this needs a test with its mutation run. - **Cost:** it spends a daemon and an index build on a project that no longer exists. ## Expected - `daemon_command` / attach-or-spawn **refuses to start for a root that does not exist**, instead of creating it. Same answer as `unavailable`, with the reason. - `indexed_trees` derives `head` only when the root is itself a git worktree top level (`git rev-parse --show-toplevel` equals the root). Otherwise it reports unavailable, never the parent repo's HEAD. - Optional: the linked-project list notices a removed root (relates to #310). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Member

Fixed in v0.41.0 (merge 9f1ae9c2, PR #389).

  • No resurrection: attach-or-spawn refuses a root that doesn't exist (spawn_refusal) instead of starting a daemon for it. The state directory is no longer created through a missing parent (ensure_state_dir), and the panic log is opened without recreating parents (panic_log::append through create_state_dir_tight). So no daemon recreates a removed worktree.
  • No borrowed HEAD: with the directory no longer recreated, a removed root reports unavailable: … No such file or directory and never walks up to the parent repository.
  • The project set follows removal: linked worktrees are re-derived (bounded to one re-derivation per 2 s), so a removed worktree drops out of replies (see #310).
  • Test: crates/mcp-server/tests/worktree_projects_e2e.rs removes a worktree mid-session, queries, and asserts the root is not recreated and the project is gone. Mutations run during verification: the log append back to create_dir_all → RED; never re-derive → RED.

🤖 Generated with Claude Code

Fixed in **v0.41.0** (merge 9f1ae9c2, PR #389). - **No resurrection:** attach-or-spawn refuses a root that doesn't exist (`spawn_refusal`) instead of starting a daemon for it. The state directory is no longer created through a missing parent (`ensure_state_dir`), and the panic log is opened without recreating parents (`panic_log::append` through `create_state_dir_tight`). So no daemon recreates a removed worktree. - **No borrowed HEAD:** with the directory no longer recreated, a removed root reports `unavailable: … No such file or directory` and never walks up to the parent repository. - **The project set follows removal:** linked worktrees are re-derived (bounded to one re-derivation per 2 s), so a removed worktree drops out of replies (see #310). - **Test:** `crates/mcp-server/tests/worktree_projects_e2e.rs` removes a worktree mid-session, queries, and asserts the root is not recreated and the project is gone. Mutations run during verification: the log append back to `create_dir_all` → RED; never re-derive → RED. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
h-dv/code-index#361
No description provided.