Skip to content

fix(tui): keep /copy aligned with rollback#18739

Merged
fcoury-oai merged 2 commits intomainfrom
fcoury/fix-copy-after-rollback
Apr 20, 2026
Merged

fix(tui): keep /copy aligned with rollback#18739
fcoury-oai merged 2 commits intomainfrom
fcoury/fix-copy-after-rollback

Conversation

@fcoury-oai
Copy link
Copy Markdown
Contributor

@fcoury-oai fcoury-oai commented Apr 20, 2026

Why

Fixes #18718.

After rewinding a thread, /copy could still copy the latest assistant response from before the rewind. The transcript cells were rolled back, but the copy source was a single last_agent_markdown cache that was not synchronized with backtracking, so the visible conversation and copied content could diverge.

What changed

ChatWidget now keeps a bounded copy history for the most recent 32 assistant responses, keyed by the visible user-turn count. When local rollback trims transcript cells, the copy cache is trimmed to the same surviving user-turn count so /copy uses the latest visible assistant response.

If the user rewinds past the retained copy window, /copy now reports:

Cannot copy that response after rewinding. Only the most recent 32 responses are available to /copy.

The change also adds coverage for copying the latest surviving response after rollback and for the over-limit rewind message.

Verification

  • Manually resumed a synthetic 35-turn session, rewound within the retained window, and verified /copy copied the surviving response.
  • Manually rewound past the retained window and verified /copy showed the 32-response limit message.
  • cargo test -p codex-tui slash_copy
  • just fix -p codex-tui
  • cargo insta pending-snapshots

Note: cargo test -p codex-tui currently fails on unrelated model catalog and snapshot drift around the default model changing to gpt-5.4; the focused /copy tests pass after fixing the new test setup.

Track a bounded set of copyable agent responses by visible user turn
so `/copy` follows the transcript after backtracking. When rewind goes
past the retained copy window, report the 32-response limit instead of
copying stale text.

Update rollback handling to trim the copy cache alongside transcript
cells and cover both surviving-response and over-limit rewind cases.
Copy link
Copy Markdown
Collaborator

@etraut-openai etraut-openai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good. I verified the bug before the change and the correct behavior after the change.

@fcoury-oai fcoury-oai merged commit cebe57b into main Apr 20, 2026
25 checks passed
@fcoury-oai fcoury-oai deleted the fcoury/fix-copy-after-rollback branch April 20, 2026 22:24
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 20, 2026
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.

/copy always copies most recent message, even after rewinding

2 participants