Repository navigation
Closed
Labels
Description
Problem
Two SSH sessions on the same machine:
- SSH session A runs
maka tuiand starts a long-running task (a Turn is in flight). - SSH session B opens a second
maka tuiand — via the session picker or/resume— switches to the Session that is busy in A. - TUI B attaches to the in-flight Turn (
switchSessionreturnsactiveTurn; the runner starts anattachedturn view, soturnRunning = true).
From that moment TUI B is trapped, and every way out is destructive:
/session(and any other known slash command except/goaland/recap, per fix(cli): stop steering known slash commands into a running turn #3310) is intercepted:Cannot run /session while a turn is running — interrupt it (Esc) or wait for it to finish.— so you cannot switch away.- Following that hint (double
Esc) or pressingCtrl+Cmid-turn callsrequestTurnInterrupt()→driver.stop()→ hostturn.stopRPC, which aborts the shared long task for both clients. - Even quitting TUI B is destructive:
exitmid-turn / doubleCtrl+C/SIGINT/SIGHUPall reachbeginClose(), which callsdriver.stop()when no interrupt is in flight — killing the Turn that TUI A is watching.
The only non-destructive escape is kill -9 of the TUI B process.
Root cause (code-confirmed, packages/cli/src)
runtime-host-session-driver.tsswitchSession(L436+) intentionally attaches to a Session with a live Turn and hands backactiveTurn— multi-client reattach is a supported pattern, so attaching is not the bug.pi-tui-runner.tseditor.onSubmit(L1099–L1116) refuses every known slash command whileturnRunning, including/session— the one command that would let the second TUI leave.pi-tui-runner.tsmid-turnCtrl+C(L3055) / doubleEsc(L3063) →requestTurnInterrupt(L779) →input.driver.stop()(L798);runtime-host-session-driver.tsstop()(L619) issuesturn.stopfor the Session's root Turn regardless of which client started it.pi-tui-runner.tsbeginClose(L695) also callsdriver.stop()on quit, so there is no detach-only close path.
Proposed direction: let /session switch away mid-turn (detach, not interrupt)
An attach mutex/lease was considered and rejected: multi-client attach is a designed Runtime Host capability (turns started by another client or the Host are meant to be observable), and leases bring stale-lock/heartbeat complexity.
Instead, extend the #3310 pattern — which let /goal and /recap run mid-turn because they are independent of the running turn — to /session:
- Switching away is turn-independent: in Runtime Host mode the Turn is host-driven, so the TUI is only a view. Detaching the view does not touch the Turn.
- Mechanically feasible today:
driver.switchSessionrequires no idle state, and#replaceChannel→channel.close()finishes every per-turn event queue (runtime-host-session-channel.tsL276), which ends the attached turn's drain loop inrunAgentTurnand resetsbusy/turnRunningcleanly. - The Turn (and any host-driven Goal continuation) keeps running; switching back later re-attaches via the existing
activeTurnpath.
Implementation notes / scope:
- Exempt
sessionfrom the mid-turn interception ineditor.onSubmit; open the picker whileturnRunning. - On selection, run the switch without
driver.stop(); add a runner-side generation fence so late events from the abandoned turn cannot render into the new Session's transcript. - Minimal scope: allow switch-away only when the running turn is an attached (externally started) turn — the reported trap. Allowing it for self-started turns (queued-followup/fallback flush,
interruptRequestedstate) can be a follow-up. - Interrupt semantics for foreign Turns are accepted as-is: any attached Client may stop the Turn (single-operator model — the "other client" is usually the same user). No ownership-aware interrupt is planned.
Related: #3310 (mid-turn slash-command interception), #3347 (config changes mid-turn, desktop).
Activity
me2seeks commentedon Aug 21, 2026
I'm working on this issue.
fix(cli): let /session detach from a running Turn instead of trapping…
fix(cli): fence mid-turn detach against re-entry and in-flight callbacks
fix(cli): let /session detach from a running Turn instead of trapping…
chore(nsh): sync upstream through a901baa2e (0.7.2)
chore(nsh): sync upstream through a901baa2e (0.7.2)
chore(nsh): sync upstream through a901baa2e (0.7.2) (#7325)