Command output not shown to the screen if output is printed before a delay
What version of Codex CLI is running?
codex-cli 0.139.0
What subscription do you have?
Enterprise
Which model were you using?
gpt-5.4-mini
What platform is your computer?
No response
What terminal emulator and version are you using (if applicable)?
No response
Codex doctor report
What issue are you seeing?
If the agent runs a command that prints out some output then sleep for a while, the user will incorrectly see (no output).
› Run exactly this command and report the output:
echo OUTPUT; sleep 0.5
• Running the exact command now.
• Ran echo OUTPUT; sleep 0.5
└ (no output)
────────────────────────────────────────────────────────────────────────────────────────────────────
• OUTPUT
────────────────────────────────────────────────────────────────────────────────────────────────────
› Run exactly this command and report the output:
sleep 0.5; echo OUTPUT
• Running the exact command as given.
• Ran sleep 0.5; echo OUTPUT
└ OUTPUT
────────────────────────────────────────────────────────────────────────────────────────────────────
• OUTPUT
────────────────────────────────────────────────────────────────────────────────────────────────────
In the second case, it's correct.
What steps can reproduce the bug?
See above.
What is the expected behavior?
The output is shown as OUTPUT in both cases.
Additional information
No response
I walked the current unified-exec/TUI path, and this looks like a race/ordering bug between the initial exec_command tool response and the TUI command-output event stream.
Why the repro shape matters:
echo OUTPUT; sleep 0.5produces output early, then keeps the process alive briefly.- The model still receives
OUTPUTin the tool response, which is why the assistant can correctly printOUTPUTafterwards. - The visible command cell shows
(no output), so the data reached the model-side tool response but did not reliably reach the TUI command cell. sleep 0.5; echo OUTPUTavoids the issue because the output arrives near process completion, so it is more likely to be included in the final completed command item.
Relevant current code paths:
codex-rs/core/src/unified_exec/process_manager.rsstartsstart_streaming_output(...), then separately callscollect_output_until_deadline(...)to build the initialExecCommandToolOutputsnapshot returned to the model.codex-rs/core/src/unified_exec/async_watcher.rs::start_streaming_outputemitsExecCommandOutputDeltaevents used by the TUI.codex-rs/tui/src/chatwidget/command_lifecycle.rs::on_exec_command_output_deltaappends those deltas to the activeExecCell.codex-rs/tui/src/exec_cell/render.rsrenders(no output)whenever the command cell has an output record but no rendered output lines.
So the bug is likely not shell execution: it is that early output can be present in the initial tool response snapshot while missing from the TUI-visible output-delta/final-aggregated-output path.
Suggested regression test:
- Exercise unified exec with a command that writes output immediately and exits only after a short delay, e.g.
printf OUTPUT; sleep 0.2. - Assert both surfaces receive the same output:
- the
ExecCommandToolOutput.raw_output/model response containsOUTPUT; - the emitted command-completion item or TUI
ExecCellrendered output also containsOUTPUT, never(no output).
- the
The fix should probably keep the final command item as the source of truth for the rendered command cell, or otherwise ensure the initial snapshot output is replayed/merged into the TUI-visible command output when the streaming delta path misses an early chunk.
Per docs/contributing.md, I am not opening a PR unless invited, but I can test a focused patch if maintainers want one.