Repository navigation
fix(pty): stop a relay leaking its own pane identity into every pane it spawns - #17257
brennanb2025 wants to merge 2 commits into
Conversation
Greptile SummaryThe 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.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| 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
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. |
There was a problem hiding this comment.
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.
86447ac to
a7010ed
Compare
02f4836 to
747b72a
Compare
b1cd969 to
b1c73e9
Compare
…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.
747b72a to
7fa4d79
Compare
|
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. |
|
Thanks @brennanb2025 — managed terminals spawn through the terminal daemon, which strips inherited pane identity ( |
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: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 therelay's
process.envand rode into every pane the relay spawned, fresh or revived.ORCA_AGENT_LAUNCH_TOKENis the damaging member. It is Orca's only in-band proof of authorship, and theretired-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.tsand give the relay the same call,rather than writing a second copy that can drift again:
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 coversboth.
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
launch token — "ignore further status posts from this launch."
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_TOKENand 10 actually author it, but nothing stated therule 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.tsnow forces everypane-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 tcexit 0, 0error TSlines, run in the foreground. Gate proven non-vacuous: plantingconst __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(E2EEhandshake) — 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.
oxlintandoxfmt --checkboth 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 hashcompared before/after and the tree restored and verified clean between runs:
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:
src/main/ipc/pty/ipc/spawn-env.tsvalidates the pane key against the spawn's owntab+leaf and deletes all four on mismatch. Already correct.
spawn-environment.ts. Already correct; now shares the hoisted module.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:
dropped.
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.
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 anode-pty patch it does reach a relay running stock node-pty. No process-liveness verdict is introduced, so
live/unverifiable/exitedare untouched.Scope: what this does not fix
Two status-fence defects in
src/main/agent-hooks/server.tsare not resolved here and need separatework — they are fence semantics, while this PR is env construction in the PTY hosts:
:1246here;:1206onmain). 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.
:2423here;:2338onmain). This PR removes a source of false matchesfeeding 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.tsand the daemon PTY subprocess as well. Different key set, so not a duplicate, buta textual conflict is likely for whichever lands second.