Skip to content

fix: keep interactive Codex execution owned by its Orca terminal - #23791

Closed
brennanb2025 wants to merge 28 commits into
mainfrom
brennanb2025/codex-daemon-identity
Closed

brennanb2025 wants to merge 28 commits into
mainfrom
brennanb2025/codex-daemon-identity

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 28 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1735 $\color{#cf222e}{\Huge{\mathbf{−}}}$​173 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1562
Prod 25 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​406 $\color{#cf222e}{\Huge{\mathbf{−}}}$​83 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​323

What this fixes

With Codex 0.156 or newer, every Codex session on a machine can run through one shared Codex background server. That server keeps the environment of the first terminal that started it, so Orca's second and later Codex terminals report as the first one.
What users saw: only the first Codex session appeared in the sidebar; status and replies from other panes landed on the first pane (even panes in another worktree); orchestration commands from a second worker used the first worker's terminal handle and inbox; and closing the first Codex terminal stopped the shared server, so the other Codex terminals showed "app-server session could not be restored" and their sidebar rows disappeared.
Who hits it: anyone running two or more interactive Codex terminals in Orca with Codex 0.156+, on macOS, Linux, Windows, WSL or an SSH host. It was worst for the system-default Codex home and for Linux/Windows managed homes; macOS managed homes mostly avoided it already because Orca's socket-path guard keeps the shared server off there (that guard is unchanged).
Product tradeoff: Orca-launched interactive Codex no longer shares Codex's background server, so Codex's "Run in background" does not outlive the Orca terminal, and these sessions do not appear in codex agents or codex queue.
Not affected: Native Chat (structured Codex), non-interactive Codex commands (exec, login, app-server, completion and the other subcommands), codex resume --remote …, Codex older than 0.156, and sessions that were already running before the update (nothing existing is converted, and no running server is stopped).

ELI5

Before, all Codex windows could quietly share one engine, and that engine only remembered who the first window was, so everything it did was labelled with the first window's name. Closing that first window turned the shared engine off for everyone.
Now each Orca terminal that starts Codex asks Codex to run its own engine, so each one carries its own name and closing one leaves the others running.

Before / After

Before: Orca put each terminal's identity (pane key, launch token, terminal handle, hook endpoint) in the terminal's environment. Codex's shared server inherited the environment of whichever terminal started it first and replayed that environment into every later session's hooks and tool commands. Orca had no control over which process ran the work.
After: every Orca terminal shell (bash, zsh, fish, Git Bash and PowerShell, locally and in the relay shells on SSH hosts) defines a codex function. For an interactive launch (fresh, resume, fork), it first runs <the codex it is about to start> --no-daemon --version in the pane's own folder and environment. If that exits 0, it starts Codex with --no-daemon, so the Codex process tree belongs to that terminal and inherits that terminal's identity. If the check fails for any reason, it starts Codex exactly as before. Orca's own agent launches run through the same shell, so typed codex and Orca-launched Codex take the same path.
The check asks Codex itself whether it accepts the flag, rather than parsing version strings. The argument order is deliberate: Codex 0.155 accepts --version --no-daemon (it stops at --version) but rejects --no-daemon --version with exit 2. Real binaries checked: 0.155.0 rejects; 0.156.0-alpha.1, 0.156.0 and 0.158.0 accept; none of them start a server during the check.
Every Orca pane (local, WSL, SSH with or without the remote Orca CLI) carries ORCA_CODEX_LAUNCH_POLICY=1, which is what installs the function; it does not depend on Orca's own CLI being present. Managed homes with hooks on still make the one orca agent hooks prepare-codex call they made before; system-default homes make no Orca CLI call at launch.
On PowerShell, Orca's own steps (hook prep, the argument check and the probe) run in one helper with fixed settings, so a user's Set-StrictMode or $ErrorActionPreference = 'Stop' cannot break them, and $LASTEXITCODE afterwards is Codex's own. The launch itself runs with the user's settings and forwards piped input. The function is written to a file in Orca's existing generated shell-wrappers folder and loaded with a one-line loader that execution policy does not block, so the launch command stays short: the longest startup command that fits in the launch arguments is about 5,400 characters (about 4,800 on main). cmd.exe keeps its managed-home hook prep and gets no flag.

Why this design

Alternatives rejected:

  • Attributing hook events by Codex's own session or thread id: the first hook of a new session already arrives with the wrong pane, and it would not fix the terminal handle that tools and orchestration commands inherit, or the shared lifetime (closing one terminal still stops the others).
  • Codex's daemon_auto_start = false setting: it only stops Codex from starting a server; a server that is already running is still reused.
  • A separate Codex home per terminal: splits the user's login and history.
  • A host-side capability cache (an earlier revision of this PR): it answered for the host's folder and environment, which is wrong for version managers that pick a Codex per folder, and it cost an Orca CLI call on every launch. Checking in the pane, on the exact file about to run, has no cache to go stale and no new RPC.
  • A codex shim on an Orca-controlled PATH folder: still needs every shell set up, fights version managers that rewrite PATH, and is fragile on Windows.
    Bug class removed: a Codex session can no longer inherit another terminal's identity or lifetime through a shared server, for every launch that goes through Orca's shell function. No second status store, no pane guessing by folder, and no persisted state were added; the hook server stays the single status authority.

Known weaknesses

  • Launches that bypass Orca's codex function keep today's behaviour and can still share a server: command codex, env X=1 codex, an absolute path to Codex, a user-defined codex alias or function (which also catches Orca-launched workers in that shell), Codex installed after the shell started, cmd.exe, fish inside WSL, Codex options the argument check doesn't recognise (for example --worktree), and SSH hosts where Orca cannot write its relay wrapper folder at all (the pane falls back to a plain login shell, exactly as before).
  • The check has no timeout: if codex --no-daemon --version hangs, the launch waits; Ctrl-C returns to the prompt. A hand-written wrapper that always exits 0 but runs Codex 0.155 or older would get the flag and fail to start.
  • Every bash, zsh, fish and Git Bash pane now loads Orca's startup file, including panes with hooks off or no Codex installed, and SSH panes whose remote Orca CLI install failed; it only defines the function. Verified over SSH that profiles still run and the prompt is unchanged; fish's process arguments now include the function script.
  • Each interactive launch runs the check first. Measured on the macOS QA machine with real Codex 0.158.0 (one sample each): warm launches 46–57 ms vs 12–19 ms on main; the first launch after app start 302 ms vs 235 ms on main. Loading the function in an SSH PowerShell pane costs about 130–450 ms at shell start.
  • PowerShell function limits that no function can avoid: $? stays True after a failed launch; a bare -- is dropped for .exe/.cmd installs (npm's codex.ps1 already behaves this way without Orca); on pwsh 7.4+ piped bytes become text for .exe installs; Get-Command codex shows a function.
  • On Windows, if the generated wrapper file disappears between Orca writing it and PowerShell starting, the pane prints one error and typed codex launches without the flag.
  • Console-window flashing on Windows (STA-8797) is expected to improve because Codex no longer detaches a server, but it is not verified (the QA box has no screen). Worker readiness detection with real Codex under --no-daemon was not exercised; the managed-home launch lane was covered by tests and Windows checks, not by the macOS/SSH live runs.
  • A new ORCA_CODEX_LAUNCH_POLICY variable appears in every pane's environment. With the shared server off, Codex may set the terminal title itself, so a Codex tab can take its first prompt as its name (seen once in QA).

Linked Issue

Disposition Tickets
Closes, for interactive launches that go through Orca's shell function STA-8761, STA-8825, STA-8467, STA-8514 (interactive launch only)
Fixes the routing cause STA-8630 (notification and Agent Activity rows not exercised live)
Partial STA-8797 (shared identity fixed; console flash and readiness not verified), STA-8796 (the row no longer vanishes because the background lifetime is gone for new launches; background-work tracking is not implemented), STA-6643 (interactive launches no longer need the socket; explicit daemon commands with long paths are unchanged)
Not claimed STA-8671, STA-8169, STA-6926

Visual Proof

Live QA on a remote macOS machine with real Codex 0.158.0 (isolated Codex home, dummy model provider, so the model call fails by design and the panes show "Reconnecting"; hooks and status still fire). Three Codex terminals: t1 and t2 in one worktree, t3 in a second worktree.

Before (main): only one sidebar row (t1) for three Codex terminals.
main: three Codex terminals collapse into one sidebar row

Before (main), after closing t1: the shared server stopped, t2 shows "app-server session could not be restored", and every agent row is gone.
main: closing the first Codex terminal breaks the others

After: t1, t2 and t3 each have their own row.
this PR: each Codex terminal has its own sidebar row

After, closing t1: t2 and t3 keep running and keep their rows.
this PR: closing the first Codex terminal leaves the others running

Re-checked on the final code (macOS, real Codex 0.158.0): three rows, then two rows survive closing the first.
final head: three Codex terminals, three rows
final head: after closing the first terminal

Windows (real Codex 0.157.1, Git Bash, PowerShell 7 and 5.1): each Codex terminal has its own row, and closing t1 leaves t2 and t3.
Windows: three Codex terminals, three rows
Windows: after closing the first terminal
Windows: PowerShell 5.1 and pwsh 7 panes on the final code, separate rows

SSH (Linux container host, real Codex 0.158.0). Before (main): three Codex panes, one row (b1); the red banner is an unrelated existing restore error.
SSH main: three Codex panes, one row
SSH main: after closing b1, no rows remain

After: separate rows, and closing t1 leaves t2 and t3 running.
SSH this PR: separate rows
SSH this PR: after closing t1
SSH this PR: four rows across a host with and one without the remote Orca CLI

Testing

  • Live QA on a remote macOS machine with real Codex 0.158.0: each Codex process has --no-daemon and its own ORCA_PANE_KEY and terminal handle, with no shared server; closing the first leaves the others running; a Codex reporting 0.155.0 launches without the flag. The real-home Codex config hashes were unchanged.
  • Real-binary check of the support test (0.155.0, 0.156.0-alpha.1, 0.156.0, 0.158.0), as described above.
  • Live QA on a real Windows machine (Codex 0.157.1): Git Bash, PowerShell 7 and PowerShell 5.1 panes each launch with --no-daemon and get their own row; closing the first leaves the others; Codex 0.155.0 launches without the flag; the "host Job Object prevents daemon detachment" error (STA-8514) never appeared; cmd.exe startup commands run; a ~5,000-character startup command goes through the launch arguments; under Set-StrictMode -Version Latest + $ErrorActionPreference = 'Stop' the launch still gets the flag; $LASTEXITCODE after a blocked or failed launch matches plain PowerShell; piped input reaches Codex; 0 Defender detections. Windows-only test files pass on the box; the 3 failures there also fail on the merge base.
  • Live QA over SSH to a Linux container (real Codex 0.158.0 and 0.155.0), on a host with the remote Orca CLI and one where its install failed: every Codex pane launches with --no-daemon and its own pane key, no shared server starts, closing the first leaves the others, 0.155 launches without the flag, bash/zsh/fish login shells still run their profiles. On main the STA-8467 failure reproduces (one row; closing the first kills the rest).
  • Automated tests: named files covering the shell wrappers (real bash, zsh, fish and pwsh with inert Codex stand-ins), argument classification, the relay shells, Windows shell arguments, the PowerShell helper and loader, cmd.exe startup lines, env scrubbing, and generated wrapper snapshots: 10 core files, 268 passed, 3 skipped by design; all 12 PowerShell tests ran.
  • The fix fails its tests when removed: forcing the check to "supported" fails 24 tests, reversing the probe's argument order fails 19, and each later fix has a test that fails without it.
  • CI: all checks that ran are green. Locally tc:cli passes; tc:node reports only src/main/codex/codex-background-task-frames.ts importing a module the branch base lacks, which current main has fixed (the merge-ref typecheck in CI is green).
  • oxlint and the changed-code quality gate pass on the changed files.

Review

Supersedes #23411 (automation-authored), which reassigned shared-server hooks to a pane by worktree and process, leaving two panes in the same folder ambiguous and the shared lifetime in place.
Leaves #22727, #19215 and #23724 untouched. #19215 touches 11 of the same files: src/main/ipc/pty/host-env/assembly.ts (Codex home selection), src/main/__fixtures__/shell-wrapper-snapshots/local-bash-rcfile.txt, src/main/daemon/pty-subprocess/spawn-environment.ts, src/main/daemon/pty-subprocess-windows-shell-launch.test.ts, src/main/ipc/pty-spawn-env-terminal-basics.test.ts, src/main/powershell-osc133-bootstrap.ts and its test, src/main/providers/windows-shell-args.ts and its test, src/main/providers/local-pty-provider-windows-shell-launch.test.ts, and src/main/providers/local-pty-shell-ready-wrapper-generation.test.ts; keep its home-selection changes when combining them. No file overlap with #22727 or #23724. Does not supersede #22866.

Agent skill upstream boundary

  • Not applicable; no upstream skill-installer material is copied or translated.

Checklist

  • Focused on who owns an interactive Codex terminal's execution; most of the diff is tests and generated shell text.
  • Explained the user-facing change, mechanism, alternatives and the background-work tradeoff.
  • Before/after screenshots attached.
  • Self-reviewed for correctness, performance and old/new version mixes (no new RPC or wire field).
  • Cross-platform, SSH, WSL and folder-workspace impact considered.
  • CI checks that ran are green. Draft until the coordinator decides.

brennanb2025 and others added 28 commits September 28, 2026 21:35
Gate no-daemon launches on execution-host executable evidence, preserve old
launches when support is unknown, and keep new panes from inheriting a
shared server's identity and lifetime.

Co-authored-by: m4air <[email protected]>
…y probe

managed-agent-hook-controls.ts is part of the CLI's module graph, so importing
the main-process Codex capability probe from it pulled main-only modules into
the CLI project (tc:cli TS6307) and made `orca agent hooks on` spawn a pointless
`codex --version` in a short-lived CLI process. The installer now reports each
detected CLI through an injected callback, and only the desktop startup caller
warms the Codex capability cache.
Overlay-only fish panes were deliberately left unwrapped because the only
thing the fish init did was print the readiness marker. This branch gives
them a second job, installing the codex function so a typed codex gets the
launch policy, so the old contract test failed in shell contracts (daemon)
and in the local provider suite. The contract now pins exactly that: wrapped
with -C, no readiness marker, and a featureless fish spawn stays unwrapped.
Every typed interactive codex ran the Orca CLI twice before Codex started:
once to prepare hooks, then again to ask whether this executable supports
--no-daemon. Each CLI start is a full Node/Electron process in front of the
launch. The wrapper now makes one call for interactive launches, and the CLI
runs hook prep and the capability request concurrently; noninteractive
launches keep the single hook-prep call they had.

Hook prep can log to stdout (the trust-grant path prints a line), so the
bash, zsh, fish and PowerShell wrappers read the verdict from the last line
instead of the whole output. A failed hook prep still returns the verdict.
The relay's new Codex branch for PowerShell dropped -l, so pwsh as the
login shell on a Linux or macOS SSH host stopped reading /etc/profile and
~/.profile, and it put the whole wrapper on the command line with -Command
instead of -EncodedCommand like every other PowerShell PTY site. POSIX
hosts now keep -l first and the script is delivered encoded.
Script launchers (npm's codex.js, Windows .ps1/.cmd shims) were never
cached, so every typed launch re-ran `codex --version` through an
interpreter within a 1 s limit, and a slow cold start silently fell back to
the shared server. The same user got isolation on some launches and not
others, and every Windows .ps1 launch spawned a hidden powershell.exe.

- Cache every launcher by its own file identity (realpath + dev/ino/size/
  mtime/ctime), bounded to 128 entries. Positive evidence is re-proven after
  10 minutes so a version-manager shim that switches to an older Codex
  cannot keep receiving the flag; failed probes expire after 30 s.
- Probe with the invoked launcher's directory on PATH (the pattern the
  existing Claude and relay version probes use), so `#!/usr/bin/env node`
  launchers from nvm find their node. The SSH relay probes with the relay
  command environment agent detection uses, and WSL probes set the same
  launcher directory through /usr/bin/env under --exec.
- Allow the probe 5 s, like the existing version probes. The CLI still
  stops waiting after 2 s, so a slow first start no longer latches a
  negative; its verdict is cached for the next launch.
- Accept prerelease version output for 0.156 and later: --no-daemon first
  appears in rust-v0.156.0-alpha.1, and 0.155.x (including its alphas) has
  none.
ORCA_CODEX_LAUNCH_PREFLIGHT is now an overlay key, so a terminal daemon
started from inside an Orca pane (dev builds, nested Orca) carried the
parent's value into every pane it spawned: each pane was wrapped, and its
typed codex asked the parent Orca's CLI for hook prep and capability. The
daemon now keeps the value only when this spawn supplied it, like
ORCA_HISTFILE. This also stops three existing inheritance tests from
failing when the suite runs inside an Orca terminal.
…okup

The launch preflight is now enabled for every pane, so the resolver's
hooksEnabled and managedHomePath options were accepted and ignored; they are
removed from the type, the one production caller, and the tests. The Codex
wrapper's PATH walk got its private result variable by regex-rewriting the
shared lookup script's output; the builder now takes the result variable name
directly, so the generated wrapper text is unchanged and no string surgery
can hit an unrelated word.
Codex exits with "--no-daemon cannot be used with --remote" when both are
present, and --remote is accepted after resume, fork, or a prompt. The
wrapper only scanned options before the first positional, so
`codex resume --remote ws://...` started working on main and failed to
launch on this branch. The bash/zsh, fish and PowerShell classifiers now
refuse the flag when --remote appears anywhere in the arguments, the same
way they already did for an explicit --no-daemon.
The launch verdict came from the host: the wrapper asked the Orca CLI,
which asked the desktop (or the SSH relay) to run `codex --version`
elsewhere and cache the answer for up to 10 minutes. Two problems:

- A version-manager shim picks its Codex from the pane's cwd and env,
  not from its own file. A cached or host-cwd answer could say 0.156+
  while the pane runs 0.155, and Codex then refused to start.
- A cold launch waited up to 2 s for that CLI round trip, and panes
  with a system-default Codex home had made no CLI call before.

The typed-Codex wrapper now runs the resolved `codex --version` itself,
in the pane, right before launch, and adds --no-daemon only for an exact
codex-cli 0.156+ line. Anything else launches exactly as before. The
probe costs one short process (a few ms for the native binary, one Node
start for an npm launcher) and cannot be stale or run in another
context. Hook prep still runs, but only when the pane carries an
Orca-managed home, so system-default and SSH panes start no Orca CLI.

This removes the capability RPC, the relay handler, the host caches and
the CLI flags, so no new wire surface remains to skew between an old
CLI, host or relay and a new wrapper.
cmd.exe runs Orca's Codex hook prep once at shell start. The launch
policy now marks every pane with ORCA_CODEX_LAUNCH_PREFLIGHT, so every
cmd.exe pane, including ones with hooks off or no Codex at all, started
the Orca CLI before its first prompt. cmd.exe gets no launch flag, and
prep only acts on an Orca-managed home, so gate it on ORCA_CODEX_HOME
like the shell wrappers.
The in-pane version gate has a PowerShell copy that no macOS run exercises.
Run it through pwsh for a supported, prerelease, older and unrecognised
version so Windows and pwsh CI lanes prove the flag decision end to end.
… Codex home

cmd.exe treats every later "& command" on an IF line as part of that IF.
The hook-prep clause now checks ORCA_CODEX_HOME, and the pane's startup
command is appended after it, so a terminal with a system-default Codex
home silently skipped its startup command. Parenthesize the clause so its
condition covers hook prep only.
Replace the three per-shell version-string parsers (bash/zsh, fish,
PowerShell) with one rule: add the flag only when
`<resolved codex> --no-daemon --version` exits 0 in the pane, with its
output discarded. Codex's argument parser rejects an unknown --no-daemon
before it reaches --version, so 0.155 and older fail the probe; the
reverse order would pass there, so the order is pinned.

This asks the installed Codex itself instead of mapping a version number
to support, so source builds reporting 0.0.0 now get the flag, a future
build that drops it fails closed, and unparseable version text no longer
matters. The 0.156.0 constant is no longer needed.
The wrapper's PATH lookup ran inside a function without declaring its
variables, so a zsh user with warn_create_global saw six "created
globally" warnings every time they typed codex. Declare them local.
…apper tree

On Windows PowerShell terminals Orca puts its shell-integration script and the
startup command into one -EncodedCommand argument capped at 28,000 characters.
Inlining the new Codex launch wrapper (argument classifier and --no-daemon
probe) grew that script by about 2,000 characters, so the longest startup
command that still fit dropped from about 4,800 to about 2,800 characters
(cwd C:\Users\alice\orca\workspaces\orca\codex-daemon-identity). Longer
commands, such as Codex worker launches with long prompts, fell back to being
typed into the shell.

The wrapper is now written into the existing content-addressed shell-ready
tree next to the bash rcfile and zsh wrapper, and the Windows bootstrap loads
it with a one-line ScriptBlock loader. ScriptBlock text is not gated by
execution policy, unlike dot-sourcing a .ps1, so Restricted/AllSigned hosts
keep the wrapper. No flag is added to the command line. If the tree cannot be
written, the wrapper is inlined as before. About 5,400 characters now fit.

Non-Windows pwsh and the SSH relay keep the inline wrapper; neither appends a
startup command to the payload.
…ft unread

The terminal environment builder read codexStatusHooksEnabled only to decide
whether to install the typed-Codex wrapper. The wrapper is now installed in
every terminal and hook preparation decides for itself whether hooks are on,
so three spawn paths computed the value and nothing read it. Remove the option
and its isCodexStatusHooksEnabled helper. No behaviour change.
The case added for the Codex launch preflight spawned /bin/bash, which on a
Windows runner takes the Windows shell branch and never selects shell
features, so its overlay assertion failed there. Pin process.platform the
way the managed-agent env suite does.
Every shell's codex function was installed only when
ORCA_CODEX_LAUNCH_PREFLIGHT named a launcher the shell could execute. When
the build had no verifiable launcher (dev WSL, a missing bundle), or the
shell rejected it (Git Bash's -x on a dev build's orca-dev.cmd), or an SSH
host had no CLI bridge, the pane got no function and typed or Orca-launched
Codex silently shared the background server again, even in panes whose
system-default home never needs the CLI.

Orca now marks every pane with ORCA_CODEX_LAUNCH_POLICY=1 (local panes,
WSL via WSLENV, SSH with or without the bridge). That marker, not the CLI
path, installs the function, selects the shell overlay, wraps Git Bash, and
wraps relay fish and PowerShell. Only the prepare-codex call still needs a
managed home and a launcher that shell can run. The daemon drops an
inherited copy of either key, as it already did for the preflight.
The PowerShell no-daemon probe reset $LASTEXITCODE to 0 before probing.
When that Codex could not run at all, as with npm's codex.ps1 under
Windows PowerShell 5.1's default Restricted policy, the launch then failed
and $LASTEXITCODE read 0, where the same failure without Orca leaves it
where it was. The probe now restores the value it found.
The no-daemon probe now saves $LASTEXITCODE before probing, so a Codex
that cannot run leaves it unchanged. It read $global:LASTEXITCODE
directly. Before any native command has run in the session that variable
is unset, and under Set-StrictMode reading an unset variable is an error.
A pane with no managed home runs no hook prep first, so the first codex
typed there printed two errors, and with $ErrorActionPreference = 'Stop'
Codex did not launch at all. The probe now reads it through Get-Variable,
which returns nothing instead of failing.
In a pane with an Orca-managed Codex home (Orca's default), the codex
function first runs the Orca CLI's hook prep. That native call set
$LASTEXITCODE to 0. When Codex then could not run at all, as with npm's
codex.ps1 under Windows PowerShell 5.1's default Restricted policy, the
caller saw 0 instead of the value it had before, which is what a plain
codex launch leaves. Found on a real Windows 5.1 host; the earlier fix
only covered the no-daemon probe.

The codex function now saves $LASTEXITCODE on entry and restores it
right before the launch. That one restore covers both hook prep and the
probe, so the probe no longer restores it itself.

$? still reads True after a failed launch. A plain PowerShell function
cannot report False without throwing (which would stop a calling
script) or becoming an advanced function (whose common parameters would
capture Codex flags such as -i and -o), and main's managed-home wrapper
behaves the same way.
In a PowerShell pane, `Get-Content prompt.md | codex exec -` gave Codex
no input: a native command run inside a function never receives the
function's pipeline input on its own, so Codex read the terminal instead.
Main already had this in panes with an Orca-managed home; this branch
installs the function in every Orca PowerShell pane (system-default
homes, dev builds, SSH), so it reached panes that piped correctly before.

The function now pipes $input into the launch when it was called with
pipeline input, the same way npm's codex.ps1 shim forwards it. A call
without piped input launches exactly as before.
The PowerShell codex function ran hook prep, the argument check and the
--no-daemon probe under the caller's own Set-StrictMode and
$ErrorActionPreference. Those are settings a user picks for their own
code, and they reached Orca's steps:
- With $ErrorActionPreference = 'Stop', any error record written during
  the probe (for example by a codex.ps1 shim) became a terminating
  error, so the probe reported the flag as unsupported and Codex
  launched without --no-daemon. On Windows PowerShell 5.1, Stop does
  the same for any stderr line from a native command, which could also
  cut hook prep short.
- An earlier defect on this branch (first launch failing under
  Set-StrictMode) came from the same cause.

Hook prep, the argument check and the probe now run in one helper,
__OrcaCodexLaunchFlags, which pins Set-StrictMode -Off,
$ErrorActionPreference = 'Continue' and
$PSNativeCommandUseErrorActionPreference = $false in its own scope,
restores $LASTEXITCODE before it returns, and returns only the flags.
The Codex launch itself, with its pipeline input forwarding, still
runs under the user's own settings. The piecemeal save/restore in the
codex function is gone because the helper owns it.

The PowerShell tests move to their own file, which keeps the original
test file under the line limit; the shell contracts CI job lists it.
When Codex was removed after the pane started, the codex function wrote
"codex executable not found" and only then set $LASTEXITCODE to 127.
Under $ErrorActionPreference = 'Stop' that Write-Error throws, so the
127 never ran and the caller saw whatever exit code was there before.
The code is now set first. Main had the same order.
…old design

The launcher resolver no longer takes hook or Codex-home options, so the
"without consulting hooks or the selected Codex home" case repeated the
packaged darwin launcher case exactly, and it named the hook-prep launcher
"the launch policy". Two relay tests still said "version gate" and one env
test said "capability gate", both from earlier revisions; they now name the
launch policy and the hook-prep launcher they actually check.
The two SSH create-operation tests pin the exact pty.spawn params. Since
every SSH pane now carries ORCA_CODEX_LAUNCH_POLICY=1 in its env, both
failed on the full unit-test job.

"Byte-for-byte legacy" is about the request fields: an old relay must get
no agent-session create or claim fields and no capability probe. Pane env
is an opaque map that every relay version copies into the shell; an old
relay has no reader of the marker, so it only shows up in `env`. The
bridge env keys already reach old relays the same way.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status (draft, not marked ready)

Verdict: the fix works for users on macOS, Windows and SSH, the final review loop came back clean, and the architecture was challenged twice and kept. The PR stays a draft for the coordinator to decide; nothing was merged.

What users get: with Codex 0.156+, each Orca Codex terminal now has its own sidebar row and its own identity, and closing one Codex terminal no longer kills the others. On main, three Codex terminals showed one row and closing the first broke the rest (reproduced live on macOS and over SSH). Codex 0.155 and older launch exactly as before.

Tradeoff to accept: Orca-launched interactive Codex no longer uses Codex's shared background server, so "Run in background" does not outlive the Orca terminal and these sessions don't appear in codex agents / codex queue.

Review loops: 12 loops; loops 5 and 11 returned clean on product code, and loop 12 only updated a test expectation that CI's full unit-test job caught. Main changes during review:

  • Replaced the first design (a host-side cache that parsed Codex version strings, plus a new RPC and CLI flags) with a check inside the terminal: <codex> --no-daemon --version must exit 0. The cache gave wrong answers for version managers that pick a Codex per folder, and it added an Orca CLI call to every launch. The new check has no cache and no wire change. Real binaries confirm it: 0.155.0 rejects the flag, 0.156.0-alpha.1 and later accept it.
  • The codex function is now installed by a per-pane marker, not by whether Orca's CLI is present. Before, Git Bash dev builds and SSH hosts without the remote CLI silently got no fix.
  • Fixed a cmd.exe regression introduced mid-review: startup commands were skipped in panes without a managed Codex home.
  • PowerShell: Orca's steps now run in one helper with fixed settings. That fixed StrictMode/Stop crashes, $LASTEXITCODE leaks and lost piped input, and the loader keeps long startup commands in the launch arguments (about 5,400 characters, main about 4,800).
  • Also fixed: a packaged-CLI import break (TS6307), codex resume --remote refusing to start, zsh warn_create_global warnings, and PowerShell over SSH losing login-shell mode.

Live QA, all on remote machines with real Codex and isolated Codex homes (real-home Codex config hashes unchanged on every box):

  • macOS, Codex 0.158.0: PASS at the final product code. Three rows; closing the first leaves the others; real 0.155.0 launches without the flag.
  • Windows, Codex 0.157.1, Git Bash + pwsh 7 + PowerShell 5.1: PASS. Separate rows; the job-object "daemon detachment" error never appeared; cmd.exe startup commands run; StrictMode/Stop, exit codes and piping behave like plain PowerShell. Console-window flashing could not be observed (no screen).
  • SSH to a Linux container, with and without the remote Orca CLI: PASS. Every pane gets --no-daemon and its own pane key; on main the shared-server failure reproduces.
  • Screenshots are embedded in the PR body.

Checks: tc:cli passes. tc:node locally reports only a module the branch base lacks (fixed on main; CI's merge-ref typecheck is green). Named tests, oxlint and the changed-code quality gate pass. CI at e46300b: every workflow completed successfully, including all five unit-test shards, relay integration, shell contracts, typecheck, cross-version wire compatibility and the Windows/Linux package jobs.

Open items for the coordinator:

  • GO asked for a cached, host-scoped capability check that reuses agent detection. Review replaced it with the per-launch in-terminal check (reasons above). Please confirm that departure.
  • Known limits, listed in the body: typed command codex, env X=1 codex, absolute paths, a user's own codex alias/function, cmd.exe, fish in WSL, unrecognised Codex options and SSH hosts where Orca can't write its wrapper folder all keep today's shared-server behaviour. The check has no timeout. Warm launches take about 30–40 ms longer (46–57 ms vs 12–19 ms on main).
  • Not verified live: worker readiness with real Codex, the managed-home launch lane on macOS/SSH, and Windows console-flash behaviour.
  • Not caused by this PR: main briefly failed to build (codex-background-task-frames.ts imported a deleted module); on SSH re-add, restored tabs show a raw terminal_pane_owner_host_mismatch banner (reproduces on main).
  • The first commit's Co-authored-by: m4air <[email protected]> trailer credits the shared automation machine account that opened fix(codex): attribute shared-daemon Codex hooks to the session's own worktree #23411, not a person. Decide whether to drop it at squash time.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Closing as superseded by #23900 (with follow-up #23907), which already launches interactive Codex in Orca terminals with --no-daemon across the bash, zsh, fish and PowerShell wrappers, the SSH relay and WSL. That covers STA-8761, STA-8825, STA-8467, STA-8514 and STA-8630.

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.

1 participant