Unified exec can omit command output when its completion listener starts late or falls behind
What issue are you seeing?
Unified exec can receive stdout or stderr from a command and still leave those bytes out of the completed tool result. Since Codex uses that result to decide what to do next, it can miss the line that explains a failure, a timeout, or a successful command.
Both the local output collector and the completion watcher read from broadcast receivers that can miss chunks sent before subscription or after falling behind.
The local output collector skips lagged chunks:
Err(tokio::sync::broadcast::error::RecvError::Lagged(_)) => continue,
The completion watcher uses the same handling while it builds the final transcript. If it subscribes late or falls behind, it can't recover the missing chunks.
What steps can reproduce the bug?
- Start a local process through unified exec.
- Let the process emit output before
start_streaming_outputsubscribes, or send enough output for the receiver to reportLagged. - Let the process complete.
- Check the completed command item.
The completed result can omit output that UnifiedExecProcess already received.
I added one test that sends output before start_streaming_output subscribes. I added another that forces a live receiver to report Lagged. I also ran the lag test with invalid UTF-8 and added a test that checks a partial streaming transcript is replaced with the process-owned copy.
What is the expected behavior?
The completed command result should include the output received by UnifiedExecProcess within the existing output cap, regardless of when the completion listener subscribes or whether it falls behind.
Additional information
Proposed change:
This implementation adds a second HeadTailBuffer to UnifiedExecProcess. Each output chunk goes into that buffer before Codex broadcasts it. When output closes, the completion watcher replaces its partial transcript with the retained copy.
The completed command result then no longer depends on whether the listener kept up.