Skip to content

fix(agent-manager): preserve untracked symlinks when moving to worktree - #15489

Open
markjoin123 wants to merge 2 commits into
Kilo-Org:mainfrom
markjoin123:cursor/fix-worktree-untracked-symlinks-87d2
Open

markjoin123 wants to merge 2 commits into
Kilo-Org:mainfrom
markjoin123:cursor/fix-worktree-untracked-symlinks-87d2

Conversation

@markjoin123

Copy link
Copy Markdown

Issue

Fixes #15488

Context

Move to Worktree copied an untracked symlink as a regular file holding the target's contents. active.txt -> settings.txt (?? active.txt) arrived in the new worktree as a normal file containing original, so later edits to settings.txt no longer showed through the link. Staged symlinks already survived because they travel through a git patch.

Implementation

The untracked capture path now records the link text from lstat/readlink (VS Code) and NOFOLLOW_LINKS/readSymbolicLink (JetBrains), and apply recreates that same target. Relative targets stay relative. A link that points outside the repo is recreated as that link, and the outside file is left unread. Regular files still copy as files. Dangling and directory symlinks are preserved as links.

If symlink creation fails, VS Code logs and skips that path, matching its other untracked write errors. JetBrains logs and fails the transfer so the move rolls back, matching its existing untracked write failures.

Screenshots / Video

N/A. This is file-transfer behavior, with no UI change.

before after
N/A N/A

How to Test

Manual/local verification

Unit and integration tests, listed below. The VS Code cases replay the issue: an untracked active.txt -> settings.txt is still a symlink after transfer, readlink is settings.txt, and writing changed to settings.txt in the destination is what the link reads.

Reviewer test steps

  1. In a git repo, commit settings.txt with contents original, then ln -s settings.txt active.txt. git status --short shows ?? active.txt.
  2. Move to Worktree.
  3. In the new worktree, ls -l active.txt shows active.txt -> settings.txt.
  4. echo changed > settings.txt, then read through active.txt. It prints changed.
  5. The source repo still has the original symlink.

Blocked checks and substitute verification

None.

  • bun test --timeout 20000 tests/unit/git-transfer.test.ts (packages/kilo-vscode): 27 pass, 0 fail. (At the default 5s hook timeout a busy machine timed out some beforeEach/afterEach hooks, including existing tests; the symlink cases alone, -t "symlink", pass 4/4 in under a second.)
  • bun run typecheck and bun run lint (packages/kilo-vscode): exit 0.
  • bun typecheck --filter='!@kilocode/kilo-jetbrains' (repo root): 29 successful.
  • ./gradlew :backend:test --tests ai.kilocode.backend.rpc.KiloWorktreeRpcApiImplTest (packages/kilo-jetbrains): BUILD SUCCESSFUL, 164 tests, 0 failures, 0 errors, 0 skipped.
  • ./gradlew typecheck (packages/kilo-jetbrains): BUILD SUCCESSFUL.

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.

This change was AI-assisted. It was reviewed and tested as described above.

@github-actions github-actions Bot added area:agent-manager Agent Manager area:jetbrains JetBrains plugin 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 27, 2026
try {
await fs.mkdir(nodePath.dirname(full), { recursive: true })
if (file.link != null) {
await fs.symlink(file.link, full)

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]: A failed fs.symlink silently drops the untracked entry while apply still returns { ok: true }

Unlike fs.writeFile (which overwrites), fs.symlink throws when full already exists, and it also fails where symlinks are unsupported or unprivileged (Windows without developer mode, SMB/network shares, FAT/exFAT). The setup script runs before the transfer (prepareWorktree runs runSetupScript, then transferState), so a setup script that creates the same path now causes the symlink to be skipped instead of overwritten. The only signal is the log line, and the move reports success with that untracked path missing. This also diverges from the JetBrains implementation, which fails the transfer and rolls back on the same error. Consider await fs.rm(full, { force: true }) before fs.symlink for parity with the writeFile path, or returning { ok: false } so callers can roll back. Note the new tests skip Windows entirely, so this branch has no coverage on the platform where symlink creation fails most often.

}
})

