Skip to content

fix(ssh): bound retained PTY relay state on the SSH provider - #10839

Closed
nwparker wants to merge 3 commits into
oom-slice-4-daemon-admissionfrom
oom-slice-5-ssh-pty
Closed

nwparker wants to merge 3 commits into
oom-slice-4-daemon-admissionfrom
oom-slice-5-ssh-pty

Conversation

@nwparker

@nwparker nwparker commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Slice 5 of the re-landed OOM work. Stacked on #10837 (slice 4) — review the diff against oom-slice-4-daemon-admission, not main.

ELI5

When you run terminals over SSH, the app keeps a little bookkeeping note for each one — where it is, how much output it still owes you. The notes were filed under names the remote machine picks. Nothing limited how many names it could invent, so the filing cabinet could grow forever.

Now there's a cap on how many notes are kept, and how long a name is allowed to be. The tricky part: one of those notes is "how much more output am I allowed to send you." Throwing that note away would leave the remote side waiting forever for permission — your terminal would just freeze. So when a note gets evicted, its permission is handed back first.

What this fixes

Retained state Keyed by Before After
Flow-control credit states relay PTY id (remote-supplied) unbounded 256 states
Credit segments per delivered chunk unbounded 4096/state, 16384 total
Aggregate credit-state id bytes — unbounded 512 KiB
Live PTY roster rows app PTY id unbounded 256 rows
Aggregate roster id bytes — unbounded 2 MiB
Relay ids / app ids / delivery tokens — any length 4 KiB / 16 KiB / 1 KiB, screened for unsafe chars

Two independent growth paths existed: a remote host cycling PTY ids, and a connection that repeatedly missed exit notifications (each miss left a roster tombstone).

The UX risk, and how it's handled

This is the slice where a naive bound would trade a crash for a freeze. Two deliberate design points:

Evicted credit is returned, not dropped. Flow-control credit is the remote's permission to keep sending. Silently discarding it stalls the producer and hangs the terminal. removeState(..., returnOutstanding: true) acknowledges the outstanding chars upstream before dropping the state.

Roster eviction prefers dead entries. The cap scans for an exited entry first and only displaces the oldest live row if all 256 are live — well beyond any real session count.

Proof of no regression

  • 2,765 tests pass across src/main/providers, src/main/daemon, and src/main/ssh; node typecheck and lint clean.
  • Ordering, fencing, and grace-period behavior are covered by pre-existing roster tests that still pass — stale listings can't resurrect an exited PTY, an in-flight listing can't evict a live one, and a locally spawned PTY still gets its one-listing grace.

Mutation-tested

Every cap was deliberately broken to confirm the tests actually catch it:

Mutation Result
Eviction drops outstanding credit instead of returning it 2 tests fail
Credit-state cap disabled 3 tests fail
Credit-segment cap disabled 1 test fails
Roster eviction ignores liveness 1 test fails
Subscriber's ingress id check removed 4 tests fail

That last one is worth calling out. PTY notification routing moves onto the provider's own subscriber (screening ids at ingress rather than after mapping them), which leaves the previous routing module with no importers. Its existing hardening test would still pass while asserting against code nothing calls — so the contract was carried onto the live subscriber. An earlier version of that test used only pty.data and survived the mutation, because pty.data is independently screened downstream by the credit layer; it now covers pty.replay and pty.exit too, which is what makes the mutant fail.

User-facing behavior changes

None expected. Every ceiling sits far above real usage, and the two paths where a bound could have degraded UX (frozen terminal, dropped live session) are explicitly designed against and mutation-tested.

Made with Orca 🐋

The SSH PTY provider retained per-PTY state keyed by ids the remote host
supplies, with no ceiling on how many distinct ids it would hold:

- Renderer flow-control credit accumulated one state per relay id, and one
  segment per delivered chunk within each state.
- The live PTY roster accumulated one row per app PTY id, including tombstones
  for exits, so repeated missed exits grew it without bound.
- Relay ids and delivery tokens were retained at whatever length arrived.

A remote host cycling ids — or a connection that repeatedly misses exit
notifications — could grow main-process memory indefinitely.

This adds a shared wire-admission check (ids and delivery tokens screened for
length in UTF-8 bytes and unsafe characters before anything retains them), plus
ceilings on credit states, credit segments per state and in aggregate, roster
entries, and aggregate retained id bytes.

Bounding flow-control credit is the risky part: silently dropping credit would
stall the producer and freeze a terminal rather than crash it. Eviction
therefore returns any outstanding credit upstream, so the remote resumes
sending. Roster eviction prefers exited entries over live ones, so a live PTY is
only displaced when the roster is genuinely full of live sessions.

PTY notification routing moves onto the provider's own subscriber, which also
screens ids at ingress rather than after mapping them.

Tests: verified by mutation. Making eviction drop outstanding credit instead of
returning it fails 2 tests; disabling the state cap fails 3; disabling the
segment cap fails 1; making roster eviction ignore liveness fails 1; and
removing the subscriber's ingress id check fails 4. Full main-process PTY
surface (2,765 tests across providers, daemon, and ssh) passes.
@nwparker
nwparker force-pushed the oom-slice-4-daemon-admission branch from 87097b4 to 97c07e6 Compare July 27, 2026 06:20
@nwparker
nwparker force-pushed the oom-slice-5-ssh-pty branch from 4f7d675 to 2d70a4a Compare July 27, 2026 06:20
@OrcaWin

OrcaWin commented Oct 11, 2026 •

Copy link
Copy Markdown
Collaborator

SSH still works: Orca connects to the host over SSH and routes workspace operations through the managed remote Orca server (orcad). These merges remove the legacy SSH relay, not SSH support.

Closing as obsolete after the merged SSH relay retirement in #27214 and #27215. This PR concerns the SSH relay PTY attach, recovery, replay, or lease lifecycle. #27214 removed the desktop relay connection/fallback path; #27215 deleted the SSH relay server, deployment assets, and relay-only tests. SSH hosts now use the managed Orca server (orcad), and unsupported hosts fail explicitly, so this relay-specific work is no longer planned. This closes the proposed relay implementation; it does not claim that any independent local, WSL, or managed-server behavior was fixed.

@OrcaWin OrcaWin closed this Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants