Skip to content

fix(vscode): create Agent Manager worktrees from a repository subdirectory - #15467

Open
cpruijsen wants to merge 2 commits into
Kilo-Org:mainfrom
cpruijsen:fix/agent-manager-lfs-subdir
Open

cpruijsen wants to merge 2 commits into
Kilo-Org:mainfrom
cpruijsen:fix/agent-manager-lfs-subdir

Conversation

@cpruijsen

@cpruijsen cpruijsen commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Issue

Fixes #15448

Context

Agent Manager worktree creation failed when the VS Code window was opened on a subdirectory of a git repository. The LFS check called stat on <folder>/.git and threw ENOENT. Pull request #14274 already asks git for the exclude file in this layout. The LFS check and the gitdir repair helper still used the direct stat.

I now resolve the shared git directory with git rev-parse --git-common-dir, from the opened folder. The project root is still that folder.

Changed files:

  • packages/kilo-vscode/src/agent-manager/constants.ts
  • packages/kilo-vscode/src/agent-manager/WorktreeManager.ts
  • packages/kilo-vscode/tests/unit/worktree-manager.test.ts
  • .changeset/agent-manager-subdir-worktree.md

Implementation

resolveGitDir runs git rev-parse --git-common-dir with the workspace as its cwd. The result can be relative, so it is resolved against that folder. repoUsesLfs passes the configured git binary.

I used --git-common-dir because Git LFS keeps its files in the shared git directory. --git-path lfs follows the per-worktree git directory, so a linked worktree would miss .git/lfs.

Screenshots / Video

N/A. No visual change.

before after
N/A N/A

How to Test

Manual/local verification

I ran bun test tests/unit/worktree-manager.test.ts -t "creates a worktree from a subdirectory of the repository" from packages/kilo-vscode before the fix. Result: 0 pass, 1 fail. The failure was ENOENT from fs.stat of <subfolder>/.git, in resolveGitDir via repoUsesLfs.

I ran the same command after the fix. Result: 1 pass.

I ran the full unit suite, bun test tests/unit/: 6968 tests, 0 fail, 2 skip.

bunx eslint on constants.ts and WorktreeManager.ts exited 0. bun run check-types and bun run check-types:webview in packages/kilo-vscode both exited 0.

I also drove resolveGitDir and WorktreeManager against temporary git repositories. A nested subdirectory resolved to the real .git. info/attributes with filter=lfs was detected from that subdirectory. A linked worktree and a subdirectory of that worktree both saw .git/lfs in the shared git directory, and worktree creation from the worktree subdirectory succeeded. A stale .kilocode gitdir path was rewritten when the manager root was a subdirectory. A separate git directory was resolved, and its lfs directory was detected.

Reviewer test steps

  1. From packages/kilo-vscode, run bun test tests/unit/worktree-manager.test.ts -t "creates a worktree from a subdirectory of the repository".
  2. In a scratch repository that has one commit, create a subfolder and open that subfolder as the only VS Code workspace folder.
  3. Open Agent Manager and create a worktree.
  4. Confirm creation finishes without ENOENT, the worktree is under that subfolder's .kilo/worktrees directory, and git status in the repository does not list it.

Blocked checks and substitute verification

None. The checks above completed.

Checklist

  • Issue linked above, or exception explained
  • Tests/verification described
  • Screenshots/video included for visual changes, or marked N/A
  • Changeset considered for user-facing changes
  • I personally reviewed the diff and can explain the changes, including any AI-assisted work.

Get in Touch

…ctory

Opening a subdirectory of a git repository made worktree creation stat a missing .git path. Git now supplies the shared git directory.
@github-actions github-actions Bot added area:agent-manager Agent Manager area:vscode VS Code extension community Opened by someone outside the Kilo team needs-triage Waiting for a maintainer to look priority:p1 High: fixes and regressions. Set from the title. Change by hand. labels Oct 25, 2026
// gitdir points to e.g. /repo/.git/worktrees/foo — go up two levels to /repo/.git
return path.resolve(path.dirname(gitPath), match[1].trim(), "..", "..")
export async function resolveGitDir(root: string, binary = "git"): Promise<string> {
const { stdout } = await exec(binary, ["rev-parse", "--git-common-dir"], { cwd: root })

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: This spawns git with plain exec, which does no PATH recovery and has no timeout.

ensureGitAvailable()/checkLfsAvailable() and the other git calls in WorktreeManager go through execWithShellEnv (src/agent-manager/shell-env.ts) because a VS Code window launched from Finder/Dock inherits a minimal PATH that can miss Homebrew/nvm git. The create path is currently shielded only because ensureGitAvailable() runs before preflight(), but resolveGitDir is also reached from migrateAgentManagerData -> fixGitWorktreeRefs before any shell-env resolution, where a missing git makes the ref repair silently no-op (resolveGitDir(root).catch(() => undefined)). fixGitWorktreeRefs also still calls resolveGitDir(root) without binary, so a custom-configured git binary is ignored on that path.

Suggestion: route this through execWithShellEnv with a bounded timeout (e.g. BUDGET.probe) and thread this.binary into the fixGitWorktreeRefs caller. Note the current exec import is still the correct Windows-safe wrapper, just not PATH-resilient.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in cd0efaa. resolveGitDir now runs through execWithShellEnv with the BUDGET.probe timeout, like the other git calls in WorktreeManager. The migration path keeps the default git binary, the same as the other callers that have no configured binary.

@kilo-code-bot

kilo-code-bot Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

The previous warning about resolveGitDir spawning plain exec is resolved: it now runs through execWithShellEnv with the BUDGET.probe timeout, matching the other git calls in Agent Manager. repoUsesLfs threads the configured binary through, and the timeout keeps the migration path from hanging. No new issues in the incremental change.

Files Reviewed (1 file)
  • packages/kilo-vscode/src/agent-manager/constants.ts - no issues
Previous Review Summary (commit ec4bb85)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit ec4bb85)

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
packages/kilo-vscode/src/agent-manager/constants.ts 125 resolveGitDir spawns git with plain exec (no shell-env PATH recovery, no timeout). fixGitWorktreeRefs calls it before any shell-env resolution and without the configured binary, so on a GUI-launched VS Code with git outside the minimal PATH the ref repair silently no-ops. Prefer execWithShellEnv with a bounded timeout, and thread binary through the caller.
Files Reviewed (4 files)
  • .changeset/agent-manager-subdir-worktree.md - no issues
  • packages/kilo-vscode/src/agent-manager/WorktreeManager.ts - no issues
  • packages/kilo-vscode/src/agent-manager/constants.ts - 1 issue
  • packages/kilo-vscode/tests/unit/worktree-manager.test.ts - no issues

Fix these issues in Kilo Cloud


Reviewed by deepseek-flash-latest · Input: 45.3K · Output: 5.9K · Cached: 354.4K

Review guidance: REVIEW.md from base branch main

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:agent-manager Agent Manager area:vscode VS Code extension community Opened by someone outside the Kilo team needs-triage Waiting for a maintainer to look priority:p1 High: fixes and regressions. Set from the title. Change by hand.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Agent Manager: worktree creation fails with a raw ENOENT when the VS Code window is opened in a subdirectory of a git repository

1 participant