Separate Streams Before You Grade: An Ingest Gate for Codex CLI Eval Runs
A golden-case harness can fail before grading: at ingest. If the grader reads a merged capture, it cannot tell whether a matching string came from the CLI's final message or from diagnostics. The official OpenAI Codex CLI non-interactive documentation establishes the relevant boundary: in the default output mode, progress goes to stderr and the final agent message goes to stdout; with JSON Lines output, stdout becomes a JSON Lines event stream in which each line is a JSON object. The supplied documentation describes channel separation and JSON Lines shape; it does not supply an event schema or an exit-code table.
The ingest problem
The following scenario is illustrative, not a recorded incident. A harness merges stdout and stderr and then searches the combined text for a golden substring. This loses provenance. If any text on either channel contains the substring, the search can match, but the harness cannot prove the match came from the final message. The result may be a false pass or an ambiguous pass; the exact outcome depends on what the CLI emitted. The structural point is simpler: a merged stream cannot answer the question the grader asks.
Who faces it and what is assumed
This applies to teams using golden cases with non-interactive coding agents, especially when verdicts are retained and compared later. Prerequisites are a documented non-interactive mode, a pinned CLI version per run, a JSON parser, and an explicit error type. The constraint is that the documentation claim is about defaults, not a guarantee that every future version keeps the same event shapes. The harness should treat the stream boundary and event vocabulary as versioned until verified against the pinned version.
Step 1: Preserve three facts per attempt
Capture exit status, stdout, and stderr as separate artifacts. Record the CLI version and a timestamp with them. Do not grade stderr. Do not collapse an empty stdout into stderr or into a generic failure message. An empty stdout is a case to adjudicate, not noise to be smoothed over. Exit-code interpretation must also be explicit, because the supplied documentation does not define a success mapping for every code.
Step 2: Observe the event stream before writing a parser
Before writing an extractor, capture one raw JSON Lines stdout fixture from a simple task on the pinned CLI version, with stderr stored separately. This is a proposed observation check, not an executed one. Inspect each parsed line. Enumerate top-level keys, candidate discriminator fields, and observed values. Do not assume a field named type. Record the observed event kinds and shapes alongside the CLI version. When the version changes, repeat the observation before trusting the old extractor. If the discriminator or value set differs, mark the extractor stale and fail closed rather than grading whatever text remains.
Step 3: Make ingest fail closed
The extractor should have one responsibility: turn a run's event stream into exactly one non-empty final message, or raise an ingest error. In prose: read each line; parse each line strictly as JSON; a malformed line raises an error. Classify each parsed object using the mapping derived from Step 2. An unknown event kind raises an error. Count final-message candidates. If the count is not exactly one, raise an error. Convert the candidate to text using the observed shape. If the text is empty or whitespace-only and the harness policy requires an answer, raise an error. Never return stderr, fallback text, or a silent empty string.
Retries need separate treatment. Each retry is a separate attempt with its own event stream and its own attempt record. Do not append two final messages into one attempt, and do not let a second final message overwrite the first.
Step 4: Record one attempt-level trace
Each attempt gets one record, and the grader reads only that record. Useful fields include attempt identifier, pinned CLI version, exit code, ingest status, error class when ingest fails, final-message hash, stderr line count, and event count. The hash matters more than it looks: it lets a reviewer confirm that two verdicts were computed from byte-identical extracted text without storing the text twice. The record should also make it clear whether a non-zero exit was treated as a run failure by policy.
Step 5: Grade only the extracted text
Point the grader at the extractor's single returned message. Nothing else. If grader code reads stdout, stderr, or the raw event stream directly, it reintroduces the original defect through a side door. Diagnostic metadata in the attempt record is fine for reporting; it is not grading input.
Verification: constructed canary fixtures
Before trusting a green suite, test the harness against synthetic fixtures with known verdicts. These are constructed inputs, not tool output. They test harness policy, not the CLI's current behavior. The official source supports the channel and JSON Lines claims; it does not validate these expected verdicts.
| Fixture | Constructed input | Expected harness verdict |
|---|---|---|
| clean | exactly one final event, non-empty text containing the golden substring; exit 0 | PASS |
| no_final | zero final events; stderr contains the golden substring | FAIL: ingest error; proves diagnostics are not graded |
| empty_text | one final event whose extracted text is empty or whitespace; exit 0 | FAIL: ingest error by policy |
| nonzero_exit | non-zero exit, one non-empty final message | FAIL at run level under the default policy; encode documented task exceptions explicitly and test them separately |
| two_finals | two final events | FAIL: ingest error; retries must be separate attempts |
| bad_line | one malformed JSON line | FAIL: ingest error |
The no_final canary is the one that catches a harness still reading a merged stream somewhere. The empty_text canary catches an extractor that counts events but never checks whether the result is usable. When a fixture mismatches, first check whether the capture path merged channels, then check whether the extractor silently skipped an unknown event or accepted an empty final message. Re-observe the pinned version's event shapes if the mismatch points to classification.
Common failure modes
- Reading a terminal transcript instead of redirected channels. Terminal capture mixes streams and adds prompt decoration.
- Choosing goldens that can appear in diagnostics. If the pinned CLI or wrapper echoes the prompt or repeats inputs in progress output, a prompt-derived golden can match without an answer. Verify the pinned version and prefer result-only substrings.
- Treating unknown events as ignorable. Skipping them converts a schema mismatch into a silent partial read.
- Merging retries into one attempt. Two attempts in one record hide which attempt produced the graded text.
- Not checking byte counts. A truncated stdout capture can look like an empty answer.
Tradeoffs and limits
A strict extractor costs flexibility. If event shapes change, runs fail closed, so budget time for a re-observation after upgrades. For quick throwaway checks, stream separation is overkill; for verdicts compared week to week, it is one of the cheapest parts of the harness to get right.
The approach does not apply when the artifact is not the message. If the task edits files in a workspace, grade the file diff and treat the final message as commentary. Ingest gating then protects the commentary channel, not the verdict. It also does not apply when a tool offers no machine-readable boundary at all. In that case a sentinel delimiter around the answer is a weaker substitute: it is still parsing human text, and it still needs canary fixtures to prove the delimiter is not being spoofed by progress output.
AI assistance: This draft was produced with AI assistance as a non-promotional educational article. It contains an explicitly illustrative scenario and proposed checks; no command or fixture was run. A human should verify the pinned CLI's documented behavior, event shapes, exit-code policy, and current DEV AI-content policy before posting. This article was created with AI assistance.
Top comments (0)