Repository navigation
Fix: findWorkspaceRoot() respects worktree boundaries - #408
Merged
waleedkadous merged 2 commits intoFeb 17, 2026
Merged
Conversation
findWorkspaceRoot() in config.ts always resolved worktree paths back to the main repo via getMainRepoFromWorktree(). This caused any codev tooling running inside a builder worktree to write files to the main tree instead of the worktree, leading to "untracked files would be overwritten by merge" errors after merging builder PRs (#404, #406, #370, #383). Fix: When in a worktree, find the worktree root first (via .git marker), then check if it has its own codev/ directory. Builder worktrees are full git checkouts with their own codev/, so we return the worktree root. Only fall back to the main repo if the worktree lacks codev/.
Address CMAP feedback: the filesystem-only tests don't exercise the worktree code path (git rev-parse fails in non-git temp dirs). Add integration tests that create real git repos and worktrees to verify the getMainRepoFromWorktree() → worktree branch.
waleedkadous
deleted the
builder/bugfix-407-builder-worktree-leakage-findw
branch
February 17, 2026 18:33
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.
Summary
Fixes #407 —
findWorkspaceRoot()inconfig.tsalways resolved worktree paths back to the main repository viagit rev-parse --git-common-dir. This caused file writes from builder tools (af commands) to leak into the main tree instead of staying within the builder's isolated worktree.Root cause: The old code detected a worktree, then immediately resolved to the main repo root. It never checked whether the worktree itself had its own
codev/directory.Fix: When in a worktree, walk up to find the worktree root (via
.gitmarker), and if that root has its owncodev/directory, return it instead of resolving to the main repo.packages/codev/src/agent-farm/utils/config.ts— Rewrote worktree handling infindWorkspaceRoot()to check worktree root forcodev/before falling back to main repopackages/codev/src/agent-farm/__tests__/findWorkspaceRoot.test.ts— 7 regression tests covering normal, subdirectory, worktree, and edge-case scenariosTest plan
npx tsc --noEmit)