Repository navigation
Description
Summary
A paired desktop client can terminate a live terminal on the host when its local remote-terminal mirror reports pty-exit (for example while retiring a stale remote PTY handle during reconnect/restore).
This destroys long-running terminal workloads such as Claude Code sessions. The affected workload does not need to be a native provider integration; the observed sessions were Claude Code processes configured to use a Grok API endpoint.
Observed behavior
- Agent sleep was disabled on the host.
- A paired client's renderer bootstrapped at
18:36:08.431local time. - The host daemon logged an explicit
session-killedfor an existing terminal at18:36:11.779, only 3.348 seconds later. - Additional mirrored terminal sessions were explicitly killed during the same paired-client activity window.
- These were
session-killedevents, not naturalsession-exitedevents.
Root cause
The renderer exit path is:
- The remote PTY transport retires/disconnects a mirrored PTY and invokes
onPtyExit. Terminal.tsxcallscloseTerminalTab(tabId, { reason: 'pty-exit' }).- For a remote-owned worktree,
closeTerminalTabprunes the local mirror and unconditionally callscloseWebRuntimeSessionTab. - The host receives
session.tabs.closeand kills the authoritative PTY.
A mirror-local pty-exit is reconciliation evidence, not user intent to close the host-owned tab. Propagating it back to the host turns stale mirror state into a destructive host action.
Relevant code:
src/renderer/src/components/terminal/terminal-tab-actions.tssrc/renderer/src/components/terminal/Terminal.tsxsrc/renderer/src/runtime/remote-runtime-pty-transport.ts
This appears related to the remote close propagation added around #8628: explicit user/cleanup closes should reach the host, but natural/mirror pty-exit must not.
Expected behavior
When a remote mirror reports pty-exit, Orca should reconcile/prune only the local mirror and wait for the authoritative host snapshot. It must not send session.tabs.close to the host.
Explicit user close and cleanup actions should continue to propagate to the host.
Regression test
A focused unit test currently fails because closeWebRuntimeSessionTab is called once for:
closeTerminalTab('local-tab-1', { reason: 'pty-exit' })The fix should make that call local-only while preserving the existing explicit-close behavior.
Activity
bbingz commentedon Jul 15, 2026
Additional forensics from a full incident analysis tonight (multi-agent code + log investigation; happy to share more detail):
1. The kill path is reachable without any remote client. The host's own daemon log shows three force-only
session-killedevents before the remote client ever connected (09:17:57, 18:00:07, 18:03:33 local that day), each preceded a few minutes earlier by creation of a replacement terminal in the same project and bracketed by host-local sidebar activity — i.e. the host renderer itself can retire a stale handle and echo the fatal close. This is a core session-lifecycle defect, not just a remote-mirror scenario.2. Direct trigger evidence for the connect-time kill. The first post-connect kill landed 3.35s after the client's
renderer_bootstrap_started, and the client's store snapshot diff shows exactly the killed tabs being dropped client-side. This matches restored mirror panes attaching with persisted handles:attach()subscribes the saved handle without re-deriving it from the current session snapshot (remote-runtime-pty-transport.ts:690-728), host handles are process-lifetime and cleared on renderer reload (orca-runtime.ts:19447-19457), and desktop clients get nowaitForLeafPtyIdgrace (rpc/methods/terminal.ts:1987-2001) — so a stale persisted handle deterministically yieldsno_connected_pty, which the transport converts into a synthesized pty-exit.3. Scope note for reviewers of #8872. The PR deliberately guards only the
reason:'pty-exit'echo incloseTerminalTab. Known residual paths, which I'd suggest treating as follow-ups rather than blockers: the storecloseTabretirement path, reasonless automatedcloseTerminalTabcallers,attach()'s persisted-handle subscribe (trigger-side), and host-side hardening (closeMobileSessionTabcould verify tab generation/expected pty before killing the live one).4. Attribution gap. None of the incident kills could be attributed to a client because the RPC context's identity fields (
ctx.clientId/clientKind/connectionId— populated atruntime-rpc.ts:1150-1155, defined atrpc/core.ts:66-77) are dropped in thesession.tabs.closehandler, and the daemon'ssession-killedlog omits the requester. I'm filing a tiny PR adding both log fields — it would have turned this investigation from inference into a one-line lookup.5. Related feedback loop.
pty-exit-reason closes never retiresleepingAgentSessionsByPaneKeyresume records, so each mirror-echo kill converts a live session into a pending duplicate resume on the next connect — filed separately with full analysis.bbingz commentedon Jul 15, 2026
Correction to point 1 of my comment above (after an independent second review of the evidence):
I'm downgrading the claim that "the kill path is reachable without any remote client." It doesn't hold up:
closeTerminalTab(reason:'pty-exit')never takes the runtimesession.tabs.closebranch (terminal-tab-actions.ts:140— that branch requires an active web-runtime session), and the storecloseTabpath performs no PTY retirement/kill at all (terminals.ts:1218). Local pty-exit handling therefore cannot produce the mirror-echo kill.immediate:true) — a different request shape from the graceful+force pairs (immediatefalse→true, milliseconds apart) that thecloseMobileSessionTabecho path produced at 19:08–19:10.Those early kills should be read as unattributed (plausibly ordinary user-initiated closes shortly before leaving the desk), not as evidence of a host-local echo path.
One honest nuance this surfaces for reviewers: the first post-connect kill (18:36:11, 3.35s after the client renderer bootstrapped, matching the client store dropping exactly that tab) is also a single force-only request rather than a graceful+force pair — so while the timing and client-store evidence still tie it to the client reconnect, the exact RPC family it traveled through is not pinned down by the current logs. That is precisely what the attribution-logging PR is for.
Points 2–5 of my earlier comment stand as written.
contextor2 commentedon Jul 15, 2026
We hit what looks like exactly this bug three times in a single session and captured clean forensics that may help — including the attribution gap noted in #8888.
Environment: Orca v1.4.141, macOS 26.2 (arm64, M4 Mac mini). Host desktop app running locally; paired remote clients (mobile scope + a second "runtime"-scope device) connecting through serve.
Incidents (local time KST = UTC+9, 2026-07-16): mass
session-killedbursts at 02:32:24, 02:42:33, and 03:02:40–41. The bursts killed the live worktree PTY sessions — 4, 7, and 7 distinct worktrees respectively (plus the serve session itself in the third burst; 10 distinct worktrees across the three bursts: Claude Code coordinator/workers, Codex, OpenCode/GLM) — predominantly withimmediate:trueindaemon.log.Key correlation: each burst coincides — within ~1 second — with a new remote-client renderer process spawning on the host (
Orca Helper (Renderer)with a fresh--renderer-client-id, accompanied by anagent-browsersidecar spawn). Process start times fromps lstart:This matches the 3.3-second bootstrap→kill correlation in the original report.
Third incident timeline (UTC):
17:58:33— serve sessionserve-7dff501ccreated (remote client connects)18:02:40— new renderer + agent-browser spawn on host (client reconnect/bootstrap)18:02:40.992–41.277— 10+ sessions killed withimmediate:true, including the serve session itself18:02:59— paired runtime-scope devicelastSeenAtupdates; killed sessions start getting recreated (with restored scrollback) immediately afterRuled out: host app and daemon PIDs were stable across all three incidents (no crash/restart), no system sleep (pmset log, AC power), no memory pressure (renderer heap ~133MB of 3.5GB limit). These were explicit
killrequests handled by the daemon, notsession-exited.Code-level observation (v1.4.141 bundle): in
closeTerminalTab,options.reason === "pty-exit"is only consulted to skip the pinned-tab confirmation; the remote-worktree branch then forwards every close to the host viasession.tabs.close, whose params carry no reason/intent field — socloseMobileSessionTabon the host cannot distinguish a stale-mirrorpty-exitreconciliation from a deliberate user close. Consistent with #8872's analysis.Until #8872 ships we're running a local host-side mitigation (a guard in
closeMobileSessionTabthat refusessession.tabs.closefor terminals currently running an agent). Happy to share rawdaemon.logexcerpts or the full timeline if useful.AmethystLiang commentedon Jul 17, 2026
will resolve this issue today
nwparker commentedon Aug 3, 2026
Closing as fixed
Verified on current tree: mirror-local
pty-exitno longer propagates a host tab close.In
closeTerminalTab(src/renderer/src/components/terminal/terminal-tab-actions.ts), when a web/runtime session is active:Unit coverage asserts
closeWebRuntimeSessionTabis not called forreason: 'pty-exit'(terminal-tab-actions.test.ts— “lets the HUB snapshot adjudicate a stream exit”).Fix PR: #9994
(
41751dd90d— introduced thereason === 'pty-exit'early-return)If anyone still sees host
session-killedfrom a remote mirror stream-exit after a build that includes #9994, please reopen with logs.