Skip to content
1 change: 1 addition & 0 deletions config/scripts/pr-code-change-scope.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const GIT_COMPAT_PREFIXES = [
const CODEX_INDEX_HEAL_CONTRACT_PREFIXES = [
'src/main/pty/codex-no-daemon-binary-contract',
'src/main/pty/codex-shell-launch-preflight',
'src/shared/codex-shell-function',
'src/main/codex/codex-index-heal-binary-contract',
'src/main/codex/codex-session-index-heal',
'src/main/codex/codex-app-server-session',
Expand Down
2 changes: 1 addition & 1 deletion src/main/daemon/daemon-bash-shell-ready-rcfile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getPosixOmpShellWrapper } from '../pty/omp-shell-wrapper'
import { getPosixCodexShellLaunchPreflight } from '../pty/codex-shell-launch-preflight'
import { getPosixCodexShellLaunchPreflight } from '../../shared/codex-shell-function'
import { BASH_PROMPT_COMMAND_COMPOSITION_BLOCK } from '../bash-prompt-command-composition'
import { BASH_FEATURE_CHANNEL_BLOCK, SHELL_STARTUP_IDENTITY_MARKER_BLOCK } from '../shell-templates'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { PREVIOUS_DAEMON_PROTOCOL_VERSIONS, PROTOCOL_VERSION } from './types'

describe('foreground-confirmation daemon protocol', () => {
it('rejects daemons from before the fresh-confirmation RPC', () => {
expect(PROTOCOL_VERSION).toBe(37)
expect(PROTOCOL_VERSION).toBe(38)
expect(PREVIOUS_DAEMON_PROTOCOL_VERSIONS).toContain(19)
expect(PREVIOUS_DAEMON_PROTOCOL_VERSIONS).toContain(22)
expect(PREVIOUS_DAEMON_PROTOCOL_VERSIONS).toContain(23)
Expand All @@ -20,5 +20,6 @@ describe('foreground-confirmation daemon protocol', () => {
expect(PREVIOUS_DAEMON_PROTOCOL_VERSIONS).toContain(34)
expect(PREVIOUS_DAEMON_PROTOCOL_VERSIONS).toContain(35)
expect(PREVIOUS_DAEMON_PROTOCOL_VERSIONS).toContain(36)
expect(PREVIOUS_DAEMON_PROTOCOL_VERSIONS).toContain(37)
})
})
6 changes: 4 additions & 2 deletions src/main/daemon/daemon-protocol-version.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
AGENT_SESSION_CLAIM_DAEMON_PROTOCOL_VERSION,
AGENT_SESSION_CREATE_OPERATION_DAEMON_PROTOCOL_VERSION,
ASYNC_CWD_VALIDATION_DAEMON_PROTOCOL_VERSION,
CODEX_FUNCTION_IN_PLAIN_SHELLS_DAEMON_PROTOCOL_VERSION,
CODEX_NO_DAEMON_SHELL_LAUNCH_DAEMON_PROTOCOL_VERSION,
CODEX_SHELL_LAUNCH_PREFLIGHT_DAEMON_PROTOCOL_VERSION,
COMPLETION_PROCESS_INSPECTION_PROTOCOL_VERSION,
Expand All @@ -20,7 +21,8 @@ import {

describe('daemon protocol version', () => {
it('ships bounded history transfer after the 2031-unsubscribe fact', () => {
expect(PROTOCOL_VERSION).toBe(37)
expect(PROTOCOL_VERSION).toBe(38)
expect(CODEX_FUNCTION_IN_PLAIN_SHELLS_DAEMON_PROTOCOL_VERSION).toBe(38)
expect(CODEX_NO_DAEMON_SHELL_LAUNCH_DAEMON_PROTOCOL_VERSION).toBe(37)
expect(CONTENT_ADDRESSED_SHELL_WRAPPER_DAEMON_PROTOCOL_VERSION).toBe(36)
expect(ASYNC_CWD_VALIDATION_DAEMON_PROTOCOL_VERSION).toBe(35)
Expand All @@ -35,7 +37,7 @@ describe('daemon protocol version', () => {
expect(AGENT_SESSION_CLAIM_DAEMON_PROTOCOL_VERSION).toBe(26)
expect(AGENT_SESSION_CREATE_OPERATION_DAEMON_PROTOCOL_VERSION).toBe(26)
expect(PREVIOUS_DAEMON_PROTOCOL_VERSIONS).toEqual(
Array.from({ length: 36 }, (_, index) => index + 1)
Array.from({ length: 37 }, (_, index) => index + 1)
)
})

Expand Down
7 changes: 4 additions & 3 deletions src/main/daemon/daemon-protocol-version.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Why: daemons survive app updates, so wire behavior must be version-gated.
// v37 runs Codex without the shared background server at the shell launch boundary; older owners stay attachable.
export const PROTOCOL_VERSION = 37
// v38 wraps plain zsh and fish tabs so a typed codex gets --no-daemon; older owners stay attachable.
export const PROTOCOL_VERSION = 38
export const CODEX_FUNCTION_IN_PLAIN_SHELLS_DAEMON_PROTOCOL_VERSION = 38
export const CODEX_NO_DAEMON_SHELL_LAUNCH_DAEMON_PROTOCOL_VERSION = 37
export const CONTENT_ADDRESSED_SHELL_WRAPPER_DAEMON_PROTOCOL_VERSION = 36
export const ASYNC_CWD_VALIDATION_DAEMON_PROTOCOL_VERSION = 35
Expand Down Expand Up @@ -31,7 +32,7 @@ export const CLEAN_DISCONNECT_PROTOCOL_VERSION = 24
export const MODE_2031_UNSUBSCRIBE_FACT_PROTOCOL_VERSION = 29
export const PREVIOUS_DAEMON_PROTOCOL_VERSIONS = [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
28, 29, 30, 31, 32, 33, 34, 35, 36
28, 29, 30, 31, 32, 33, 34, 35, 36, 37
] as const

export function supportsPtyStartupIngress(protocolVersion: number): boolean {
Expand Down
10 changes: 4 additions & 6 deletions src/main/daemon/pty-subprocess-env-inheritance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,8 @@ describe('createPtySubprocess', () => {

it.each([
// ORCA_HISTFILE is exported into every pane, so a daemon started from an
// Orca pane inherits one. Left in place it BOTH re-scopes the pane to
// another worktree's history file (#11146) and wraps a zsh pane nothing
// asked to wrap, since `history` is selected on its presence.
// Orca pane inherits one. Left in place it re-scopes the pane to another
// worktree's history file (#11146) and selects `history` on its presence.
['drops an inherited Orca ORCA_HISTFILE', undefined, undefined],
[
'keeps the path this spawn injected',
Expand Down Expand Up @@ -289,9 +288,8 @@ describe('createPtySubprocess', () => {

const env = spawnMock.mock.calls.at(-1)?.[2].env
expect(env.ORCA_HISTFILE).toBe(expected)
// The wrapping consequence: no inherited value may point a pane at Orca's
// ZDOTDIR that the client scoped no history for.
expect(env.ORCA_SHELL_FEATURES).toBe(expected === undefined ? undefined : 'history')
// Why '' and not absent: every zsh pane is wrapped for the codex function.
expect(env.ORCA_SHELL_FEATURES).toBe(expected === undefined ? '' : 'history')
})

it('does not inherit ELECTRON_RUN_AS_NODE from the daemon process env', async () => {
Expand Down
26 changes: 14 additions & 12 deletions src/main/daemon/pty-subprocess/shell-launch-plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ import {
resolveWindowsShellLaunchArgs
} from '../../providers/windows-shell-args'
import { resolveUnixShellPath } from '../../providers/local-pty-utils'
import { selectShellStartupFeatures } from '../../shell-startup-features'
import {
keepsConfiguredShellUnwrapped,
selectShellStartupFeatures
} from '../../shell-startup-features'
import { parseWslPath } from '../../wsl'
import { addWslEnvKeys } from '../../wsl-env'
import {
Expand All @@ -35,7 +38,7 @@ import {
} from '../../../shared/agent-process-recognition'
import { ORCA_HERMES_STARTUP_QUERY_ENV } from '../../../shared/hermes-startup-query'
import { WINDOWS_GIT_BASH_SHELL } from '../../../shared/windows-terminal-shell'
import { getShellLaunchConfig, resolvePtyShellPath } from '../shell-ready'
import { getShellLaunchConfig, resolvePtyShellPath, UNWRAPPED } from '../shell-ready'
import { resolveWslSessionContext } from '../wsl-session-context'
import { finalizeDaemonPtyEnvironment, rescrubDaemonPtyEnvironment } from './spawn-environment'
import type { PtySubprocessOptions } from '../pty-subprocess'
Expand Down Expand Up @@ -198,17 +201,16 @@ export function createPtyShellLaunchPlan(
shellPath
}))
delete env.ORCA_SHELL_FEATURES
const shellLaunch = getShellLaunchConfig(
const features = selectShellStartupFeatures({
shellPath,
selectShellStartupFeatures({
shellPath,
env,
hasStartupCommand: Boolean(opts.command),
waitsForShellReady,
emitsStartupIdentity: waitsForShellReady
}),
{ hasStartupCommand: Boolean(opts.command) }
)
env,
hasStartupCommand: Boolean(opts.command),
waitsForShellReady,
emitsStartupIdentity: waitsForShellReady
})
const shellLaunch = keepsConfiguredShellUnwrapped(features, opts)
? UNWRAPPED
: getShellLaunchConfig(shellPath, features)
Object.assign(env, shellLaunch.env)
shellArgs =
!opts.command && !opts.launchAgent && opts.terminalShellArgs !== undefined
Expand Down
7 changes: 5 additions & 2 deletions src/main/daemon/shell-ready.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,15 @@ describePosix('daemon shell-ready launch config', () => {
expect(init).toContain('functions -e __orca_shell_ready_marker')
})

it('keeps markerless fish spawns unwrapped', async () => {
it('wraps a markerless fish spawn for the codex function only', async () => {
const { getMarkerlessShellLaunchConfig } = await importFreshShellReady()

const config = getMarkerlessShellLaunchConfig('/opt/homebrew/bin/fish')

expect(config).toEqual({ args: null, env: {}, supportsReadyMarker: false })
expect(config.args?.slice(0, 2)).toEqual(['-l', '-C'])
expect(config.args?.[2]).toContain('function codex')
expect(config.args?.[2]).not.toContain('orca-shell-ready')
expect(config.supportsReadyMarker).toBe(false)
})

itWithFish(
Expand Down
22 changes: 10 additions & 12 deletions src/main/daemon/shell-ready.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
getPowerShellOsc133Bootstrap,
isPowerShellExecutableName
} from '../powershell-osc133-bootstrap'
import { getFishCodexShellLaunchPreflight } from '../pty/codex-shell-launch-preflight'
import { getFishCodexShellLaunchPreflight } from '../../shared/codex-shell-function'
import { getFishShellReadyInitCommand } from '../shell-templates'
import {
encodeShellStartupFeatures,
Expand Down Expand Up @@ -114,27 +114,26 @@ export type ShellLaunchConfig = {
supportsReadyMarker: boolean
}

const UNWRAPPED: ShellLaunchConfig = {
export const UNWRAPPED: ShellLaunchConfig = {
args: null,
env: {},
supportsReadyMarker: false
}

/**
* The one launch-config entry point: args + env for a shell that should start
* with exactly `features` enabled. An empty selection is never wrapped.
* with exactly `features` enabled. An empty selection wraps only zsh and fish.
*/
export function getShellLaunchConfig(
shellPath: string,
features: readonly ShellStartupFeature[],
options: { hasStartupCommand?: boolean } = {}
features: readonly ShellStartupFeature[]
): ShellLaunchConfig {
const shellName = pathWin32.basename(basename(shellPath)).toLowerCase()

// Why zsh and fish wrap with no feature: the wrapper defines the codex function a
// typed launch needs, and both keep their normal login startup. bash does not:
// its --rcfile wrapper would make every plain tab a non-login shell.
if (shellName === 'zsh') {
if (features.length === 0) {
return UNWRAPPED
}
if (!ensureShellReadyWrappers()) {
// Why plain login zsh: ZDOTDIR pointed at an incomplete wrapper dir makes
// zsh skip the user's whole config. Losing Orca's features is recoverable.
Expand Down Expand Up @@ -178,10 +177,9 @@ export function getShellLaunchConfig(
}
}

// Why: mirrors local-pty-shell-ready.ts; markerless fish stays unwrapped unless a
// startup command (e.g. Orca's Codex launch) needs the codex wrapper. The selection
// is baked into the init command, so fish needs no feature env var.
if (shellName === 'fish' && (features.includes('ready') || options.hasStartupCommand)) {
// Why: mirrors local-pty-shell-ready.ts. The selection is baked into the init
// command, so fish needs no feature env var.
if (shellName === 'fish') {
return {
args: [
'-l',
Expand Down
14 changes: 11 additions & 3 deletions src/main/ipc/command-path-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,16 @@ export async function isCommandOnLocalPath(
command: string,
options: ResolveCommandOptions = {}
): Promise<boolean> {
return (await resolveCommandOnLocalPath(command, options)) !== null
}

/** The absolute path `isCommandOnLocalPath` found, or null. */
export async function resolveCommandOnLocalPath(
command: string,
options: ResolveCommandOptions = {}
): Promise<string | null> {
if (!command) {
return false
return null
}
const platform = options.platform ?? process.platform
const env = options.env ?? process.env
Expand Down Expand Up @@ -98,9 +106,9 @@ export async function isCommandOnLocalPath(
continue
}
if (await isExecutableFile(candidate, isWin)) {
return true
return candidate
}
}
}
return false
return null
}
15 changes: 13 additions & 2 deletions src/main/ipc/pty/ipc/spawn-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { ptySizes } from '../delivery/visibility-state'
import { shouldSeedPreAttachPtySize } from '../delivery/attached-pty-size'
import { getStartupTerminalIngressIntent } from '../../terminal-startup-color-query-replies'
import { resolveConfiguredTerminalShellArgs } from '../configured-terminal-shell-args'
import { planCodexNoDaemonLaunch } from '../../../pty/codex-no-daemon-launch-command'
import type { PtyIpcSpawnState } from './spawn-state'

/** Carries deletions to provider-owned environments, including persistent older daemons. */
Expand Down Expand Up @@ -77,8 +78,18 @@ export async function buildPtyIpcSpawnOptions(
if (ctx.combinedEnvToDelete) {
ctx.spawnOptions.envToDelete = ctx.combinedEnvToDelete
}
if (ctx.launchCommand !== undefined) {
ctx.spawnOptions.command = ctx.launchCommand
const noDaemonLaunch =
args.connectionId || ctx.codexSelectionTarget.runtime === 'wsl'
? null
: planCodexNoDaemonLaunch({
command: ctx.launchCommand,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This planner only receives the PTY launch command, so a wait-for-setup Codex launch slips through: runtime-local-worktree-terminal-startup.ts:79-93 replaces the launch command with a sequencing gate and moves the real Codex command into env ORCA_SEQUENCED_STARTUP_COMMAND, whose gate shell (bash -lc on POSIX, -NoProfile -NonInteractive PowerShell on Windows) never sources the Orca wrapper — so neither this flag nor the shell function reaches Codex, and #22873 persists. The runtime call site at src/main/ipc/pty/runtime/spawn-options.ts:105-110 has the same gap.

Technical details
# Sequenced setup launches never get `--no-daemon`

## Affected sites
- `src/main/ipc/pty/ipc/spawn-options.ts:84-89` — planner sees only `ctx.launchCommand`
- `src/main/ipc/pty/runtime/spawn-options.ts:105-110` — same, using `ctx.daemonShellOverride`
- `src/main/runtime/runtime-local-worktree-terminal-startup.ts:79-93` — swaps the launch command for the gate, real Codex command goes to `ORCA_SEQUENCED_STARTUP_COMMAND`
- `src/shared/setup-agent-sequencing.ts:82` — POSIX gate `bash -lc 'eval "$ORCA_SEQUENCED_STARTUP_SCRIPT"'`; `:268` — Windows gate evals `$env:ORCA_SEQUENCED_STARTUP_COMMAND` under a profile-less PowerShell
- `src/main/ipc/pty/host-env/codex-resume.ts:120-137` — existing precedent for rewriting the sequenced env (`stripSequencedStartupResumeArgv`)

## Required outcome
A Codex launch under the `wait-for-setup` policy must receive exactly one `--no-daemon`, including on cmd.exe/Git Bash where no shell function exists.

## Suggested approach
When the env carries `ORCA_SEQUENCED_STARTUP_COMMAND`, apply the same `planCodexNoDaemonLaunch` rule to that string and write the result back into the spawn env (mirroring how resume argv is stripped from it), or emit the flag into the sequenced command before it is stored. Cover the sequenced path in `codex-no-daemon-launch-command.test.ts`.

## Open questions for the human
Is `wait-for-setup` deliberately out of scope for this PR, or should the host-side planner also handle the sequenced command?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Valid, fixed in 985498a. This is a pre-existing gap from #23900 rather than a regression: setup-agent-sequencing-codex-no-daemon.test.ts runs the real POSIX gate and shows main running codex --yolo. Instead of a host-side rewrite, the gate's bash -lc script now defines the same codex function (moved to src/shared/codex-shell-function.ts). That way it checks the binary the gate actually runs after the login profile, and it also covers SSH gates. The PowerShell gate (native Windows runner) is left as-is: it is typed as an -EncodedCommand whose size is limited by cmd.exe's 8191-character command line. That remains a documented gap.

shellOverride: ctx.effectiveShellOverride,
env: ctx.spawnEnv,
cwd: ctx.cwd
})
const launchCommand = noDaemonLaunch ? await noDaemonLaunch : ctx.launchCommand
if (launchCommand !== undefined) {
ctx.spawnOptions.command = launchCommand
}
if (args.commandDelivery !== undefined) {
ctx.spawnOptions.commandDelivery = args.commandDelivery
Expand Down
15 changes: 13 additions & 2 deletions src/main/ipc/pty/runtime/spawn-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { CLAUDE_AUTH_ENV_VARS } from '../../../claude-accounts/environment'
import { LEGACY_TERMINAL_SHIM_REMOTE_ENV_KEYS } from '../../../pty/legacy-terminal-shim-dir'
import { PI_PROCESS_OWNER_ENV_KEYS } from '../../../pty/pi-process-owner-env'
import { resolveConfiguredTerminalShellArgs } from '../configured-terminal-shell-args'
import { planCodexNoDaemonLaunch } from '../../../pty/codex-no-daemon-launch-command'
import { resolveStablePaneOwner } from '../pane/stable-owner'
import { getStartupTerminalIngressIntent } from '../../terminal-startup-color-query-replies'
import {
Expand Down Expand Up @@ -98,8 +99,18 @@ export async function buildRuntimePtySpawnOptions(
}
deleteRequestedEnvKeys(ctx.env, ctx.spawnOptions.envToDelete)
promoteAgentTeamsShimPath(ctx.env, ctx.requestedAgentTeamsPath)
if (ctx.launchCommand !== undefined) {
ctx.spawnOptions.command = ctx.launchCommand
const noDaemonLaunch =
args.connectionId || ctx.codexSelectionTarget.runtime === 'wsl'
? null
: planCodexNoDaemonLaunch({
command: ctx.launchCommand,
shellOverride: ctx.daemonShellOverride,
env: ctx.env,
cwd: ctx.cwd
})
const launchCommand = noDaemonLaunch ? await noDaemonLaunch : ctx.launchCommand
if (launchCommand !== undefined) {
ctx.spawnOptions.command = launchCommand
}
if (args.commandDelivery !== undefined) {
ctx.spawnOptions.commandDelivery = args.commandDelivery
Expand Down
2 changes: 1 addition & 1 deletion src/main/powershell-osc133-bootstrap.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getPowerShellOmpShellWrapper } from './pty/omp-shell-wrapper'
import { getPowerShellCodexShellLaunchPreflight } from './pty/codex-shell-launch-preflight'
import { getPowerShellCodexShellLaunchPreflight } from '../shared/codex-shell-function'
export { encodePowerShellCommand } from '../shared/powershell-command-encoding'

/**
Expand Down
70 changes: 70 additions & 0 deletions src/main/providers/configured-shell-args-wrapping.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { mkdtempSync, rmSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { createPtyShellLaunchPlan } from '../daemon/pty-subprocess/shell-launch-plan'
import { createDaemonPtyEnvironment } from '../daemon/pty-subprocess/spawn-environment'
import { finalizeLocalPtySpawnEnvironment } from './local-pty-finalize-environment'
import { createLocalPtyLaunchPlan } from './local-pty-launch-plan'

// Why: a plain tab launched with the user's configured shell args stays exactly
// their shell; Orca wraps it only when it needs a feature (e.g. zsh history).
const CONFIGURED_ARGS = ['--custom-arg']
const SHELLS = ['/bin/bash', '/bin/zsh', '/usr/bin/fish']

describe.skipIf(process.platform === 'win32')('plain tabs with configured shell args', () => {
let userData: string

beforeEach(() => {
userData = mkdtempSync(join(tmpdir(), 'orca-configured-shell-args-'))
vi.stubEnv('ORCA_USER_DATA_PATH', userData)
// Why: the daemon env inherits this process's; a parent's zsh or history setting must not leak in.
vi.stubEnv('ZDOTDIR', undefined)
vi.stubEnv('ORCA_HISTFILE', undefined)
})

afterEach(() => {
vi.unstubAllEnvs()
rmSync(userData, { recursive: true, force: true })
})

it.each(SHELLS)('daemon transport keeps %s unwrapped on the configured args', (shell) => {
const opts = {
sessionId: 'configured-args',
cols: 80,
rows: 24,
cwd: userData,
shellOverride: shell,
terminalShellArgs: CONFIGURED_ARGS
}
const env = createDaemonPtyEnvironment(opts)

const plan = createPtyShellLaunchPlan(opts, env)

expect(plan.shellArgs).toEqual(CONFIGURED_ARGS)
expect(env.ZDOTDIR).toBeUndefined()
expect(env.ORCA_SHELL_FEATURES).toBeUndefined()
})

it.each(SHELLS)('local transport keeps %s unwrapped on the configured args', (shell) => {
const spawn = {
cols: 80,
rows: 24,
cwd: userData,
shellOverride: shell,
terminalShellArgs: CONFIGURED_ARGS
}
const getOptions = () => ({})
const plan = createLocalPtyLaunchPlan(spawn, getOptions)
if (!('shellArgs' in plan)) {
throw new Error('expected a resolved posix launch plan')
}
const env: Record<string, string> = { HOME: userData }

finalizeLocalPtySpawnEnvironment({ spawn, getOptions, plan, env })

expect(plan.shellArgs).toEqual(CONFIGURED_ARGS)
expect(env.ZDOTDIR).toBeUndefined()
expect(env.ORCA_SHELL_FEATURES).toBeUndefined()
})
})
Loading
Loading