fix(coding-agent): open isolated subagent sessions in worktree cwd#2626
Merged
Conversation
Persisted isolated subagents created their fresh JSONL session through SessionManager.open(), which fell back to getProjectDir() when the file had no header. createAgentSession still received the isolated worktree cwd, but built-in tools resolve paths through sessionManager.getCwd(), so file tools could target the parent repository while patch capture saw no isolated delta. Allow SessionManager.open() to take an initial cwd for empty/missing session files and pass the isolated worktree cwd from task execution. Non-empty resumes still use the persisted header cwd. Add regression coverage asserting persisted isolated subagent sessions expose the worktree cwd through their session manager.
roboomp
reviewed
Jun 15, 2026
roboomp
left a comment
Collaborator
There was a problem hiding this comment.
P0 — focused root-cause fix: persisted isolated subagent sessions now seed SessionManager.open() with the worktree cwd only for fresh JSONL files, preserving header cwd on resume.
No inline findings. Changelog and regression coverage are present for the observable sessionManager.getCwd() contract.
Thanks @bjin.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixed isolated task subagents with persisted JSONL sessions so their built-in
file tools resolve paths against the isolated worktree cwd instead of the parent
repository cwd.
This change updates the session-opening path used by isolated task execution:
SessionManager.open()now accepts an optionalinitialCwd.initialCwdis used only when the target session file is empty or missing andtherefore has no persisted session header yet.
the current cross-project resume behavior.
worktree ?? cwdas thatinitialCwdwhenopening the persisted subagent JSONL.
isolated subagent session exposes the isolated worktree via
sessionManager.getCwd().Why
rcopyisolation was creating and using the isolated worktree correctly for thesubagent process-level cwd. A probe from the failing session showed subagents
running under paths like:
However, the actual file-tool writes did not participate in isolated patch
capture. The first symptom was confusing:
No changes to apply.;<agentId>.patchartifacts were empty;applied.
The relevant code path split cwd ownership in two places:
TaskToolcreates the isolated worktree and callsrunSubprocess()withworktree: isolationDir.runSubprocess()passescwd: worktree ?? cwdintocreateAgentSession().CreateAgentSessionOptions.cwd.They resolve through
ToolSession.cwd.ToolSession.cwdis backed bysessionManager.getCwd().runSubprocess()opened the JSONL withSessionManager.open(sessionFile).SessionManager.open()fellback to
getProjectDir().That meant the prompt and some setup paths knew about the isolated worktree, but
file tools saw the parent/global project cwd through the session manager. Patch
capture then inspected the isolated worktree, found no git-visible delta, wrote
an empty patch artifact, and correctly reported
No changes to apply..This is why the fix is intentionally at the persisted-session boundary rather
than in the file tools. The file tools were already using the right abstraction:
sessionManager.getCwd()is the session cwd. The bug was that new isolatedsubagent sessions were initialized with the wrong cwd before their first header
was written.
The manual follow-up test also distinguished this root cause from a separate
untracked-file setup issue. A first retest created new arbitrary root files in an
AUR repository. Those writes stayed inside the isolated worktree after this fix,
but patch capture still produced empty patches because the files were not
visible to:
That was not the original cwd bug: the parent repository did not receive direct
writes. A second retest edited existing tracked files (
PKGBUILDand.SRCINFO), and those changes were captured and merged through non-empty patchartifacts.
Testing
Automated verification:
bun test packages/coding-agent/test/task/subagent-lsp.test.tssessionManager.getCwd()wouldremain the parent/default project cwd instead of the isolated worktree.
bun --cwd=packages/coding-agent run checkManual patched-binary validation in a separate git repository:
task.isolation.mode=rcopy;task.isolation.merge=patch;isolated: true;Applied patches: yes;~/.omp/wt/.../merged;This validates the intended end-to-end behavior: file-tool edits made by
persisted isolated subagents are captured in the isolated worktree, emitted as
patch artifacts, and merged back to the parent repository by patch mode.
bun checkpasses