COSI_WORKTREES_DIR links worktrees only at startup: a lane created mid-session is invisible to every tool #310

Closed
opened 2026-10-02 13:50:51 +02:00 by buildagent · 2 comments
Member

Found while dogfooding on 2026-10-02.

With COSI_WORKTREES_DIR set (#238), each worktree under that directory becomes a project named agent-<id>. project_overview says the link was "Discovered at startup: a worktree created since then is not here." In practice the agent workflow creates a worktree for every lane, AFTER the MCP server has started. Today four lanes were spawned after the server started, and their worktrees became reachable only after a manual /mcp reconnect.

Impact. A lane's own code is invisible to search_symbols, search_text, file_outline, find_callers, changed_symbols and review_diff for the whole life of the lane. Agents fall back to grep and sed, which is the failure #238 set out to fix. Lanes Q and P of #309 reported exactly this.

Expected. Worktrees created under COSI_WORKTREES_DIR are discovered while the server runs, for example by the watcher on that directory or by a re-scan on project_not_found for an agent-* name. They are disclosed the same way startup links are. A worktree removed mid-session goes project_not_available, not stale.

Test. Start the server, create a worktree, then query project: "agent-<new>" → answered. Mutation: disable rediscovery → project_not_found.

Found while dogfooding on 2026-10-02. With `COSI_WORKTREES_DIR` set (#238), each worktree under that directory becomes a project named `agent-<id>`. `project_overview` says the link was "Discovered at startup: a worktree created since then is not here." In practice the agent workflow creates a worktree for every lane, AFTER the MCP server has started. Today four lanes were spawned after the server started, and their worktrees became reachable only after a manual `/mcp` reconnect. **Impact.** A lane's own code is invisible to `search_symbols`, `search_text`, `file_outline`, `find_callers`, `changed_symbols` and `review_diff` for the whole life of the lane. Agents fall back to grep and sed, which is the failure #238 set out to fix. Lanes Q and P of #309 reported exactly this. **Expected.** Worktrees created under `COSI_WORKTREES_DIR` are discovered while the server runs, for example by the watcher on that directory or by a re-scan on `project_not_found` for an `agent-*` name. They are disclosed the same way startup links are. A worktree removed mid-session goes `project_not_available`, not stale. **Test.** Start the server, create a worktree, then query `project: "agent-<new>"` → answered. Mutation: disable rediscovery → `project_not_found`.
Author
Member

This is the second half of the same problem, observed on 2026-10-02: a linked worktree removed mid-session is resurrected.

git worktree remove deleted .claude/worktrees/agent-ac20002b5c531d127. The directory then came back holding only .code-index/ (created 18:27, the minute of the removal), so git worktree remove failed with "Directory not empty". The server still had the link from startup, and something in its per-link handling recreated the index directory under a project root that no longer existed.

Expected: when a linked root disappears, the link becomes project_not_available and nothing is created there. The index directory of a missing root must never be created; at most it is opened if it still exists. Test: link a worktree, remove it, query the link → project_not_available, and the path does not exist afterwards.

This is the second half of the same problem, observed on 2026-10-02: a linked worktree removed mid-session is resurrected. `git worktree remove` deleted `.claude/worktrees/agent-ac20002b5c531d127`. The directory then came back holding only `.code-index/` (created 18:27, the minute of the removal), so `git worktree remove` failed with "Directory not empty". The server still had the link from startup, and something in its per-link handling recreated the index directory under a project root that no longer existed. Expected: when a linked root disappears, the link becomes `project_not_available` and nothing is created there. The index directory of a missing root must never be created; at most it is opened if it still exists. Test: link a worktree, remove it, query the link → `project_not_available`, and the path does not exist afterwards.
Author
Member

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

The linked-worktree set is no longer frozen at startup. crates/mcp-server/src/project_set.rs re-derives it from the worktrees directory, at most once per 2 s (REDERIVE_BOUND), so:

  • a worktree created after the server started is reachable as agent-<id> without a /mcp reconnect;
  • a worktree removed mid-session drops out (with #361, its daemon is never respawned and its directory never recreated).

Test: crates/mcp-server/tests/worktree_projects_e2e.rs starts the server, creates a worktree, queries it by name (answered), removes it, and queries again (gone). Mutation run during verification: never re-derive → both cases RED.

🤖 Generated with Claude Code

Fixed in **v0.41.0** (merge 9f1ae9c2, PR #389). The linked-worktree set is no longer frozen at startup. `crates/mcp-server/src/project_set.rs` re-derives it from the worktrees directory, at most once per 2 s (`REDERIVE_BOUND`), so: - a worktree created after the server started is reachable as `agent-<id>` without a `/mcp` reconnect; - a worktree removed mid-session drops out (with #361, its daemon is never respawned and its directory never recreated). Test: `crates/mcp-server/tests/worktree_projects_e2e.rs` starts the server, creates a worktree, queries it by name (answered), removes it, and queries again (gone). Mutation run during verification: never re-derive → both cases 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#310
No description provided.