Skip to content

fix(agent-manager): resolve live managed worktree sessions - #13422

Merged
marius-kilocode merged 1 commit into
mainfrom
fix-agent-manager-worktree-ownership
Aug 27, 2026
Merged

fix(agent-manager): resolve live managed worktree sessions#13422
marius-kilocode merged 1 commit into
mainfrom
fix-agent-manager-worktree-ownership

Conversation

@marius-kilocode

@marius-kilocode marius-kilocode commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Agent Manager can display a session inside a managed worktree even though the session exists only in the live project listing and has not been recorded in persisted worktree state. Prompt, answer, and move actions previously checked only persisted state, then incorrectly failed with "The session is not managed by this Agent Manager workspace". Stop also needed the exact worktree directory, and a stopped live-only session could become authorized again after restarting VS Code.

Why This Change Was Made

Resolve live-only sessions strictly from the project context that owns the request directory, and accept them only when their worktree is already present in that project's managed state. Persisted state remains authoritative, backend directory verification remains unchanged, and unrelated roots are never searched. Stop registers the verified worktree route and persists a bounded, project-scoped closed-session record. Explicitly attaching the session again clears that record, while deleted worktrees remove their associated records.

User Impact

Prompt, answer, move, and stop work for sessions shown in managed worktrees, including secondary projects and sessions discovered through another Agent Manager surface. Unknown sessions, foreign worktrees, cross-project requests, and stopped sessions remain rejected, including after a full VS Code restart. Existing session history is not deleted or automatically persisted as managed state.

Evidence

  • Real VS Code extension instance, real kilo serve backend, real SSE orchestration, and a deterministic local OpenAI-compatible provider with no paid credentials.
  • Created a primary managed worktree and a backend session intentionally absent from .kilo/agent-manager.json.
  • Verified real agent_manager tool calls for move, prompt, answer to an actual pending question, and stop.
  • Verified genuinely foreign sessions and a session belonging to another managed project are rejected.
  • Added a second real Git project through VS Code's folder picker, created its managed worktree, and prompted its live-only session successfully.
  • Restarted the VS Code window, verified both worktrees restored, confirmed active live-only sessions still work, and confirmed stopped sessions stay rejected.
  • bun run test:unit: 4,191 passed, 0 failed across 353 files.
  • bun run typecheck, bun run lint, bun run format:check, and bun run compile: passed.

Two real Agent Manager projects with a successful prompt delivered to a live-only secondary worktree session

Comment thread packages/kilo-vscode/src/agent-manager/orchestration-setup.ts Outdated
Comment thread packages/kilo-vscode/src/agent-manager/provider-lifecycle.ts Outdated
Comment thread packages/kilo-vscode/src/agent-manager/tool-start.ts Outdated
@kilo-code-bot

kilo-code-bot Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (10 files)
  • .changeset/steady-agent-manager-ownership.md
  • packages/kilo-vscode/src/agent-manager/AgentManagerProvider.ts
  • packages/kilo-vscode/src/agent-manager/WorktreeStateManager.ts
  • packages/kilo-vscode/src/agent-manager/orchestration-bridge.ts
  • packages/kilo-vscode/src/agent-manager/orchestration-domain.ts
  • packages/kilo-vscode/src/agent-manager/orchestration-setup.ts
  • packages/kilo-vscode/src/agent-manager/state-recovery.ts
  • packages/kilo-vscode/tests/unit/agent-manager-orchestration-bridge.test.ts
  • packages/kilo-vscode/tests/unit/agent-manager-orchestration-domain.test.ts
  • packages/kilo-vscode/tests/unit/worktree-state-manager.test.ts
Previous Review Summaries (2 snapshots, latest commit fc10629)

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

Previous review (commit fc10629)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (7 files)
  • .changeset/steady-agent-manager-ownership.md
  • packages/kilo-vscode/src/agent-manager/AgentManagerProvider.ts
  • packages/kilo-vscode/src/agent-manager/orchestration-bridge.ts
  • packages/kilo-vscode/src/agent-manager/orchestration-domain.ts
  • packages/kilo-vscode/src/agent-manager/orchestration-setup.ts
  • packages/kilo-vscode/tests/unit/agent-manager-orchestration-bridge.test.ts
  • packages/kilo-vscode/tests/unit/agent-manager-orchestration-domain.test.ts

Previous review (commit e45b944)

Status: 3 Issues Found | Recommendation: Address before merge

Overview

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

WARNING

File Line Issue
packages/kilo-vscode/src/agent-manager/orchestration-setup.ts 78 Unqualified sessionDirectories hint wins over origin, breaking fail-closed for colliding ids
packages/kilo-vscode/src/agent-manager/provider-lifecycle.ts 314 Live-only worktree close falls back to project root for abort and process cleanup
packages/kilo-vscode/src/agent-manager/tool-start.ts 81 Parent registration uses lexical path compare and skips symlink/case-aliased roots
Files Reviewed (22 files)
  • .changeset/steady-agent-manager-ownership.md
  • packages/kilo-vscode/src/KiloProvider.ts
  • packages/kilo-vscode/src/agent-manager/AgentManagerProvider.ts
  • packages/kilo-vscode/src/agent-manager/WorktreeStateManager.ts
  • packages/kilo-vscode/src/agent-manager/host.ts
  • packages/kilo-vscode/src/agent-manager/orchestration-bridge.ts
  • packages/kilo-vscode/src/agent-manager/orchestration-domain.ts
  • packages/kilo-vscode/src/agent-manager/orchestration-setup.ts - 1 issue
  • packages/kilo-vscode/src/agent-manager/project/context.ts
  • packages/kilo-vscode/src/agent-manager/project/contexts.ts
  • packages/kilo-vscode/src/agent-manager/project/init.ts
  • packages/kilo-vscode/src/agent-manager/provider-lifecycle.ts - 1 issue
  • packages/kilo-vscode/src/agent-manager/tool-start.ts - 1 issue
  • packages/kilo-vscode/src/agent-manager/vscode-host.ts
  • packages/kilo-vscode/tests/unit/agent-manager-arch.test.ts
  • packages/kilo-vscode/tests/unit/agent-manager-close-session.test.ts
  • packages/kilo-vscode/tests/unit/agent-manager-orchestration-bridge.test.ts
  • packages/kilo-vscode/tests/unit/agent-manager-orchestration-domain.test.ts
  • packages/kilo-vscode/tests/unit/agent-manager-orchestration-ownership.test.ts
  • packages/kilo-vscode/tests/unit/agent-manager-tool-start.test.ts
  • packages/kilo-vscode/tests/unit/agent-project-sessions.test.ts
  • packages/kilo-vscode/tests/unit/worktree-state-manager.test.ts

Fix these issues in Kilo Cloud


Reviewed by grok-4.6 · Input: 149.5K · Output: 23.2K · Cached: 1.2M

Review guidance: REVIEW.md from base branch main

@marius-kilocode
marius-kilocode force-pushed the fix-agent-manager-worktree-ownership branch from e45b944 to fc10629 Compare August 25, 2026 19:55
@marius-kilocode marius-kilocode changed the title fix(agent-manager): resolve managed session ownership fix(agent-manager): resolve live managed worktree sessions Aug 25, 2026
@marius-kilocode
marius-kilocode force-pushed the fix-agent-manager-worktree-ownership branch from fc10629 to 83e2772 Compare August 26, 2026 12:25
@marius-kilocode
marius-kilocode merged commit 0c55eac into main Aug 27, 2026
24 checks passed
@marius-kilocode
marius-kilocode deleted the fix-agent-manager-worktree-ownership branch August 27, 2026 07:32
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