Skip to content

[Bug]: ssh terminal state lost after >5min Orca disconnect #2248

Closed

Description

@BradleyGoulding

Operating system

macOS

Orca version

previous release before 1.4.5 - 1.4.2/3?

Details

Summary

When the Orca client stays disconnected from the remote for longer than the relay daemon's --grace-time 300 (i.e. >5 minutes), the daemon exits cleanly on its own, killing every pseudoterminal it was managing and all the processes inside those ptys. When Orca later reconnects (whether automatically or by user clicking reconnect), tabs are restored as UI elements showing green/connected, but the pty session inside each tab is brand new — prior shells have exited, scrollback is gone, any running tool (e.g. an interactive process like claude, vim, a build) is dead.

This isn't an error — the daemon's exit is documented behaviour of --grace-time. The bug is that the daemon's grace-time is shorter than common disconnect durations (Mac sleep, lid close, network drop while moving between locations, etc.), and there's no recovery path that survives.

Why this matters

The disconnect trigger is user-routine: closing the laptop lid, sleeping the Mac, walking from one office to another, switching WiFi. Any of these can cross the 5-minute threshold trivially. The cost is "all the in-progress work in every Orca terminal" each time — measured in minutes-to-hours of re-doing things.

What's actually broken

The disconnect itself isn't the bug — disconnects are fine, they happen. The bug is that the relay's failure mode for "client disconnected for a while" is exit cleanly and SIGHUP everything, with no mechanism by which a returning client can re-attach to existing ptys.

A tmux-style daemon that kept ptys alive across client absences, or a longer/configurable grace-time, or detaching pty children from the daemon process group, would all solve this. Any of those would convert the user pain from "lose all work" to "click reconnect."

Environment

  • Orca remote-helper version: 0.1.0+8ed91fb74fa0 (post-update, current)
  • Remote: Ubuntu Noble (24.04), aarch64
  • Client: macOS, Orca app version current as of 2026-05-18
  • Disconnect mechanism in reproduction: Mac sleep via lid close on battery + drive between locations (~28 minutes elapsed)

Reproduction steps

Concrete repro path — anyone with Orca + a remote can run this:

1. In Orca, connect to a remote you control.
2. Open a new terminal tab.
3. Start something with visible state — easiest is to print
   distinctive output:
      echo "==== before disconnect ===="
      date
      sleep 36000     # any long-running thing
   Or start `claude` / `vim` / a build / anything with internal state.
4. SSH to the remote in a SECOND, SEPARATE terminal (NOT through Orca):
      ssh user@remote
   Note the running processes:
      pgrep -af relay.js
   You'll see one `relay.js --detached --grace-time 300 ...` daemon
   and one `relay.js --connect ...` client. Save those pids.
5. Disconnect Orca for >5 minutes. Multiple ways:
      a. Sleep the Mac for >5min:
            sudo pmset schedule wake "$(date -v+7M "+%m/%d/%y %H:%M:%S")"
            sudo pmset sleepnow
      b. Kill the network on the Mac side for >5min.
      c. Force-quit Orca and wait >5min before reopening.
   Any one suffices.
6. From the SECOND ssh session (outside Orca), confirm what happened
   to the daemon:
      pgrep -af relay.js
   You should see NOTHING after about 5 min of Orca being away.
      cat ~/.orca-remote/relay-*/relay.log
   The last line will be:
      [relay] Process exiting with code 0
7. Reconnect Orca (auto or manual click — same outcome).
8. Look at the tab from step 3.

Expected behaviour

  • Tab is restored with its prior pty session. The output from step 3 is still in the scrollback. The sleep 36000 (or claude, or vim, or your build) is still running. You can interact with it.

Actual behaviour

  • Tab is restored as a new pty.
  • Prior process is gone (the shell that hosted it received SIGHUP when the daemon exited and the controlling terminal went away).
  • Scrollback: anything Orca's client had buffered locally before the disconnect may be visible; anything emitted during the disconnect is permanently lost; the new pty starts fresh.
  • The tab's UI status shows green/connected, masking the fact that the underlying session was completely replaced.

Verbatim evidence

Captured live during a real user disconnect cycle (28-minute return drive — Mac asleep, lid closed, network change at venue):

Server-side state at the moment of Mac wake, before user touched anything (auto-captured by an instrumentation heartbeat script that detected the >90s wall-clock gap caused by OrbStack pausing the VM along with the host):

=== wake gap detected: 1693s ===
=== prev tick: 2026-05-18T12:52:02+02:00 ===
=== this tick: 2026-05-18T13:20:15+02:00 ===

=== relay processes (pgrep -af relay.js) ===
(no relay.js processes running)

=== SSH-server-side activity (pgrep -af sshd) ===
278 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups
(no sshd user sessions)

