Skip to content

TUI large paste placeholder number increments after Ctrl+C clears draft #19940

@Sungyoun-Kim

Description

@Sungyoun-Kim

What issue are you seeing?

In the Codex CLI TUI, large paste placeholder numbering appears to be tied to paste attempts rather than the active draft state.

If a large paste inserts a placeholder such as [Pasted Content 1004 chars], pressing Ctrl+C clears the draft, but the next same-size paste renders [Pasted Content 1004 chars] #2 instead of reusing the base placeholder. This makes a fresh draft look like it still contains state from a canceled draft.

This looks similar to #10032, but that was a closed PR, not an issue. The reproduction path here is Ctrl+C draft clearing rather than manually deleting the placeholder. #17203 is related to paste/draft undo behavior, but this is a narrower placeholder numbering bug.

What steps can reproduce the bug?

  1. Open the Codex CLI TUI.
  2. Paste text longer than LARGE_PASTE_CHAR_THRESHOLD so the composer inserts a placeholder, for example [Pasted Content 1004 chars].
  3. Press Ctrl+C to clear/cancel the draft.
  4. Paste the same text again.
  5. Observe that the placeholder becomes [Pasted Content 1004 chars] #2.

I also verified this at unit-test level on main before the fix by adding a test for:

handle_paste -> clear_for_ctrl_c -> handle_paste

The test fails with:

left:  [Pasted Content 1004 chars] #2
right: [Pasted Content 1004 chars]

What is the expected behavior?

After Ctrl+C clears the active draft and pending paste state, the next large paste should be treated as a fresh draft and should reuse the base placeholder label, for example [Pasted Content 1004 chars].

Multiple simultaneously active same-size pending pastes should still receive suffixes such as #2, #3 so they remain distinct.

Additional information

The likely cause is the monotonic large_paste_counters: HashMap<usize, usize> state in the TUI composer. A fix can compute the next suffix from currently active pending_pastes instead of from total paste attempts.

A branch with the change and before/after verification is available here:
https://github.com/Sungyoun-Kim/codex/tree/fix-large-paste-placeholder-numbering

Validated locally:

  • cargo fmt --check
  • cargo test -p codex-tui large_paste_numbering
  • cargo test -p codex-tui placeholder_deletion
  • cargo test -p codex-tui deleting_duplicate_length_pastes_removes_only_target

Metadata

Metadata

Assignees

Labels

TUIIssues related to the terminal user interface: text input, menus and dialogs, and terminal displaybugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions