codex icon indicating copy to clipboard operation
codex copied to clipboard

Command output not shown to the screen if output is printed before a delay

Open user202729 opened this issue 5 months ago • 1 comments

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

user202729 avatar Jun 14 '26 16:06 user202729

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.

wgu9 avatar Jun 15 '26 02:06 wgu9