orca icon indicating copy to clipboard operation
orca copied to clipboard

SSH terminal reconnect can repeatedly spawn detached PTYs for the same pane

Open davefano opened this issue 4 months ago • 1 comments

Summary

When an SSH-backed workspace terminal drops or fails to reattach, Orca can repeatedly create replacement PTYs for the same saved terminal pane. The old PTYs become detached/orphaned, Resource Manager counts climb quickly, and eventually new terminal creation can fail with posix_spawnp failed.

This was observed in a fleet-style setup where one Orca server manages multiple SSH-backed workspaces for the same repo across different hosts.

Related: #8585 Diagnostic/mitigation PR: #9022

Environment

  • Orca production build observed around 1.4.142-rc.6
  • macOS arm64
  • Remote SSH workspaces using Orca relay
  • Same repo configured on multiple SSH hosts, each with its own project host setup

What happened

For one SSH host/workspace, the terminal pane started dropping from the UI. Each recovery/reconnect attempt appeared to create a fresh PTY instead of rebinding the existing PTY to the saved pane.

The persisted state showed hundreds of sshRemotePtyLeases, with repeated leases for the same saved pane:

  • same SSH target / connection id
  • same saved tab id
  • same saved leaf id
  • increasing PTY ids

The live graph then showed many synthetic detached terminals with ids shaped like:

pty:ssh:<ssh-target-id>@@pty-415
pty:ssh:<ssh-target-id>@@pty-416
pty:ssh:<ssh-target-id>@@pty-417
...

Eventually Orca showed a terminal creation failure:

posix_spawnp failed

Expected behavior

If Orca reconnects/restores a saved SSH terminal pane, it should either:

  1. rebind the existing live PTY to the saved renderer tab/leaf, or
  2. clearly mark the old PTY as detached and create at most one replacement, or
  3. fail visibly with a retry/close action.

It should not keep creating replacement PTYs for the same saved pane in a loop.

Actual behavior

A saved SSH terminal pane can repeatedly generate new PTYs. Superseded PTYs remain visible to runtime/resource state as detached/orphaned terminals, causing:

  • Resource Manager terminal counts to balloon
  • lost or unreachable terminal sessions
  • confusing Unattributed or detached terminal rows
  • resource pressure on the SSH host
  • eventual terminal spawn failures

Repro shape

I do not yet have a minimal clean-room repro, but the observed setup was:

  1. Configure Orca with multiple SSH-backed host setups for the same Git repo.
  2. Open terminals on those remote SSH workspaces.
  3. Restart/update Orca or cause a transient SSH relay drop.
  4. Reopen/click the affected SSH workspace terminal pane.
  5. Observe new PTYs created for the same saved tab/leaf while older PTYs become detached/orphaned.

Why this matters

In multi-host SSH usage, detached PTYs are not just cosmetic. They may contain idle shells, active agents, dev servers, or long-running jobs. If the UI loses the binding and keeps spawning replacements, users cannot tell which sessions are safe to close and can accidentally leak CPU/RAM/processes on remote hosts.

Proposed direction

The fix likely needs two parts:

  • lifecycle: when attaching a replacement PTY for the same SSH target/tab/leaf, expire superseded same-pane leases so only the current PTY remains eligible for pane restore
  • observability: Resource Manager should explicitly list detached/orphaned terminals with host, PTY id, origin tab/leaf, and safe close/reattach actions

PR #9022 adds initial diagnostics and same-pane lease expiry behavior to make the failure visible and reduce future accumulation.

davefano avatar Jul 16 '26 16:07 davefano

Closing this as fixed. #18546 found the root cause of the lease buildup: on reconnect, the pane's binding was read from a stale local copy, so the leases it replaced were never retired. Each pane now ends up with a single reattachable lease. #26088 and #26308 then tightened up how reattached SSH panes get bound and recovered. If you still see replacement PTYs piling up for one pane on a current build, please reopen with the lease counts or logs.

OrcaWin avatar Oct 09 '26 06:10 OrcaWin