Skip to content

fix(pty): stop a relay leaking its own pane identity into every pane it spawns - #17257

Closed
brennanb2025 wants to merge 2 commits into
fix/unmanaged-omp-status-extensionfrom
brennanb2025/pane-identity-env-leak
Closed

brennanb2025 wants to merge 2 commits into
fix/unmanaged-omp-status-extensionfrom
brennanb2025/pane-identity-env-leak

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​293 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​293
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​38 $\color{#cf222e}{\Huge{\mathbf{−}}}$​17 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​21

Stacked on #17243. Base: fix/unmanaged-omp-status-extension.

What broke

The relay builds every PTY's environment from its own process.env, stripping only build-mode keys:

// src/relay/pty-handler.ts — buildSpawnEnv()
...stripInheritedBuildModeEnv(process.env),

A relay is routinely started from an Orca pane. So that pane's identity quadruple —
ORCA_PANE_KEY, ORCA_TAB_ID, ORCA_WORKTREE_ID, ORCA_AGENT_LAUNCH_TOKEN — was already sitting in the
relay's process.env and rode into every pane the relay spawned, fresh or revived.

ORCA_AGENT_LAUNCH_TOKEN is the damaging member. It is Orca's only in-band proof of authorship, and the
retired-pane status fence is keyed on it. One leaked token let any pane on the relay satisfy a fence a
different pane had set.

The daemon PTY host already scrubbed exactly these four keys. The relay never did.

The fix

Hoist the daemon's existing scrub into src/shared/pane-identity-env.ts and give the relay the same call,
rather than writing a second copy that can drift again:

removeUnspecifiedPaneIdentityEnv(result, rendererEnv)

A key the spawn explicitly named is left exactly as given; only keys arriving by inheritance are
dropped. Both the spawn and revive paths funnel through buildSpawnEnv, so the single insertion covers
both.

ELI5

Think of each terminal pane as a person wearing a name badge.

The relay is the receptionist who prints badges for everyone who walks in. But the receptionist was
themself hired through the same door, and never took their own badge off — so every badge they
printed came out with their name already on it.

Most of the badge is harmless: a wrong desk number. But one line on it is the signature proving "Orca
personally hired this person," and everyone downstream trusts that signature. So every pane the relay
created walked around holding someone else's signature, and could open a door that had been locked
specifically for that other person.

This makes the receptionist take their own badge off before printing anyone else's.

What a user could actually have seen

Setup: you run Orca over SSH, and you start the relay from inside an Orca agent pane — the normal way.
You're already in Orca, you open a terminal, you bring the remote host up from there. That pane had an
agent in it, so it carries a launch token.

Before

  1. Your agent pane finishes and is retired. Orca sets the retired-pane fence on it, keyed to that pane's
    launch token — "ignore further status posts from this launch."
  2. You open a brand-new, unrelated remote pane on that relay. It inherits the retired pane's token.
  3. That new pane now presents the retired pane's proof of authorship. It matches the fence.
  4. The new pane's agent status is silently suppressed — the sidebar shows nothing, or shows the dead
    agent's last state. You restart the pane and it stays wrong, because the token is re-inherited on every
    spawn. Every pane on that relay shares one identity.

There is no error message. It reads as "remote agent status is just flaky over SSH."

After

Each remote pane is spawned with only the identity that spawn was actually given. It carries no token it
did not earn, does not match another pane's fence, and reports its own status.

Ratchet

34 non-test source files name ORCA_AGENT_LAUNCH_TOKEN and 10 actually author it, but nothing stated the
rule that produces it. Two paths shipped without it — the detached-pane restart (#17243) and this one —
and each was found by accident. src/shared/pane-identity-env-spawn-inventory.test.ts now forces every
pane-identity env site to be classified deliberately as one of mints-token / propagates-token /
no-agent-launch / strips-identity, so a new site cannot silently join the broken half.

Verification

pnpm tc exit 0, 0 error TS lines, run in the foreground. Gate proven non-vacuous: planting
const __tcProbe: number = "not-a-number" gives exit 1 / TS2322.

Blast-radius suite (src/relay src/main/daemon src/shared src/main/ipc/pty src/main/providers src/main/pty):
1,056 files / 11,291 tests. The single red is remote-runtime-shared-control-connection.test.ts (E2EE
handshake) — it references none of the changed files, is a real socket-server test, and passes 28/28 in
isolation
on a quiet machine. Not attributable to this PR.

oxlint and oxfmt --check both exit 0.

Both scrubs are pinned

Deleting the daemon's scrub reddened 0 tests before this work — the behaviour this fix copies was itself
entirely unpinned. Ablations run serially, by deleting the branch (not true &&), with the file hash
compared before/after and the tree restored and verified clean between runs:

Ablation Reds Which
baseline 0 / 23 pass —
delete relay scrub 3 1 behavioural + 2 ratchet
delete daemon scrub 4 2 behavioural + 2 ratchet

The daemon ablation reddens two behavioural tests, not just the source-text ratchet — the 0-red hole is
closed, and each host fails when its own scrub is removed.

Surface

There are three user-pane PTY spawn hosts:

  1. Local / main — src/main/ipc/pty/ipc/spawn-env.ts validates the pane key against the spawn's own
    tab+leaf and deletes all four on mismatch. Already correct.
  2. Daemon — spawn-environment.ts. Already correct; now shares the hoisted module.
  3. Relay — pty-handler.ts. Was the only one with no scrub at all. Fixed here.

The scrub runs after the env augmenters; neither production augmenter writes a pane-identity key, so it
cannot delete a legitimately-authored value.

SSH / wire compatibility

No new field and no new stream opcode, so nothing here needs capability negotiation. But scrubbing an env
var changes what the host publishes, which reaches old clients with no wire change:

  • New client ↔ new relay — identity the renderer explicitly names survives; only inherited identity is
    dropped.
  • Old client ↔ new relay — a client that names the keys keeps them; one that does not now gets panes
    carrying no token where they previously carried the relay's leaked one. The leaked value was always the
    wrong pane's, so nothing correct breaks.
  • New client ↔ old relay — the leak persists. The fix lives on the execution host, so it only takes
    effect once the remote relay is upgraded; a client-side update alone changes nothing.

The fix is pure TypeScript (Object.hasOwn + delete) and depends on no patched module, so unlike a
node-pty patch it does reach a relay running stock node-pty. No process-liveness verdict is introduced, so
live / unverifiable / exited are untouched.

Scope: what this does not fix

Two status-fence defects in src/main/agent-hooks/server.ts are not resolved here and need separate
work — they are fence semantics, while this PR is env construction in the PTY hosts:

  • Retired-pane token fence (:1246 here; :1206 on main). A tokenless process in a fenced,
    non-retired pane is permanently suppressed, because the only re-fence path requires a token. Note this PR
    makes it more reachable: pre-fix every pane on a relay shared the one leaked token, so posts
    accidentally matched whatever fence was set — the leak was masking this gate.
  • Relay spool replay fence (:2423 here; :2338 on main). This PR removes a source of false matches
    feeding it, but the gate still fails open when no hydrated hash exists.

Related

#10188 is the same shape of bug (inherited env markers leaking into spawned PTYs) and touches
src/relay/pty-handler.ts and the daemon PTY subprocess as well. Different key set, so not a duplicate, but
a textual conflict is likely for whichever lands second.

@greptile-apps

greptile-apps Bot commented Aug 29, 2026 •

Copy link
Copy Markdown

Greptile Summary

The PR centralizes pane-identity environment scrubbing and applies it to relay-created PTYs so inherited host identity does not leak into spawned or revived panes.

  • Adds a shared helper and pane-identity key list used by daemon and relay PTY hosts.
  • Adds behavioral coverage for inherited identity removal on daemon spawn and relay spawn/revive paths.
  • Adds an inventory ratchet classifying production sites that mint, propagate, or strip agent launch tokens.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
src/shared/pane-identity-env.ts Defines the shared pane-identity key set and removes identity values not explicitly supplied by a spawn.
src/relay/pty-handler.ts Scrubs inherited pane identity while constructing environments for relay spawn and revive operations.
src/main/daemon/pty-subprocess/spawn-environment.ts Replaces the daemon-local implementation with the shared identity scrub without changing its contract.
src/relay/pty-handler-revive.test.ts Verifies that relay spawn and revive paths remove inherited identity while retaining explicitly supplied pane identity.
src/main/daemon/pty-subprocess/spawn-environment-pane-identity.test.ts Adds daemon coverage for inherited identity removal and preservation of explicitly supplied keys.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  H[Relay or daemon process.env] --> M[Build child PTY environment]
  E[Explicit spawn environment] --> M
  M --> S[Remove inherited pane identity keys]
  S --> P[Spawn or revive PTY]
  E -->|Explicit identity keys survive| P
Loading

Reviews (4): Last reviewed commit: "test(pty): state the ratchet's own scann..." | Re-trigger Greptile

throw new Error(`String scanner desynchronized while inventorying ${path}`)
}
// Why the decommented+blanked read: a mention inside a comment or an emitted shell snippet
// is not this file authoring pane identity.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 String keys bypass inventory

The scan blanks string contents before searching for ORCA_AGENT_LAUNCH_TOKEN, so a computed assignment such as env['ORCA_AGENT_LAUNCH_TOKEN'] = token passes without classification. This leaves the ratchet unable to enforce its stated contract for a standard environment-assignment form.

@brennanb2025
brennanb2025 force-pushed the fix/unmanaged-omp-status-extension branch 3 times, most recently from 86447ac to a7010ed Compare August 29, 2026 21:44
@brennanb2025
brennanb2025 force-pushed the brennanb2025/pane-identity-env-leak branch from 02f4836 to 747b72a Compare August 30, 2026 01:56
@brennanb2025
brennanb2025 force-pushed the fix/unmanaged-omp-status-extension branch from b1cd969 to b1c73e9 Compare August 30, 2026 02:02
…it spawns

The relay builds each PTY's env from its own process.env, and a relay is
routinely started *from* an Orca pane — so that pane's ORCA_PANE_KEY, TAB_ID,
WORKTREE_ID and ORCA_AGENT_LAUNCH_TOKEN rode into every pane the relay spawned,
fresh or revived. The launch token is the damaging member: it is Orca's only
in-band proof of authorship, and the retired-pane status fence is keyed on it,
so one leaked token let any pane on the relay satisfy a fence a different pane
had set.

The daemon already scrubbed exactly these four keys. Hoist that scrub into
src/shared/pane-identity-env.ts and give the relay the same call, so the two PTY
hosts cannot drift again.

Adds a spawn-site ratchet: 52 files name the launch token but nothing stated the
rule producing it, and two paths shipped without it (#17243's detached-pane
restart, and this one) — each found by accident. A new pane-identity env site now
has to be classified deliberately instead of silently joining the broken half.
…e count

The comment justified the ratchet with 52, which is the repo-wide count
including tests on main. The ratchet scans non-test src/**/*.{ts,tsx},
where 34 files name the token and 10 actually author it.
@brennanb2025
brennanb2025 force-pushed the brennanb2025/pane-identity-env-leak branch from 747b72a to 7fa4d79 Compare August 30, 2026 02:15
@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 server and its relay-only handlers. #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
@OrcaWin

OrcaWin commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator

Thanks @brennanb2025 — managed terminals spawn through the terminal daemon, which strips inherited pane identity (ORCA_PANE_KEY, ORCA_TAB_ID, ORCA_AGENT_LAUNCH_TOKEN, …) in daemon/pty-subprocess/spawn-environment.ts, so this can't recur on orcad. Closing as fixed.

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