Skip to content

fix(cli): restore subagent isolation in session forks - #11000

Merged
marius-kilocode merged 1 commit into
mainfrom
airy-becklespinax
Jun 8, 2026
Merged

fix(cli): restore subagent isolation in session forks#11000
marius-kilocode merged 1 commit into
mainfrom
airy-becklespinax

Conversation

@marius-kilocode

Copy link
Copy Markdown
Collaborator

Session forks can retain task-part references to the source session's subagent sessions. Continuing a copied task then runs the original child session, so activity, permission prompts, and state can leak between the source and fork. This affects every editor flow using the generated SDK fork endpoint, including the sidebar, Agent Manager LOCAL sessions, Agent Manager worktrees, and Continue in Worktree.

The isolation behavior originally introduced in #8956 regressed in two migrations:

  • daaa2e5911 introduced the Effect HttpApi lifecycle handler and called the raw Session.Service.fork() operation directly. That bypassed the Kilo wrapper responsible for cloning and remapping task child sessions.
  • e4c9b4363e converted the remapper to Effect services but lost the graph-wide source-to-copy map, its root seed, and the cyclic-session regression coverage. Self-references and cycles were no longer safely remapped.

This restores isolation at the shared server boundary used by editor clients. The HTTP fork wrapper now remaps task child-session references after creating the root fork, while direct CLI forks retain the same behavior. A single graph-wide map is seeded with the source and copied roots, reused through recursive child forks, and used to rewrite task metadata. This makes each referenced subagent independent, deduplicates repeated references, and terminates self-referential or cyclic graphs.

Regression coverage now exercises the generated SDK against the real HTTP route used by Agent Manager, and restores nested, self-referential, and cyclic session graph cases. A patch changeset records the restored user-facing behavior.

@marius-kilocode
marius-kilocode enabled auto-merge (squash) June 8, 2026 11:08
@kilo-code-bot

kilo-code-bot Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

The fix correctly restores subagent isolation at both the HTTP boundary (forkRaw) and the CLI path (kiloSessionFork). The graph-wide remapped map is seeded with the [sourceID → forkedID] pair before recursive remapping, which correctly handles self-referential and cyclic session graphs, and deduplicates repeated references.

One non-blocking observation (not in diff):

In fork.ts:51, the guard if (remapped.size === 0) return is now dead code for all callers — the map is always pre-seeded with at least one entry. It's harmless (the update loop handles the empty-refs case via continue), but the log on line 69 will always report count >= 1 even when no children were actually copied (just the seed entry). Not a bug, just slightly misleading. Consider removing the guard and adjusting the log to track actual forks rather than map size, in a follow-up.

Files Reviewed (5 files)
  • .changeset/isolate-forked-subagents.md
  • packages/opencode/src/kilocode/server/httpapi/session-fork.ts
  • packages/opencode/src/kilocode/session/fork.ts
  • packages/opencode/src/kilocode/session/index.ts
  • packages/opencode/test/kilocode/session-fork-remap.test.ts

Fix these issues in Kilo Cloud


Reviewed by claude-4.6-sonnet-20260217 · 683,735 tokens

Review guidance: REVIEW.md from base branch main

@marius-kilocode
marius-kilocode merged commit 741b00f into main Jun 8, 2026
23 of 25 checks passed
@marius-kilocode
marius-kilocode deleted the airy-becklespinax branch June 8, 2026 11:36
t7tran pushed a commit to t7tran/kilocode that referenced this pull request Aug 14, 2026
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