codex icon indicating copy to clipboard operation
codex copied to clipboard

Fix terminal history truncation when clearing multi-line input

Open muyuanjin opened this issue 2 weeks ago • 3 comments

What

Fix terminal history truncation that can occur when clearing a multi-line input with Ctrl+C after a /status command, 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 /status command and even parts of the welcome banner, after the following sequence:

  1. Start Codex CLI.
  2. Run /status and wait for the status card to finish rendering.
  3. Paste a multi-line input into the prompt (for example 1\n2\n...\n30\n).
  4. Do not send the message; press Ctrl+C once to clear the input.
  5. Paste another multi-line input and press Ctrl+C again.

After a few repetitions, earlier history from the terminal scrollback (including /status output, 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+C operations.

How

  • Add a regression test that exercises the TUI / history path around multi-line input and Ctrl+C clearing.
  • Adjust the TUI history handling so that clearing the input does not cause the underlying recorded terminal history to be truncated.

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 #6427 and also help with similar cases like #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:

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

    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.

muyuanjin avatar Dec 01 '25 06:12 muyuanjin

@codex review

etraut-openai avatar Dec 01 '25 07:12 etraut-openai

Codex Review: Didn't find any major issues. :rocket:

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

This PR should also improve issue #5589. I found the terminal history to be much more stable during testing.

muyuanjin avatar Dec 01 '25 08:12 muyuanjin

After reviewing the PR, we've decided to pass on this fix. While it does mitigate several bugs that were previously reported, it potentially creates other issues.

A member of the codex team is currently working on a significant update to the code that writes cells to the screen. This change aims to address these bugs in a more holistic way.

Thanks again for taking the time to submit the PR.

etraut-openai avatar Dec 05 '25 17:12 etraut-openai