Command output not shown to the screen if output is printed before a delay
Open 💬 2 comments Opened Jun 14, 2026 by user202729
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_
2 Comments
I walked the current unified-exec/TUI path, and this looks like a race/ordering bug between the initial
exec_commandtool 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.OUTPUTin the tool response, which is why the assistant can correctly printOUTPUTafterwards.(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:
printf OUTPUT; sleep 0.2.ExecCommandToolOutput.raw_output/model response containsOUTPUT;ExecCellrendered output also containsOUTPUT, never(no output).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.I can reproduce this on codex-cli 0.147.0, and it also affects
codex exec --json, not only the TUI.Minimal reproduction:
codex exec --json 'Run exactly ONE shell tool call containing:
printf "AAA\n"
sleep 0.2
printf "BBB\n"
sleep 0.2
printf "CCC\n"
sleep 0.2
printf "DDD\n"
sleep 0.2
printf "EEE\n"
sleep 0.2
printf "FFF\n"
Do not run these commands separately.' > /tmp/codex-test.jsonl
The completed
command_executionevent contains:"aggregated_output":"BBB\nCCC\nDDD\nEEE\nFFF\n"
AAAis missing.Running the shell command directly produces all six lines:
AAA
BBB
CCC
DDD
EEE
FFF
So the early output appears to be lost before/during aggregation into the final
command_executionevent.This is particularly problematic for programmatic consumers of
codex exec --json, becauseaggregated_outputlooks complete but is silently missing part of the command output.