=== last 50 lines of relay.log ===
ORCA-RELAY v0.1.0 READY
[relay] Handshake OK from version=0.1.0+8ed91fb74fa0
...
[relay] Process exiting with code 0    ← daemon cleanly exited
                                          during the disconnect

The box was network-reachable the entire time — verified independently with ping from the Mac (0% loss, sub-2ms latency). The disconnect on Orca's side was real but the network was not the failure point.

Server-side state immediately after the user clicked "reconnect":

=== relay processes (pgrep -af relay.js) ===
163776 /usr/bin/node relay.js --detached --grace-time 300 ...
163798 /usr/bin/node relay.js --connect ...

=== last 50 lines of relay.log ===
ORCA-RELAY v0.1.0 READY
[relay] Handshake OK from version=0.1.0+8ed91fb74fa0

(Note: only 2 lines — the new daemon opens its log in write-mode, so the previous daemon's history is gone. The new pty is brand new.)

Client-side observation: a tab that pre-disconnect was running claude now showed "claude has exited" but the tab itself was green and looked normal. Running claude --continue recovered the conversation (Claude state is on disk by design) — but for any non-Claude long-running process (a build, vim, ssh forward, anything without on-disk state) the work would just be gone.

Root cause

The relay.js --detached --grace-time 300 argument means "if no --connect client has been attached for 300 seconds, the daemon exits cleanly." This is documented and intentional behaviour — daemons shouldn't hang around forever after their client is gone.

The problem is that when the daemon exits, it takes its child ptys with it (they're in its process group / their controlling terminal is the daemon's). Every shell and every process inside those shells receives SIGHUP and exits. There's no other process keeping them alive.

When Orca's reconnect spawns a new daemon, that daemon has no knowledge of the previous ptys (which are dead anyway) and no mechanism to re-attach the user's tabs to anything. So tabs become fresh shells.

Suggested fixes (ranked, not exhaustive)

  1. Make --grace-time configurable and default it higher. 300 seconds is shorter than common user behaviour (closing lid, walking between rooms, network roaming). A value of e.g. 1 hour would convert the most common pain cases to no-ops. If users want aggressive cleanup, they can tune it down.

  2. Detach pty children from the daemon's process group. Re-parent them to init (setsid + double-fork pattern, or systemd-managed sessions) so they survive the daemon's exit. The next daemon can re-attach via the existing pty fds (held by a stable parent or addressable via a socket dir).

  3. Persist pty session state to disk so that a returning client can re-attach across daemon respawns. This is what tmux/screen do; would be a bigger architectural change.

  4. Disconnect-time warning in the UI so users know to wrap their work in tmux before disconnecting. Cheapest, doesn't actually fix the bug, but at least warns rather than silently destroying work.

Workaround we currently use

tmux on the remote for anything non-Claude:

# Inside any Orca terminal:
tmux new -s work
# ... do work inside the tmux session ...
# After a reconnect-with-dead-session, in a fresh tab:
tmux attach -t work

For Claude specifically: claude --continue in the same cwd restores the conversation completely, which makes Issue #2's impact on Claude-centric workflows close to zero. (Claude's on-disk state preservation is doing the right thing here.) But this doesn't help with anything else.

Why disconnect trigger doesn't matter

We initially suspected the bug was tied to network-stack changes during Mac sleep (loopback drops, different WiFi on wake, etc.). Testing today shows the trigger is irrelevant: any disconnect long enough for the grace-time to fire produces the same outcome. Verified by:

  • 7.5-minute Mac sleep, same WiFi, same dock: daemon survived (under grace-time), recovered cleanly. No bug.
  • 28-minute Mac sleep with location/WiFi change: daemon timed out, all ptys died, bug fully reproduced.

The grace-time is the threshold. Network changes are a coincidence — they make disconnects more likely to cross 5 min in practice, but they're not causally involved.

Activity

  1. added
    bug
    on May 18, 2026
  2. added
    os:macos
    on May 18, 2026
  3. AmethystLiang commented on May 18, 2026

    @AmethystLiang
    Contributor

    thx for reporting. will get it resolved in today's release

  4. changed the title [-][Bug]: Terminal state lost after >5min Orca disconnect[/-] [+][Bug]: ssh terminal state lost after >5min Orca disconnect[/+] on May 18, 2026
  5. added
    wip
    on May 18, 2026
  6. removed
    wip
    on May 18, 2026
  7. Jinwoo-H commented on May 18, 2026

    @Jinwoo-H
    Contributor

    Thanks for reporting this. I opened #2274 to address it.

    The fix changes the SSH relay lifecycle so a normal disconnect keeps the remote relay alive much longer by default, which means reconnecting to the same SSH target should preserve remote terminal state instead of dropping it after a short idle window. It also adds an explicit reset control for cases where the remote relay does need to be force-stopped.

    You can also now set your relay grace period to 0 so it stays alive indefinitely
    Image

  8. added theissue type on Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugos:macos

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions