Skip to content

Codex is undetectable at runtime: CODEX_HOME is not exported, so #460's routing never fires and every Codex session still bills Anthropic #463

Closed

Description

@fdaviddpt

Observed immediately after #462 merged (main at 60837af), on codex-cli 0.150.1, macOS 15.3.2 arm64.

Symptom

A Codex session saved memory — the first time that has been observed — and the log names the provider it used:

13:56:38 [write] appended (provider: claude): ## 13:56 | master

provider: claude. #460 shipped Codex-native routing, every test passes, and it does not fire. A Codex session still shells claude -p and still bills Anthropic.

The provider field that makes this visible is #461's, on its first live run. Without it this would have looked like a complete success.

Location

pipeline/host.py:

CODEX = Host(
    name="codex",
    plugin_root_vars=("PLUGIN_ROOT", "CLAUDE_PLUGIN_ROOT"),
    project_dir_vars=("CLAUDE_PROJECT_DIR",),
    signature_vars=("CODEX_HOME", "PLUGIN_ROOT"),
)

Mechanism

Neither signature variable exists in a process Codex spawns. Dumped from inside a live codex exec session:

CODEX_CI=1
CODEX_SANDBOX=seatbelt
CODEX_SANDBOX_NETWORK_DISABLED=1
CODEX_SESSION_ID=01a04d61-6b17-7e53-8d08-5866df34f967
CODEX_THREAD_ID=01a04d61-6b17-7e53-8d08-5866df34f967

No CODEX_HOME, no PLUGIN_ROOT. CODEX_HOME is a configuration path Codex reads, not a variable it exports to children — the distinction that makes it useless as a runtime signature. PLUGIN_ROOT is likewise absent.

So detect_host() cannot return CODEX on any machine, and the fix #460 shipped is unreachable in production while passing every test, because the tests set the signature variables the implementation expects rather than the ones the host actually sets.

That is the real lesson here and it is worth writing into whatever fix lands: a test that constructs its own environment cannot discover that the environment is wrong. Only running the binary can, and running the binary is what found this.

A second, distinct defect in the same read

The dump also carries the environment of the session that launched Codex:

CLAUDE_CODE_ENTRYPOINT=cli
CLAUDE_CODE_SESSION_ID=9059bdf0-e8fb-4f1b-a205-2c2783d46788

Those are CLAUDE_CODE's signature, CLAUDE_CODE is tested first in REGISTRY, so detection would have answered claude-code even if the Codex signature were correct.

Grade this one honestly: it is partly an artefact of how the probe ran. Codex was launched from inside a Claude Code session, which a user typically would not do. But it is not only an artefact — nested agents are a real configuration, this project is itself an agent plugin, and a detector that inherits an ancestor's identity is wrong in a way that will resurface. The precedence comment in REGISTRY reasons about aliases (Codex setting CLAUDE_PLUGIN_ROOT); it does not reason about inheritance, which is a different failure and is not covered.

What would settle it

  1. Replace CODEX_HOME with a variable Codex actually exports. CODEX_SESSION_ID and CODEX_THREAD_ID are both present and both specific; CODEX_SANDBOX is present but describes a mode rather than the host. Read this off a live dump rather than off this issue — the list above is one version on one platform.
  2. Decide what detection does when two hosts' signatures are present at once. Today it silently prefers whichever is earlier in the registry. The honest options are to prefer the innermost host, or to report ambiguity as its own state — and, given every other three-state rule in this repository, the second deserves real consideration rather than being dismissed as over-engineering.
  3. Pin the fix against a recorded real environment, not a constructed one. A fixture captured from a live codex exec would have failed the moment CODEX_HOME was chosen.

Release impact

This blocks the v0.24.0 tag. Multi-host support is that release's headline, and its central promise — a Codex session that does not depend on, or bill, a foreign CLI — is not delivered by the merged code. The tag waits until a Codex session logs provider: codex.

Follows #460 and #461.

Metadata

Metadata

Assignees

Labels

bugpriority:high

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions