Skip to content

Conversation

@muyuanjin
Copy link
Contributor

What

  • Limit the TUI "user shell" output panel by the number of visible screen lines rather than by the number of logical lines.
  • Apply middle truncation after wrapping, so a few extremely long lines cannot expand into hundreds of visible lines.
  • Add a regression test to guard this behavior.

Why
When the ExecCommandSource::UserShell tool returns a small number of very long logical lines, the TUI wraps those lines into many visual lines. The existing truncation logic applied USER_SHELL_TOOL_CALL_MAX_LINES to the number of logical lines before wrapping.

As a result, a command like:

  • Ran bash -lc "grep -R --line-number 'maskAssetId' ."

or a synthetic command that prints a single ~50,000‑character line, can produce hundreds of screen lines and effectively flood the viewport. The intended middle truncation for user shell output does not take effect in this scenario.

How

  • In codex-rs/tui/src/exec_cell/render.rs, change the ExecCell rendering path for ExecCommandSource::UserShell so that:
    • Each logical line from CommandOutput::aggregated_output is first wrapped via word_wrap_line into multiple screen lines using the appropriate RtOptions and width from the EXEC_DISPLAY_LAYOUT configuration.
    • truncate_lines_middle is then applied to the wrapped screen lines, with USER_SHELL_TOOL_CALL_MAX_LINES as the limit. This means the limit is enforced on visible screen lines, not logical lines.
    • The existing layout struct (ExecDisplayLayout) continues to provide output_max_lines, so user shell output is subject to both USER_SHELL_TOOL_CALL_MAX_LINES and the layout-specific output_max_lines constraint.
  • Keep using USER_SHELL_TOOL_CALL_MAX_LINES as the cap, but interpret it as a per‑tool‑call limit on screen lines.
  • Add a regression test user_shell_output_is_limited_by_screen_lines in codex-rs/tui/src/exec_cell/render.rs that:
    • Constructs two extremely long logical lines containing a short marker ("Z"), so each wrapped screen line still contains the marker.
    • Wraps them at a narrow width to generate many screen lines.
    • Asserts that the unbounded wrapped output would exceed USER_SHELL_TOOL_CALL_MAX_LINES screen lines.
    • Renders an ExecCell for ExecCommandSource::UserShell at the same width and counts rendered lines containing the marker.
    • Asserts output_screen_lines <= USER_SHELL_TOOL_CALL_MAX_LINES, guarding against regressions where truncation happens before wrapping.

This change keeps user shell output readable while ensuring it cannot flood the TUI, even when the tool emits a few extremely long lines.

Tests

  • cargo test -p codex-tui

Issue

@muyuanjin muyuanjin force-pushed the bug/shell-output-folding branch from 7c3d715 to 527f85b Compare December 1, 2025 17:06
@etraut-openai etraut-openai merged commit 3395ebd into openai:main Dec 3, 2025
26 checks passed
@etraut-openai
Copy link
Collaborator

Thanks for the contribution!

@github-actions github-actions bot locked and limited conversation to collaborators Dec 3, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TUI user shell output not limited when lines are extremely long

3 participants