Skip to content

fix(agent-manager): clean up failed session moves - #11358

Merged
marius-kilocode merged 1 commit into
mainfrom
swamp-isthmus
Jun 17, 2026
Merged

fix(agent-manager): clean up failed session moves#11358
marius-kilocode merged 1 commit into
mainfrom
swamp-isthmus

Conversation

@marius-kilocode

Copy link
Copy Markdown
Collaborator

When Move to Worktree cannot apply the source checkout's Git changes, worktree creation has already persisted the checkout and marked its setup as busy. The move reports an error to the originating chat but leaves the partial worktree registered. Without a terminal setup event, Agent Manager continues treating it as busy and hides the normal delete action.

Treat Git transfer as part of the worktree creation transaction. On transfer failure, use the existing worktree deletion path to remove persisted state, the checkout, and the generated branch. Then emit a terminal setup error so Agent Manager clears its busy state while preserving the original transfer error. Successful moves, Git patch behavior, base selection, and setup ordering remain unchanged.

@kilo-code-bot

kilo-code-bot Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: 1 Observation | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 0
Other Observations (not in diff)

Issues found in unchanged code that cannot receive inline comments:

File Line Issue
packages/kilo-vscode/src/agent-manager/continue-in-worktree.ts 162 forkSession failure on line 162 leaves the worktree in a built-but-orphaned state. When forkSession fails (e.g. backend connectivity issue), continueInWorktree calls progress("error") but does NOT call cleanupWorktree or notifyError. This means: (1) the worktree branch/checkout persists on disk, and (2) the Agent Manager webview never receives the terminal agentManager.worktreeSetup error event, so it continues to treat the worktree as "busy" — the same class of bug this PR fixes for git transfer failures. Consider applying the same rollback pattern to forkSession failures, or document why orphaned worktrees from fork failures are intentional and recoverable.
Files Reviewed (4 files)
  • .changeset/move-worktrees-safely.md - good user-facing changeset
  • packages/kilo-vscode/src/agent-manager/AgentManagerProvider.ts - clean additions of cleanupWorktree and notifyError context functions
  • packages/kilo-vscode/src/agent-manager/continue-in-worktree.ts - well-structured rollback function with proper ordering (cleanup → notify → progress)
  • packages/kilo-vscode/tests/unit/continue-in-worktree.test.ts - good test using real git repos/worktrees, properly cleans up temp dirs

Fix these issues in Kilo Cloud


Reviewed by deepseek-v4-pro-20260423 · 379,801 tokens

Review guidance: REVIEW.md from base branch main

@marius-kilocode
marius-kilocode merged commit ce7ec1d into main Jun 17, 2026
23 checks passed
@marius-kilocode
marius-kilocode deleted the swamp-isthmus branch June 17, 2026 12:49
t7tran pushed a commit to t7tran/kilocode that referenced this pull request Aug 14, 2026
fix(agent-manager): clean up failed session moves
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.

2 participants