ZhuLinsen/daily_stock_analysis · error · CodexAppServerError

command_not_found

command_not_found

Error message

Codex executable was not found

What it means

resolve_command() uses shutil.which() to locate the codex executable on PATH and raises command_not_found when it resolves to None. This is the first POSIX-side validation after the Windows check, before any '-c' overrides are appended.

Source

Thrown at src/agent/codex_app_server_transport.py:1063

                    time.sleep(0.02)

            if process.poll() is None or _process_group_alive(process_group_id):
                raise CodexAppServerError(
                    "resource_cleanup_failed",
                    "Codex App Server process group could not be reclaimed",
                )


def resolve_command(executable: str = "codex") -> list[str]:
    """Resolve the fixed App Server argv and least-privilege overrides."""
    if is_native_windows():
        raise CodexAppServerError(
            "capability_unsupported",
            "Codex App Server Agent is not supported on native Windows in this phase",
        )
    resolved = shutil.which(executable)
    if resolved is None:
        raise CodexAppServerError("command_not_found", "Codex executable was not found")
    command = [resolved, "app-server", "--stdio"]
    for override in _BASE_CONFIG_OVERRIDES:
        command.extend(["-c", override])
    return command


def harden_command_against_configured_mcp(
    command: Sequence[str],
    *,
    timeout: float,
    deadline: Optional[float] = None,
    cancel_event: Optional[threading.Event] = None,
) -> list[str]:
    """Discover effective MCP config keys, then disable each via transient overrides."""
    empty_surface = ToolSurface.empty()
    with CodexAppServerTransport(
        command,
        tool_surface=empty_surface,

View on GitHub (pinned to 5159bd72e8)

Solutions

  1. Install the codex CLI and verify with `codex --version` from the same shell/environment the app runs in
  2. If the app runs as a service, set PATH explicitly in its unit/env or pass an absolute executable path
  3. Pass executable='/abs/path/codex' to resolve_command()/build_hardened_command() instead of relying on PATH lookup
  4. In containers, add the codex install step to the image build

Example fix

// before
command = resolve_command()  # raises if 'codex' not on PATH

// after
codex_path = os.environ.get("CODEX_BIN") or shutil.which("codex")
if not codex_path:
    raise RuntimeError("install codex CLI or set CODEX_BIN")
command = resolve_command(executable=codex_path)
Defensive patterns

Strategy: validation

Validate before calling

import shutil

codex = shutil.which("codex")
if codex is None:
    raise RuntimeError("codex CLI not found on PATH; install it or set CODEX_BIN")

Prevention

When it happens

Trigger: constructing the transport on a machine where the codex CLI is not installed, not on PATH for the running process's environment (service/daemon PATH differs from login shell), or the configured executable name points to nothing.

Common situations: Fresh machines without codex installed; Docker images missing the codex binary; systemd/launchd services with minimal PATH; virtualenvs where PATH is rewritten; typos in a configurable executable name.

Related errors


AI-assisted analysis of ZhuLinsen/daily_stock_analysis@5159bd72e8 (2026-08-15). Data as JSON: /api/errors/ed18415514dd41d8. Report an issue: GitHub.