Skip to content

fix(mcp): false worktree-mismatch warning when worktree has its own index (#926)#934

Open
Allicai wants to merge 1 commit into
colbymchenry:mainfrom
Allicai:fix/mcp-worktree-stale-project-cache
Open

fix(mcp): false worktree-mismatch warning when worktree has its own index (#926)#934
Allicai wants to merge 1 commit into
colbymchenry:mainfrom
Allicai:fix/mcp-worktree-stale-project-cache

Conversation

@Allicai

@Allicai Allicai commented Jun 20, 2026

Copy link
Copy Markdown

Closes #926

What was wrong

Two stale-cache bugs in ToolHandler combined to produce a false "index belongs to a different git working tree" warning even when a linked worktree had its own .codegraph/ index and the tool was called with an explicit projectPath pointing at it.

Bug A — projectCache staleness: a prior tool call with projectPath=<wt> (before the worktree index existed) cached wt → mainRepoCG. After the worktree index was created the stale entry persisted, so getCodeGraph(wt) kept returning the main repo's CodeGraph.

Bug B — worktreeMismatchCache key collision: the mismatch cache was keyed on startPath alone. A call without projectPath (where startPath = defaultProjectHint = wt, indexRoot = mainRepo) cached a legitimate mismatch under key "wt". A later call with projectPath=wt (where indexRoot = wt) hit the same key and returned the stale entry.

Fix

  • Fix A (getCodeGraph): when a cached entry's root is a parent of projectPath, re-run findNearestCodeGraphRoot; evict and fall through if a closer index now exists.
  • Fix B (worktreeMismatchFor): key the mismatch cache on ${startPath}\0${indexRoot} so the two call shapes above get independent entries.

Tests

Added a regression describe block to __tests__/worktree-detection.test.ts covering the two fixed scenarios and the correct null result for (worktree, worktree).

@Allicai Allicai force-pushed the fix/mcp-worktree-stale-project-cache branch from 400d42e to daed12b Compare June 20, 2026 21:27
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.

MCP projectPath worktree queries falsely warn that a valid local worktree index belongs to the main repo

1 participant