Fix terminal history truncation when clearing multi-line input #7433
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
Fix terminal history truncation that can occur when clearing a multi-line input with
Ctrl+Cafter a/statuscommand, and add a regression test around the TUI history handling.Why
In some cases the Codex CLI would appear to "lose" earlier parts of the session history, including the initial
/statuscommand and even parts of the welcome banner, after the following sequence:/statusand wait for the status card to finish rendering.1\n2\n...\n30\n).Ctrl+Conce to clear the input.Ctrl+Cagain.After a few repetitions, earlier history from the terminal scrollback (including
/statusoutput, and sometimes the>_ OpenAI Codex (v...)banner) would intermittently disappear and could not be recovered by scrolling.This change fixes that behavior in the TUI so that the terminal history remains intact when clearing multi-line input, even after repeated
Ctrl+Coperations.How
Ctrl+Cclearing.The new test fails before this fix and passes after it, which helps guard against regressions in this area.
Notes / Related Issues
This should improve the behavior described in Codex Truncates Chat Messages When Scrolling #6427 and also help with similar cases like Codex client output truncated when scrolling in Zellij #2558 where terminal history appeared to be lost.
Once history is preserved more reliably, it becomes easier to notice another, possibly related, issue: occasionally Codex will emit very large outputs directly into the normal conversation stream instead of folding them into the history view (
Ctrl+T). For example, during testing I observed a run of:which produced tens of screens of output in the primary chat view without being folded.
These sporadic, unfolded long outputs might have contributed to earlier reports of history "disappearing", since they can push a large amount of content through the terminal and interact badly with scrollback limits.
I am happy to adjust the test naming or structure if you prefer a different place for this regression test.