TUI paste failure during streaming can hide assistant message prefix
What version of Codex CLI is running?
codex-cli 0.146.0
What subscription do you have?
Not relevant to local TUI transcript rendering.
Which model were you using?
The issue reproduces in the client-side transcript path and is independent of the model.
What platform is your computer?
Microsoft Windows NT 10.0.19045.0 x64
What terminal emulator and version are you using (if applicable)?
Windows Terminal with PowerShell 7.6.4.
Codex doctor report
{
"overallStatus": "ok",
"codexVersion": "0.146.0",
"platform": "windows-x86_64",
"terminal": "Windows Terminal",
"os": "Windows 10.0.19045 (Windows 10 Pro) [64-bit]"
}
What issue are you seeing?
If an image-paste attempt fails while an assistant response is streaming, the
visible TUI transcript can lose the prefix of the finalized assistant message.
The raw rollout still contains the complete assistant message.
In a real session, the paste error was rendered between provisional assistant
cells. The exported visible transcript retained the numbered body after the
error, but omitted the introductory line that was present in the corresponding
raw response_item.
This is a transcript consolidation problem rather than model-output loss.ChatWidget immediately commits the paste error as a history cell. At response
completion, handle_consolidate_agent_message only consolidates the trailing
contiguous run of AgentMessageCells. The interleaved error cell splits that
run, so the earlier provisional assistant cell is left outside the canonicalAgentMarkdownCell replacement.
Relevant source locations on current main:
codex-rs/tui/src/chatwidget/interaction.rs: theCtrl+V/Alt+Verror
path calls add_to_history(new_error_event(...)) immediately.
codex-rs/tui/src/app/agent_message_consolidation.rs:
handle_consolidate_agent_message uses a contiguous trailing-run search
before replacing provisional cells with the finalized markdown cell.
What steps can reproduce the bug?
- Start a Codex TUI task that produces a response long enough to stream several lines.
- Put plain text, not an image, on the clipboard.
- While the assistant response is still streaming, press
Alt+Vto triggerFailed to paste image: no image on clipboard. - Let the response complete.
- Inspect or export the visible transcript and compare the finalized assistant message with the session rollout JSONL.
A deterministic app-level regression can model the same ordering with these
committed cells before consolidation:
AgentMessageCell(first line)
PlainHistoryCell(paste error)
AgentMessageCell(stream continuation)
On current main, consolidation leaves four transcript cells where the correct
result has three: prior history, one canonical AgentMarkdownCell, and the
preserved paste error. The failure reproduces consistently in the focused test.
What is the expected behavior?
Finalizing a streamed assistant message must preserve its complete canonical
markdown source even when a local history event is committed during the stream.
The local paste error should remain visible without splitting, replacing, or
hiding any part of the assistant response.
Additional information
A minimal local patch changes agent-message consolidation to find the active
stream across interleaved local history cells, replace all of its provisionalAgentMessageCells with one canonical AgentMarkdownCell, and then preserve
the interleaved cells after that finalized message in their original relative
order. A guard prevents consolidation from crossing a non-stream transcript
tail.
Local validation:
- Regression before the patch: failed consistently with
left: 4,right: 3. - Focused consolidation tests after the patch: 6 passed.
just fix -p codex-tui: passed with no clippy diagnostics.- Human TUI validation on the patched Windows binary: two complete
BEGIN / 1-through-30 / END responses remained intact in both normal
history and the Ctrl+T transcript after four paste-failure events. No
response prefix, body item, or final line was hidden.
- Full
just test -p codex-tui: 3,327 passed; 7 unrelated
app::tests::safety_buffering tests timed out waiting for mock Responses API
requests on this Windows environment. The 7 tests fail identically when run
in isolation and do not touch transcript consolidation.
Related but distinct reports:
- #17103 covers text/image routing for
Ctrl+V; this bug remains possible for
any legitimate image-paste failure during streaming.
- #16801 covers missing reasoning summaries and stream event ordering.
- #15001 covered older subagent replay corruption, not main-TUI history cells
interleaved during agent-message consolidation.
The repository currently accepts external pull requests by invitation only. A
focused commit with the regression test is ready locally. Would maintainers like
this submitted as an invited PR, or prefer a different consolidation invariant?