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_

View original on GitHub ↗

2 Comments

wgu9 · 2 months ago

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.5 produces output early, then keeps the process alive briefly.
  • The model still receives OUTPUT in the tool response, which is why the assistant can correctly print OUTPUT afterwards.
  • 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 OUTPUT avoids 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.rs starts start_streaming_output(...), then separately calls collect_output_until_deadline(...) to build the initial ExecCommandToolOutput snapshot returned to the model.
  • codex-rs/core/src/unified_exec/async_watcher.rs::start_streaming_output emits ExecCommandOutputDelta events used by the TUI.
  • codex-rs/tui/src/chatwidget/command_lifecycle.rs::on_exec_command_output_delta appends those deltas to the active ExecCell.
  • codex-rs/tui/src/exec_cell/render.rs renders (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:

  1. Exercise unified exec with a command that writes output immediately and exits only after a short delay, e.g. printf OUTPUT; sleep 0.2.
  2. Assert both surfaces receive the same output:
  • the ExecCommandToolOutput.raw_output/model response contains OUTPUT;
  • the emitted command-completion item or TUI ExecCell rendered output also contains OUTPUT, 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.

MarPan · 11 days ago

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_execution event contains:

"aggregated_output":"BBB\nCCC\nDDD\nEEE\nFFF\n"

AAA is 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_execution event.

This is particularly problematic for programmatic consumers of codex exec --json, because aggregated_output looks complete but is silently missing part of the command output.