Duplicate last assistant message when the same text is emitted as both commentary and final answer

Open 💬 1 comment Opened Apr 11, 2026 by ozan-s

What version of Codex CLI is running?

codex-cli 0.120.0

What subscription do you have?

Pro

Which model were you using?

gpt-5.2

What platform is your computer?

Darwin 24.6.0 arm64 arm

What terminal emulator and version are you using (if applicable)?

Ghostty

What issue are you seeing?

I sometimes see the last Codex message twice in a row.

The duplicate appears as a normal assistant message.

This looks like Codex accepting and rendering two assistant message items with identical text but different phases.

Expected behavior: if the final answer is text-identical to the immediately preceding commentary for the same turn, the user should only see one copy.

Actual behavior: both copies are shown.

What steps can reproduce the bug?

Uploaded thread: 019d7bc5-5c69-7b22-a4fe-60c83f9febc6

What is the expected behavior?

Show only single message.

Additional information

Prompt Request to investigate

Investigate a duplicate-assistant-message bug in Codex.

Symptom:
Sometimes the last assistant message appears twice in a row as normal chat output. 

Tasks:
1. Inspect the assistant-message pipeline end to end:
   - Responses/SSE parsing
   - core turn/item handling
   - history/transcript persistence
   - TUI rendering
2. Determine whether Codex can accept two completed assistant message items with identical text but different phases, especially commentary and final_answer.
3. Identify the safest fix location:
   - core/history layer if duplicate content pollutes transcript or future prompt history
   - TUI layer if the problem is display-only
   - both, if needed
4. If the cause is confirmed, implement a fix.
5. Add a regression test for this exact scenario:
   - assistant emits one completed message with phase=commentary
   - assistant emits a second completed message with phase=final_answer
   - both have identical text
   - only one visible assistant message should be shown, and history should not be polluted if that is part of the bug
6. Run the most relevant targeted tests and summarize the outcome.

Deliverables:
- Root cause summary
- Files involved
- Whether the bug was rendering-only or also affected persisted history/prompt inputs
- Patch and regression test if fixed
- Any residual risks or edge cases

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