Repository navigation
Fix inherited PTY setup launch state - #16909
brennanb2025 wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (10)
💤 Files with no reviewable changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughA shared Merge Risk: 🔵 Low · up to The change prevents setup and agent-launch state from leaking into ordinary terminals, restoring expected Git credential prompting and status behavior across local, daemon, and relay sessions. The PR is mergeable with owner awareness that local environment augmentation should not accidentally reintroduce the protected variables before spawning a terminal. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description is detailed and covers the required change, rationale, testing, visual proof, review, and checklist sections. The required Linked Issue section is marked N/A even though the template requires an issue link.
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Status: ready for CI at exact SHA
|
9cdb210 to
f875c0f
Compare
|
Follow-up at exact SHA 1. The 2. Correction: this PR did not unblock #16336. I previously reported #16336 as "confirmed unblocked" by this fix. That was wrong. #16336's only red check was the e2e app build (plain-node-entry-guard / missing pty.node), which is inherited base staleness fixed on main by 3. Rebase + post-rebase verification. The PR was DIRTY against main; it is now CLEAN/MERGEABLE. The one conflict was with #16778 ("Extract local PTY launch helpers"): main moved Post-rebase verification at
|
Independent adversarial review —
|
| Consumer | Channel | Inheritance-dependent? |
|---|---|---|
Gated pane's bash -lc 'eval "$ORCA_SEQUENCED_STARTUP_SCRIPT"' |
explicit startupEnv |
No — explicit, preserved by hasOwn |
host-env/assembly.ts:49 launch-hint + OMP-shadow decision |
assembled child env | Inherited presence was the bug |
relay/pty-handler.ts:1620 launch-hint + credential-guard + shell-ready delivery |
assembled child env | Inherited presence was the bug |
| Relay plugin augmenter OMP materialization | assembled child env | Inherited presence was the bug |
codex-resume.ts stripSequencedStartupResumeArgv |
env under assembly; rewrites the key only if present | No |
wsl-orca-env.ts WSLENV /u passthrough |
names keys; inert when absent | No — explicit values still cross into the guest |
orca-runtime.ts:29133 (agent-teams sequenced launch) |
producer, sets explicitly | No |
No consumer depended on inheriting the keys; the extra scrubbing is exactly the intended semantics. ORCA_TERMINAL_HANDLE is deliberately absent from the list — it has its own trust-gated reconciliation (local-configure.ts:84: untrusted inherited handles are deleted and replaced by a pre-allocated one).
3. Failing-first + ablation (all runs local, this head)
PR tests against parent production code (bdabb09a07af): 6 failed / 100 passed — all five claimed sites red (local, daemon, WSL managed terminal, relay fresh-spawn, relay revive). Head: 106/106 green.
Per-hunk ablation (revert one production hunk, keep PR tests):
| Ablated hunk | Result |
|---|---|
daemon spawn-environment.ts |
1 failed — daemon inheritance test |
local-pty-provider.ts (+helpers) |
2 failed — local spawn + WSL managed-terminal tests |
relay pty-handler.ts |
3 failed — relay fresh-spawn, relay revive, plus the pre-existing "leaves an ordinary Windows SSH user terminal unchanged" test |
Every hunk is load-bearing; no dead production code.
4. Independent confirmation this is a production environment-ownership bug
My review terminal is itself a setup-gated Orca agent pane, so the test process inherits both sequencing vars — the exact production condition. Under parent code, the pre-existing relay test "leaves an ordinary Windows SSH user terminal unchanged" fails in isolation in this environment (GIT_TERMINAL_PROMPT expected '1', got '0'): the inherited command resolves as a launch hint and applyTerminalGitCredentialPromptGuard treats an ordinary user terminal as agent-launched. So the bug's blast radius was wider than the suppressed OMP status entry — it also disabled interactive git credential prompts in plain terminals spawned by an Orca that was launched from a gated pane. Under head, the same environment is fully green (126/126 across the six related files, and 6 existing overlay tests that fail on parent under pollution pass on head). This confirms deterministic environment ownership, not test-order flakiness.
5. WSL correctness
The diff builds no wsl.exe argv (WSL appears only in test assertions). The managed-WSL spawn path is untouched and already routes through the --exec builder; the guard suite passes on head. Nothing new parses WSL stdout, so login-shell fencing is not applicable; the interactive terminal is the documented do-not-fence case. The scrub runs on the Windows-side env before wsl.exe spawns, so the untouched WSLENV /u passthrough carries explicitly-set sequencing keys into the guest and is inert for the now-absent inherited ones — which is the fix.
6. Relay/SSH wire compatibility
No RPC param, serialized-state, or stream-frame changes; no new opcodes, so no capability negotiation needed. What the host publishes does change: a new relay scrubs the six keys from child env unless the client set them explicitly. Old client + new relay is safe — old clients already deliver pane identity and gated-launch env explicitly, and relay-inherited values were never a deliberate delivery channel (the relay daemon's env comes from sshd/nohup). New client + old relay simply keeps the bug until the host updates; no hazard.
7. Flake spot-check
GitHub Actions has zero reruns on this branch — every run is attempt 1, all green at both commits — so the recorded green CI was not masked by retries; the reported 8-flake rerun was a local run. I replicated CI's exact shard 1/8 invocation locally on head (in the polluted gated-pane environment): 7,642 passed / 0 failed (846 files; author reported 846+1/7,642+2, within environment-conditional drift). Exit code 1 came solely from one vitest worker-fork pool error ("Worker exited unexpectedly") with no failing test — a local-load harness artifact, not a PR effect. Nothing suggests this PR causes flakes.
8. Performance
By-hand analysis (the perf skill is disable-model-invocation here): the scrub is a six-key Object.hasOwn loop per PTY spawn/revive — user-interaction-rate, not hot-path. No new allocations of consequence, timers, listeners, retained state, or polling. Negligible.
9. Superseding bar
This is close to what I would write from scratch: one shared scrubber in src/shared (importable by relay and main), keys as constants owned by their defining module, one invocation per spawn boundary, explicit-env passthrough. Two things a from-scratch design might do differently, both non-blocking:
- P2:
PTY_CHILD_SCOPED_ENV_KEYSis an enumerated list; the next pane-scopedORCA_*var must be remembered manually, and nothing ratchets new per-pane env keys into it. A prefix-based default-deny with an explicit child-passthrough allowlist would fail closed, but it would touch many legitimate passthrough keys and is a materially bigger change than this fix warrants. - Nit: the save/restore block in
pty-serializer-settlement-mapping.test.tshand-rolls per-key restore where the loop pattern used in the relay tests would be tighter. Cosmetic.
Checklist coverage
Crash/cast/growth: no new casts, no unbounded structures. Security/supply chain: no dependency, network, or exec-surface changes. Backcompat/data loss: no persisted state or migrations; no mobile-facing surface touched. Code organization: pty-child-scoped-env.ts is a concrete domain name in the right layer. Counsel validation not triggered: verdict is PASS with no P0/P1 candidates.
…ch state The spawn-env scrub only fixes the reported bug if it runs before buildSpawnEnv's consumers read the env. Moving it after the credential-guard read left every existing test green on a clean environment while ordinary user terminals silently lost Git credential prompts again.
f875c0f to
02cacf6
Compare
Review round 1 — verdict: PATCH (not superseded), one test addedRebased onto current The bug is real, and reproduces from a setup-gated panePure Those same 5 files are green at head (106 passed). This is independent confirmation of the PR's premise, not a re-run of its own assertions. Can launch state still cross a PTY boundary? No — via inheritance or replay.I traced all four lifecycle transitions rather than assuming spawn parity:
The scrub is also correctly ordered before its consumers at every boundary — it runs ahead of Also confirmed: the 6-key set is a strict superset of the old 4-key Ablation table — every production hunk is pinned
One gap found and closedThe scrub-before-read ordering was not pinned by any test. I moved the relay scrub to after the credential-guard read and, on a clean CI-like environment, the entire suite stayed green — including the PR's own new test, which only checks that the keys are absent from the final spawn env. A future refactor could have reintroduced the exact user-visible bug undetected. Added Live end-to-end validation, and one thing this PR does NOT fixI launched an isolated dev build from a setup-gated pane (own CDP port, own renderer port, own user-data profile) so the app genuinely inherited the markers, and spawned a plain terminal through the real PTY IPC: The sequencing markers are correctly gone. But Root cause is the early return in Deliberately not fixed here — different mechanism, different fix site, its own test surface. Worth a follow-up. It does mean the PR body's symptom-1 claim should be read as "removes one of two causes": a user who launches Orca from a gated pane still gets prompt-less Git in every terminal. Gates
Not verifiedWindows and WSL legs were not executed on real hosts — reasoned about only ( |
|
Closing: replaced by #43153, which moves Setup-gated launches off inherited environment variables. |
ELI5
Some Orca terminals are "gated": the workspace has a setup script, so instead of starting the agent immediately, Orca gives that terminal two private environment variables that mean "wait for setup to finish, then run this agent command." Environment variables are inherited by every program a process starts — and that is the bug. If you launched Orca itself from inside one of those gated terminals (for example, typing
orcain that pane's shell), the new Orca process inherited the "you are launching an agent" markers and passed them on to every terminal it opened. Every plain terminal then looked like it was launching an agent.Two things you could actually notice:
GIT_TERMINAL_PROMPT=0, blankedGIT_ASKPASS/SSH_ASKPASS,GCM_INTERACTIVE=never,credential.interactive=false) so an agent can never hang on an invisible "Username:" prompt. With the inherited markers, that guard fired in ordinary user terminals too: agit clone/fetch/pushover HTTPS that needed to ask for credentials failed immediately withfatal: could not read Username … terminal prompts disabledinstead of prompting. Cached credentials kept working (the credential helper is preserved), so it presented as intermittent auth failure rather than an obvious config problem.When you'd hit it
ORCA_SEQUENCED_STARTUP_COMMAND(plusORCA_SEQUENCED_STARTUP_SCRIPTon POSIX) for its whole lifetime.process.envnow carries the sequencing variables.process.env(buildPtyHostEnv), the persistent daemon inherits by fork, and the SSH relay'sbuildSpawnEnvspreads the relay server'sprocess.env.resolveSetupAgentSequenceLaunchCommandturns the inherited startup command into that terminal's launch-command hint, soapplyTerminalGitCredentialPromptGuardand the OMP-shadow logic both treat the plain terminal as an agent launch.Before this PR, the local and daemon boundaries already scrubbed the four pane-identity keys (
ORCA_PANE_KEY,ORCA_TAB_ID,ORCA_WORKTREE_ID,ORCA_AGENT_LAUNCH_TOKEN) — but not the two sequencing keys, and the SSH relay boundary scrubbed none of the six.What Changed
removeUnspecifiedPtyChildScopedEnv) removes all six keys above at every spawn boundary unless the caller explicitly supplied them for that child. The relay previously had no scrub of any of these keys; it now scrubs all six at fresh spawn and at revive.Why
The WSLENV test exposed a production environment ownership bug, not an order-dependent assertion. The 16-to-8 shard change made the test visible in a different batch, but the failure also reproduced isolated because the parent Orca process carries setup-sequencing variables.
The blast radius is wider than the OMP status symptom: the same inherited state made
applyTerminalGitCredentialPromptGuardtreat ordinary user terminals as agent launches, forcingGIT_TERMINAL_PROMPT=0(overriding both an explicit=1and Git's prompt-by-default) along with the askpass/GCM guards — a user-visible behavior change in terminals where people run Git by hand, not an internal detail. An independent review reproduced this from its own gated pane: with the inherited environment present, pre-PR code fails 7 existing tests in isolation, including the relay assertion that an ordinary user terminal'sGIT_TERMINAL_PROMPTis left unchanged.The E2E native build blocker is already resolved on main by
9e0704b9d46209885e95f1a24292a486b041dc73; this PR does not duplicate that fix.Linked Issue
N/A — current-main CI health blocker.
Visual Proof
N/A — no visible UI or interaction surface changes; this changes PTY child environment construction.
Testing
--shard=1/8— 847 files passed, 6 skipped; 7,644 tests passed, 26 skippedpnpm tc:nodeReview
Independent same-model adversarial review found the missing relay parity path; it was fixed and the updated diff was re-reviewed clean. Performance is bounded to six key checks per PTY spawn with no polling, fanout, retained state, or output-path work. A second independent adversarial review at head
f875c0ff72bareproduced the bug from its own gated review pane and confirmed the wider user-facing blast radius described above.Agent skill upstream boundary
Notes
No persisted state, IPC/RPC wire contract, mobile surface, renderer UI, or user-owned data changes.
Checklist