Skip to content

fix(codex): a Codex chat keeps its Orca identity when the user's Codex config strips command environment variables - #30406

Merged
brennanb2025 merged 5 commits into
mainfrom
brennanb2025/codex-chat-shell-env
Oct 19, 2026
Merged

brennanb2025 merged 5 commits into
mainfrom
brennanb2025/codex-chat-shell-env

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​112 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​106
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​66 $\color{#cf222e}{\Huge{\mathbf{−}}}$​24 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​42

ELI5

Some people tell Codex to give the commands it runs only a few basic environment variables ([shell_environment_policy] inherit = "core" in ~/.codex/config.toml). Orca tells a chat's commands which chat they belong to through environment variables, so for those people every orca command a Codex chat ran forgot which chat it was. Orca now tells Codex, for each chat thread, to always keep those few variables.

What Changed

Before: with inherit = "core" (or "none"), a Codex chat asked to coordinate other agents failed at the first step. orca orchestration run-create returned no_active_sender_terminal and told the agent to pass a terminal handle it doesn't have; the agent then tried to open a terminal. As a worker in a workspace with exactly one other terminal, a chat's reply went out under that terminal's name into the wrong Run (tracked in #30402). Inline chat visuals also lost their folder.

After: the chat's commands see its identity whatever the user's Codex policy is, so orchestration and visuals work as they do for everyone else. The user's Codex config is not changed.

Mechanism: Codex rebuilds each command's environment from shell_environment_policy; inherit = "core" keeps only PATH, HOME, USER and a few others, and drops everything Orca put on the Codex process. Every thread start and resume now also sends per-thread config shell_environment_policy.set.<KEY> for the chat's own values: its session id, the "this is a chat" marker, a dispatched worker's own handle, the Orca launcher path, this Orca's data folder, the blanked remote-host selectors, and the visuals folder. Codex applies set after its filter and merges these per key, so the user's inherit and their own set entries stay as written. The step that seals every chat's child process now also returns exactly the values it wrote, and Codex sends those plus the chat's visuals folder, so there is one source of truth: a value later added to that step reaches the commands too, and nothing new is saved. A terminal handle is sent only when that step named one (a registered worker's own handle), never one inherited from the pane that started Orca.

Why

This is the common pattern for a host app whose agent calls back into it through a CLI: hand the per-thread values to Codex as shell_environment_policy.set overrides on every thread open. Alternatives considered:

  • Asking users to change their Codex config: not ours to change, and it broke silently.
  • Moving orchestration from the CLI to agent tools: a different feature, and it would split chat agents from terminal agents.
  • Also forwarding Orca's per-agent custom variables: left out on purpose. Those keep following the user's own Codex policy, exactly as they do for Codex in an Orca terminal; this PR only restores Orca's identity, which the user never chose to strip.

