DEV Community

Jordan Huang
Jordan Huang

Posted on

stdout Is Not the Transcript: A Codex CLI Channel Check for CI

A CI job can print a clean final answer and still hide the run. The wrapper captured stdout. Progress went to stderr. The team then treated the answer as the whole record.

This matters when teams wrap the Codex CLI in shell scripts, Makefiles, or CI steps. The prerequisites are modest: shell redirection, a disposable repository, and the current Codex CLI documentation.

The documented channels

The Codex CLI documentation states that, in the default output mode, the non-interactive command writes progress to stderr and sends the final agent message to stdout. In JSON mode, stdout becomes a JSON Lines event stream. Each line is a JSON object.

Source: Codex CLI non-interactive mode.

Those are different artifacts. They answer different questions. Treating them as one log creates blind spots.

Corrected mental model: three artifacts, not one log

Artifact Channel Good for Failure mode
Final message stdout by default Human-readable result Mistaken for a full run record
Progress stderr by default Diagnostics and timing Dropped by stdout-only wrappers
Event stream stdout in JSON mode Machine parsing Parsed as one JSON document

The final message is an output. Progress is diagnostic context. The event stream is structured data. None of them is, by itself, a complete audit record.

FAQ: four claims to retire

“If stdout has the answer, I have the whole run.”

No. By default, progress goes to stderr. A wrapper that captures only stdout loses that context.

Capture both channels. Keep them separate. Name the files by purpose, not by timestamp alone.

“JSON mode is just formatting.”

No. The documentation describes a JSON Lines event stream. That means one JSON value per line, not one JSON array or object.

Parse line by line. Reject non-JSON lines explicitly. Do not assume the stream is a single document.

“Merging the channels is harmless.”

It is not harmless when one channel is data and the other is diagnostics. Merging them can interleave progress text with JSONL records.

A line-oriented parser may stop at the first bad line. Keep the channels separate unless you control both formats.

“The final message is the test result.”

It is a message. It is not a validation gate by itself.

Validate the artifacts you care about. Check the event records you need. Keep human-readable output for humans.

Edge case: the CI log is truncated

Imagine a CI job that keeps only the last 200 lines. The final answer is short. Progress is long. The useful failure context is gone.

Or the script merges streams. A JSONL parser sees a progress line and stops. Both are channel bugs, not model bugs.

Observation-based channel check (not executed for this article)

This check is illustrative and was not executed for this article. It uses a disposable repository and a small, non-sensitive prompt. A JSON parser is a prerequisite; if the parser is missing, the check is incomplete.

Step 1: Run the CLI in default mode with stdout and stderr captured to separate files. Observe two things: whether the stdout file contains a final message and whether the stderr file contains progress or diagnostics. Interpret a missing stdout file as no captured final message. Interpret an empty stderr file as either no progress or a redirection mistake; check the wrapper before concluding that the CLI produced no diagnostics.

Step 2: Run the CLI in JSON mode with stdout and stderr captured to separate files. Observe whether every stdout line is a JSON object and whether stderr still contains progress. Interpret any non-JSON stdout line as either malformed output or contamination from a merged channel. Interpret JSON-looking stderr as a sign that the wrapper or CLI version changed the documented channel split.

Step 3: Compare the two runs. The default final message and the JSON event stream are different artifacts. Do not use the human final message as a substitute for the event stream, and do not parse the event stream as one JSON document.

Pass condition: the default run shows separate stdout and stderr artifacts; the JSON-mode stdout is valid JSON Lines when parsed line by line; and the JSON-mode stderr is kept separate. This is a channel check, not a correctness test. If automating it, make the parser exit non-zero on invalid lines and declare the parser dependency; otherwise the check can report success while hiding a bad line.

Failure modes to watch

  • Merging stdout and stderr and then parsing JSONL.
  • Capturing only stdout and losing progress context.
  • Treating JSON-mode output as one JSON document.
  • Parsing the human final message as structured data.
  • Logging sensitive prompt or file content in progress output.
  • Assuming channel behavior is stable across CLI versions.

Tradeoffs and limits

Separate channels cost storage and pipeline code. JSONL needs a parser and schema discipline. Human-readable final messages are easier to read but harder to machine-check.

This check does not prove model correctness. It only verifies channel separation. It also does not cover interactive use or every CLI version.

If your wrapper already normalizes events, keep this check as a regression test. Re-read the current documentation after upgrades.

AI assistance and review

AI assistance: This draft was generated with AI assistance. The observation-based check was not executed for this article. A human should verify the current Codex CLI documentation, test in a disposable repository, and check DEV's current AI content policy before publishing.

This article was created with AI assistance.

Top comments (0)