Skip to content

Codex adapter: false error categorization from broad string matching in output #49

@denash84

Description

@denash84

Problem

The Codex adapter's SendMessage error detection in pkg/adapters/codex.go uses broad strings.Contains() checks on the combined stdout+stderr output. When Codex is killed by a timeout (context deadline), the partial output often contains strings that trigger incorrect error categorization:

  • strings.Contains(outputStr, "not found") — matches Codex's normal file-not-found errors during codebase scanning, but reports as "codex model not found"
  • strings.Contains(outputStr, "401") || strings.Contains(outputStr, "unauthorized") — can match content in files Codex reads, but reports as "codex authentication failed"
  • strings.Contains(outputStr, "terminal") || strings.Contains(outputStr, "tty") — can match content in Codex's stderr, but reports as "codex requires non-interactive mode"

Observed behavior

With Codex CLI v0.114.0 and agentpipe v0.7.0, a typical council run shows alternating errors for the same agent:

[09:27:29] ERROR - Codex Implementer: attempt 1/4 failed: codex authentication failed - check API keys
[09:29:31] ERROR - Codex Implementer: attempt 2/4 failed: codex authentication failed - check API keys
[09:31:35] ERROR - Codex Implementer: attempt 3/4 failed: codex authentication failed - check API keys
[09:33:43] ERROR - Codex Implementer: attempt 4/4 failed: codex requires non-interactive mode: {"type":"thread.started",...}

The actual root cause is simply a timeout — Codex takes >120s scanning files, gets killed, and the partial output triggers the wrong error branch.

Suggested fix

Make error detection more specific:

  • Check for "model" AND "not found" together (not just "not found" alone)
  • Check HTTP status codes more precisely (e.g., parse JSON error responses)
  • Add a separate timeout-specific error message when the context deadline is exceeded
  • Consider checking ctx.Err() == context.DeadlineExceeded before pattern-matching the output

Environment

  • agentpipe v0.7.0
  • Codex CLI v0.114.0
  • macOS (arm64)
  • Codex auth mode: chatgpt (OAuth, not API key)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions