fix: stop Codex app-server transcript repeating older messages after idle - #419
Merged
dimavedenyapin merged 1 commit intoJul 15, 2026
Merged
Conversation
reconcileCompletedTurn() re-lists the entire Codex thread on every
turn/completed. The dedup guard (bufferedThreadItemIds) only registered
items that had a top-level `id`, and extractItemId fell back to
`item-${Date.now()}`. But many Codex item types have no `id` — only a
`call_id` or nothing (function_call_output, custom_tool_call_output,
tool_search_output, user/developer input messages). Those id-less items
were therefore re-buffered and re-emitted with a brand-new part id on
every idle, so the transcript repeated older messages after each turn.
Make reconcile buffering idempotent: derive a STABLE key for every item
(id/itemId/call_id, else a deterministic content hash), skip already
buffered items using that key, and forward it as `itemId` so the derived
part id stays stable across passes. Also drop the Date.now() fallback in
extractItemId for a deterministic content-based id.
Adds a regression test proving an id-less tool output is buffered exactly
once across multiple completed turns.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This was referenced Jul 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In the Codex agent transcript, older messages get repeated after the last ongoing idle — every time a Codex turn completes and the thread goes idle, previously-shown messages are re-appended to the transcript, so the conversation keeps growing with duplicates.
Root cause
CodexAppServerAdapter.reconcileCompletedTurn()(added in #412) re-lists the entire thread viathread/items/liston everyturn/completed, to make sure the final assistant message isn't lost. Re-buffering the whole history is only safe if it's idempotent — and it wasn't:bufferedThreadItemIdsonly registered an item whenasString(item.id)was truthy.extractItemId()fell back to`item-${Date.now()}`when no id was found.But many Codex thread item types have no top-level
id— only acall_id, or nothing at all. Verified against real Codex rollout logs (~/.codex/sessions/.../rollout-*.jsonl) for the referenced taskpf-web: analyse slow mongodb queries(thread019f4a0d-e8c7-73f3-8592-6b5f312d1b5b, 12 turns):idfunction_call_output(168×)call_id)custom_tool_call_outputtool_search_outputmessageSo on every reconcile those id-less items bypassed the dedup, got re-buffered, and were re-emitted to the renderer with a fresh
item-${Date.now()}part id that neitherseenPartIdsnor the renderer's id-keyed dedup could collapse → the transcript repeated older messages after each idle.Fix
Make reconcile buffering idempotent for every item:
deriveItemIdentity()derives a stable identity fromid/itemId/call_id.computeThreadItemKey()falls back to a deterministic content hash (turn + type + role + text) when there's no id-like field.bufferReconciledThreadItem()(shared bybufferThreadItemsandbufferAllThreadTurns) skips already-buffered items by that key and forwards it asitemId, so the derived part id stays stable across passes.extractItemId()no longer usesDate.now()— it uses the same stable identity, then a deterministic content hash.Reproduction / test
Added a regression test that fires three
turn/completedreconciles returning the same id-less tool output and asserts it is buffered exactly once (was 3× before the fix).codex-app-server-adaptertests: 19 passing🤖 Generated with Claude Code