fix(tui): limit user shell output by screen lines #7448
Merged
+106
−10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What
Why
When the
ExecCommandSource::UserShelltool returns a small number of very long logical lines, the TUI wraps those lines into many visual lines. The existing truncation logic appliedUSER_SHELL_TOOL_CALL_MAX_LINESto 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
codex-rs/tui/src/exec_cell/render.rs, change theExecCellrendering path forExecCommandSource::UserShellso that:CommandOutput::aggregated_outputis first wrapped viaword_wrap_lineinto multiple screen lines using the appropriateRtOptionsand width from theEXEC_DISPLAY_LAYOUTconfiguration.truncate_lines_middleis then applied to the wrapped screen lines, withUSER_SHELL_TOOL_CALL_MAX_LINESas the limit. This means the limit is enforced on visible screen lines, not logical lines.ExecDisplayLayout) continues to provideoutput_max_lines, so user shell output is subject to bothUSER_SHELL_TOOL_CALL_MAX_LINESand the layout-specificoutput_max_linesconstraint.USER_SHELL_TOOL_CALL_MAX_LINESas the cap, but interpret it as a per‑tool‑call limit on screen lines.user_shell_output_is_limited_by_screen_linesincodex-rs/tui/src/exec_cell/render.rsthat:"Z"), so each wrapped screen line still contains the marker.USER_SHELL_TOOL_CALL_MAX_LINESscreen lines.ExecCellforExecCommandSource::UserShellat the same width and counts rendered lines containing the marker.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-tuiIssue