it.skipIf(process.platform === "win32")("logs and skips an untracked symlink that cannot be created", async () => {

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.

[SUGGESTION]: This test does not reach the symlink-creation failure it names. target/sub is a regular file, so fs.mkdir(dirname(full), { recursive: true }) throws EEXIST before fs.symlink runs, and the assertion only checks that the path appears in some log line. Making target/sub a directory that already contains an active.txt file would exercise the fs.symlink EEXIST path (the overwrite-vs-fail case above) instead.

@kilo-code-bot

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

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

The incremental changes resolve both earlier findings. In VS Code, apply now lstats the untracked link path, removes an existing file or symlink before fs.symlink, and returns { ok: false } when link creation still fails, so continueInWorktree rolls the worktree back instead of reporting success with the entry missing. JetBrains mirrors this with NOFOLLOW_LINKS checks and the same rollback path, and the reworked tests now reach the symlink failure case (a directory occupying the target path) rather than failing earlier in mkdir/createDirectories.

Files Reviewed (4 files)
  • packages/kilo-jetbrains/backend/src/main/kotlin/ai/kilocode/backend/rpc/WorktreeTransfer.kt
  • packages/kilo-jetbrains/backend/src/test/kotlin/ai/kilocode/backend/rpc/KiloWorktreeRpcApiImplTest.kt
  • packages/kilo-vscode/src/agent-manager/git-transfer.ts
  • packages/kilo-vscode/tests/unit/git-transfer.test.ts
Previous Review Summary (commit 05d87af)

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

Previous review (commit 05d87af)

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 1

The core fix is sound: capture now records link text via lstat/readlink and NOFOLLOW_LINKS/readSymbolicLink, and apply recreates the link instead of following it, so the reported active.txt -> settings.txt case works and outside content is no longer copied. Changeset is present and the touched paths are Kilo-only, so no fork-hygiene concerns. One behavioral regression and one test gap are noted inline.

Issue Details (click to expand)

WARNING

File Line Issue
packages/kilo-vscode/src/agent-manager/git-transfer.ts 162 fs.symlink throws on EEXIST and where symlinks are unsupported (Windows without developer mode, SMB/FAT); the error is only logged, so apply returns { ok: true } with the untracked entry silently missing. Previously fs.writeFile overwrote. JetBrains fails and rolls back on the same error.

SUGGESTION

File Line Issue
packages/kilo-vscode/tests/unit/git-transfer.test.ts 337 The "cannot be created" test fails in fs.mkdir (because target/sub is a regular file) and never reaches the fs.symlink failure it claims to cover.
Files Reviewed (5 files)
  • .changeset/worktree-untracked-symlinks.md - 0 issues
  • packages/kilo-jetbrains/backend/src/main/kotlin/ai/kilocode/backend/rpc/WorktreeTransfer.kt - 0 issues
  • packages/kilo-jetbrains/backend/src/test/kotlin/ai/kilocode/backend/rpc/KiloWorktreeRpcApiImplTest.kt - 0 issues
  • packages/kilo-vscode/src/agent-manager/git-transfer.ts - 1 issue
  • packages/kilo-vscode/tests/unit/git-transfer.test.ts - 1 issue

Fix these issues in Kilo Cloud


Reviewed by deepseek-flash-latest · Input: 58K · Output: 12.3K · Cached: 517.1K

Review guidance: REVIEW.md from base branch main

@markjoin123

Copy link
Copy Markdown
Author

Addressed both review points in cb46709:

  • Existing path / symlink failure: before creating the link, both the VS Code and JetBrains paths now remove an existing file or symlink at the target path (matching the previous overwrite behaviour). If the link still can't be created (e.g. a directory is in the way, or symlinks are unsupported), the failure is returned as Failed to write untracked file … and the VS Code move rolls back the worktree, consistent with JetBrains, instead of silently reporting success.
  • Test gap: the old "cannot be created" case is split into two that actually reach symlink: an existing active.txt file gets replaced by the link, and a directory at active.txt makes symlink fail and apply report the error. Same two cases added on the JetBrains side.

Tests: git-transfer.test.ts 28 pass; typecheck and lint clean; KiloWorktreeRpcApiImplTest 165 tests pass.

markjoin123 added a commit to markjoin123/markjoin123 that referenced this pull request Oct 28, 2026

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:jetbrains JetBrains plugin 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.

[Bug] Move to Worktree turns untracked symbolic links into regular files

1 participant