fix(mcp): false worktree-mismatch warning when worktree has its own index (#926)#934
Open
Allicai wants to merge 1 commit into
Open
fix(mcp): false worktree-mismatch warning when worktree has its own index (#926)#934Allicai wants to merge 1 commit into
Allicai wants to merge 1 commit into
Conversation
400d42e to
daed12b
Compare
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.
Closes #926
What was wrong
Two stale-cache bugs in
ToolHandlercombined 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 explicitprojectPathpointing at it.Bug A —
projectCachestaleness: a prior tool call withprojectPath=<wt>(before the worktree index existed) cachedwt → mainRepoCG. After the worktree index was created the stale entry persisted, sogetCodeGraph(wt)kept returning the main repo's CodeGraph.Bug B —
worktreeMismatchCachekey collision: the mismatch cache was keyed onstartPathalone. A call withoutprojectPath(wherestartPath = defaultProjectHint = wt,indexRoot = mainRepo) cached a legitimate mismatch under key"wt". A later call withprojectPath=wt(whereindexRoot = wt) hit the same key and returned the stale entry.Fix
getCodeGraph): when a cached entry's root is a parent ofprojectPath, re-runfindNearestCodeGraphRoot; evict and fall through if a closer index now exists.worktreeMismatchFor): key the mismatch cache on${startPath}\0${indexRoot}so the two call shapes above get independent entries.Tests
Added a regression
describeblock to__tests__/worktree-detection.test.tscovering the two fixed scenarios and the correct null result for(worktree, worktree).