fix(ui): close the outgoing ConPTY pane on merge-helper handoff

Each handoff tile is a live claude process with the full mcp__claudedo__* surface; leaving the
outgoing phase's pane open leaked one process per phase. Close it via CloseConPtySession before
opening the next phase's tile, restoring the one-pane-per-TaskId invariant so
OpenConPtySessionAsync's dedupe and OnPaneSubmitForReview can go back to FirstOrDefault.
This commit is contained in:
mika kuns
2026-08-11 16:55:25 +02:00
parent 79b35801ae
commit e343baf21a
3 changed files with 73 additions and 14 deletions
@@ -153,9 +153,9 @@ public sealed partial class MissionControlViewModel : ViewModelBase, IDisposable
public async System.Threading.Tasks.Task OpenConPtySessionAsync(string taskId)
{
if (string.IsNullOrEmpty(taskId)) return;
// A merge-helper handoff can leave more than one pane for this TaskId (the outgoing phase's
// frozen tile plus the active one) -- LastOrDefault resolves to the newest/active pane.
if (ConPtySessions.LastOrDefault(s => s.TaskId == taskId) is { } existing)
// One pane per TaskId is an invariant -- a merge-helper handoff closes its outgoing pane
// before opening the next phase's (see OpenMergeHelperHandoffConPtySessionAsync).
if (ConPtySessions.FirstOrDefault(s => s.TaskId == taskId) is { } existing)
{
FocusedPane = existing;
return;
@@ -284,18 +284,21 @@ public sealed partial class MissionControlViewModel : ViewModelBase, IDisposable
}
// List-handler handoff: the running session called handoff_list_handler at the end of a phase.
// Opens a NEW tile for the SAME handler task id to carry out nextPhase, and deliberately leaves
// the outgoing tile open -- it still shows that phase's finished output, which the wait/merge
// chain can run through several times for one handler task. ConPtySessions can therefore hold
// more than one pane per TaskId from here on; lookups that mean "the current/active session for
// this task" (OpenConPtySessionAsync's dedupe, OnPaneSubmitForReview) use LastOrDefault so they
// resolve to the newest tile rather than a frozen earlier phase. No new task is created here;
// see InteractiveLaunchSpecService.BuildForMergeHelperHandoffAsync.
// Opens a NEW tile for the SAME handler task id to carry out nextPhase. Each tile is a live
// `claude` process with the full mcp__claudedo__* surface, so the outgoing phase's pane is
// closed first -- it was only ever told to end its turn, never to exit, and a multi-phase run
// would otherwise leave one live process per phase behind. This keeps the one-pane-per-TaskId
// invariant intact, so OpenConPtySessionAsync's dedupe and OnPaneSubmitForReview can keep using
// FirstOrDefault. No new task is created here; see
// InteractiveLaunchSpecService.BuildForMergeHelperHandoffAsync.
public async System.Threading.Tasks.Task OpenMergeHelperHandoffConPtySessionAsync(
string taskId, IReadOnlyList<string> survivingTaskIds, string nextPhase)
{
if (string.IsNullOrEmpty(taskId) || survivingTaskIds is not { Count: > 0 }) return;
foreach (var stale in ConPtySessions.Where(s => s.TaskId == taskId).ToList())
CloseConPtySession(stale);
var baseTitle = Loc.T("missionControl.mergeHelperTitle");
var title = baseTitle + Loc.T("missionControl.mergeHelperHandoffTitleSuffix");
try
@@ -342,9 +345,9 @@ public sealed partial class MissionControlViewModel : ViewModelBase, IDisposable
// SubmitTaskForReviewAsync calls, with the loser flashing a spurious footer error.
private async void OnPaneSubmitForReview(string taskId)
{
// See OpenConPtySessionAsync -- LastOrDefault resolves to the newest/active pane when a
// merge-helper handoff has left an earlier phase's frozen tile in place for this TaskId.
if (ConPtySessions.LastOrDefault(s => s.TaskId == taskId) is not { } pane || pane.IsSubmitPending)
// See OpenConPtySessionAsync -- one pane per TaskId is an invariant, so FirstOrDefault is
// always the current/active pane for this task.
if (ConPtySessions.FirstOrDefault(s => s.TaskId == taskId) is not { } pane || pane.IsSubmitPending)
return;
pane.IsSubmitPending = true;