Not covered:

  • PATH (intended): it is not sent. Codex keeps PATH under inherit = "core", and a set PATH would freeze it over the login shell's PATH restore. The chat reaches this Orca through the absolute launcher path (ORCA_CLI_COMMAND) and the data-folder pin (ORCA_USER_DATA_PATH) instead.
  • Codex typed into an Orca terminal (Orchestration loses caller identity in Codex tool shells with inherit = "core" #25775) loses its terminal handle the same way; Orca can't change a command the user typed. Workaround: inherit = "all" with include_only = [..., "ORCA_*"].
  • A user policy with a non-empty include_only: Codex filters set keys too, and overriding that list would replace the user's.

Linked Issue

Linear STA-11090. Tracked in #30402 (the misrouted worker reply; the routing half of that issue is separate).

Visual Proof

Real Codex chat (Codex 0.163.0) in a test copy of Orca on macOS, with the chat's Codex home set to [shell_environment_policy] inherit = "core", same inputs on main and this branch.

Before (main): the chat's orca status cannot find this Orca and run-create fails (the command lost both the chat id and the pin to this Orca instance; an install at the default path instead fails with no_active_sender_terminal, as in the original report).

main, no terminal

main, one terminal open

After (this branch): orca status names the chat as the caller and run-create creates the Run; with one ordinary terminal open, a bare orca orchestration check acts as the chat, not the terminal; a resumed chat in a fresh Codex process keeps its identity; inline visuals still get their folder.

branch, caller and Run created

branch, bare check with one terminal open

branch, cold resume

branch, inline visual

Testing

  • Reproduced before the change with the real Codex 0.162.1 app-server, a throwaway Codex home containing only inherit = "core", and Orca's start and resume requests: commands saw no ORCA_* values; with the overrides they did, on start and on resume.

  • New opt-in test codex-structured-real-cli-command-env.test.ts (ORCA_REAL_CODEX_CLI_TEST=1, POSIX only, no account or model): runs a user shell command (thread/shellCommand) and proves the policy strips the id, then that it survives a new thread and a cold resume. The model's own command tool reads the same shell_environment_policy.set in Codex's source; that path needs a model, so the test doesn't drive it.

  • Updated the adapter test that builds the launch the production way, so CI pins the overrides on the thread request.

  • Six named test files on macOS (M4Air), installed Codex 0.163.0: 64 passed, 0 skipped.

  • Electron QA on macOS with a real Codex chat under inherit = "core", main vs branch (screenshots above): main fails; on the branch the chat is the caller, creates a Run, a bare check acts as the chat with another terminal open, a cold resume keeps the identity, inline visuals work, normal turns complete (4/4).

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • SSH / remote / WSL: native chat launches only on a local host, and the values come from the host that runs Codex, so nothing crosses a host boundary. No wire or saved-data change; Codex 0.136.0 (Orca's floor) already takes per-thread config on start and resume.
  • Windows: same mechanism; the real-binary test is skipped there because its probe is a POSIX command.

Author: Brennan Benson (@BrennanKB5)

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…stricted shell environment policy

Codex rebuilds each command's environment from the user's shell_environment_policy, so
inherit = "core" dropped the chat id, marker, launcher and instance pin Orca gives the
app-server. orca orchestration then could not tell which chat was calling.

Every thread start and resume now sends those values as shell_environment_policy.set
overrides, which Codex applies after its filter and merges per key.
@brennanb2025
brennanb2025 marked this pull request as ready for review October 18, 2026 19:52
@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 50 seconds.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 98988867-63fd-4b49-8bd8-6d55fe17fff6
📥 Commits

Reviewing files that changed from the base of the PR and between d046292 and be7b94c.

📒 Files selected for processing: 6
  • src/main/codex/codex-structured-real-cli-command-env.test.ts
  • src/main/codex/codex-structured-session-acquire.ts
  • src/main/codex/codex-structured-session-state.ts
  • src/main/codex/codex-structured-visuals.test.ts
  • src/main/runtime/structured-agent-launch-composition.ts
  • src/main/runtime/structured-session-child-env.ts

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 820fa4ca-5ebd-4c6a-8e57-3d0eef0b3fc4
📥 Commits

Reviewing files that changed from the base of the PR and between 915923f and d046292.

📒 Files selected for processing: 2
  • src/main/codex/codex-structured-visuals.test.ts
  • src/main/native-chat/native-chat-inline-visuals-setting.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

📝 Walkthrough

Structured sessions now select command environment values from the sealed child and pass them to Codex thread settings. Tests check the resulting configuration, including the absence of visual-related settings when visuals are disabled. An opt-in integration test checks whether a shell command can see the session identity without an override, on a new thread with an override, and on a resumed thread with an override.

Priority: ⬇️ Low

Merge Risk: 🔵 Low · up to d0462

The opt-in integration test may close its app-server before the turn completes, making the cold-resume check flaky. This is a bounded test-reliability risk rather than a demonstrated production-chat failure.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 7 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check Warning The description is detailed and covers the user impact, implementation, rationale, testing, visual proof, platform considerations, and checklist. However, the required Linked Issue section does not pr… Add a direct link to the relevant issue and complete the Fixes # reference. Mark pnpm lint, pnpm typecheck, pnpm test, and pnpm build as passed, or state that CI will cover them.
Passed Passed checks: 3 passed
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly identifies the primary change: preserving a Codex chat's Orca identity when Codex strips command environment variables. It is specific and related to the changeset.
Full details: Description check

Explanation

The description is detailed and covers the user impact, implementation, rationale, testing, visual proof, platform considerations, and checklist. However, the required Linked Issue section does not provide an actual issue link or completed Fixes # reference, and the required validation commands remain unchecked without an explicit CI explanation.

Resolution

Add a direct link to the relevant issue and complete the Fixes # reference. Mark pnpm lint, pnpm typecheck, pnpm test, and pnpm build as passed, or state that CI will cover them.

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e75dc5b8-bd31-4160-be85-4e50d99a72df
📥 Commits

Reviewing files that changed from the base of the PR and between 63f0cb9 and 915923f.

📒 Files selected for processing: 5
  • src/main/codex/codex-structured-real-cli-command-env.test.ts
  • src/main/codex/codex-structured-session-acquire.ts
  • src/main/codex/codex-structured-session-adapter.test.ts
  • src/main/codex/codex-structured-thread-open.ts
  • src/main/runtime/structured-session-child-env.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

…econd key list

The seal now returns the session values it set (identity, a registered worker's own handle, the CLI launcher, the instance pin and the blanked remote selectors) as commandEnv, and the composed launch carries it. The Codex acquire sends that plus the chat's scratch folder from its own visuals. This deletes the hand-kept key list, the handle prefix test and the delete-list re-check, so a key later added to the seal reaches each command too, and an inherited worker handle the seal never named no longer does.
@brennanb2025

brennanb2025 commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Codex chats could lose their Orca identity when a user limited shell commands to core environment variables. Codex filtered the values Orca put on its process, so a chat could fail to create an orchestration Run or act as another terminal.

The branch passes the chat’s own identity and CLI connection values through Codex’s per-thread environment settings on start and resume. Commands can identify the chat again, and inline visuals retain their folder, without editing the user’s Codex configuration.

Round 2 continues the original review. The independent re-review agreed that all three items were fixed: the launch seal now returns the values it writes instead of maintaining a second selection list; the real-binary test accurately describes its user-shell-command coverage; and the PR body labels the deliberate PATH omission. No proven new issue was found. Readiness and performance source checks passed on 63ffaf95406bb536cf35110cc535a15c903d90d3.

Verified on that commit:

  • The full PR Checks workflow, including its aggregate gate, passed.
  • All six named files passed on the M4Air: 64 tests, zero failures or skips. Installed Codex 0.163.0 ran the opt-in test for stripped identity, a new thread, and cold resume.
  • Test-launch config hashes matched, the worktree remained clean, and the test processes were cleaned up. Config hashes also changed earlier during dependency setup; the writer is unproven, so the whole setup interval is not claimed unchanged.

Deferred: non-empty include_only policies still filter these values; overriding a user’s list is outside this change. A source concern about closing the test app-server before resume persistence remains unproven and did not reproduce in the real-binary run.

Electron QA passed on 63ffaf95406bb536cf35110cc535a15c903d90d3 (macOS, M4Air, real Codex 0.163.0 chat with inherit = "core", main vs branch with the same inputs). An earlier Windows attempt could not start a QA worker (Codex there isn't signed in; its Claude CLI is too old for the 1M model), so it moved to the M4Air.

  • Main: the chat's orca status couldn't find this Orca and run-create failed. The command lost the chat id and the pin to this Orca instance; an install at the default path fails with no_active_sender_terminal instead. (no terminal, one terminal)
  • Branch: the chat is the caller and run-create creates the Run (screenshot); with one ordinary terminal open, a bare check acts as the chat (screenshot); a resumed chat in a fresh Codex process keeps its identity (screenshot); inline visuals get their folder (screenshot); normal turns complete (4/4). These commands ran through the model's own command tool, so that path is now verified at runtime too.
  • All test processes stopped by recorded PID; worktree clean. The machine's real Codex config files changed about 35 seconds after the test copy had exited, written by a real-home process on the shared machine (not the test copy, which used a throwaway home); every Orca hook entry in them is still present and enabled.

Since QA: one test-only commit, be7b94c6a78. The opt-in real-Codex test now waits for the shell command's turn/completed before the cold resume (the one open review thread, now resolved); it passes against installed Codex 0.162.1. No shipped code changed after the QA head, so QA was not rerun. The full PR Checks workflow passed on be7b94c6a78.

@brennanb2025
brennanb2025 merged commit add1ecc into main Oct 19, 2026
35 checks passed
@brennanb2025
brennanb2025 deleted the brennanb2025/codex-chat-shell-env branch October 19, 2026 07:31
brennanb2025 added a commit that referenced this pull request Oct 19, 2026
…ity, held-send revert

Sleep (#28445) closes a workspace's chats through the same abort a close gives a
registered start, re-aborts a start registered while it waited for the lane, and
judges its receipt once the start it aborted has settled, so only a newer start
reads as later work. Each adapter's owned-acquisition check covers the child it
owns between acquire and open. Main's Sleep cases from the deleted surface
lifetime suite move to the workspace Sleep suite, plus one for a starting agent.

Codex (#30406): the split open sends the chat's command env overrides when it
opens the thread; the adapter test keeps that assertion on the open's request.

Revert of #30134 (#30572): the event sink, exit observation, Pi held-send wrapper
and adapter heldSends overrides go with it; Pi dispatch submits through its
turns again and its idle report is wired back.
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