refactor(ai): drop responses replay tombstones - #46965
Merged
Merged
Conversation
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.
Why
ParserStatecarried two tombstone sets,completedMessages(#46064) andcompletedTools(#45789), that ignoredoutput_item.added/output_item.donefor item ids the parser had already finished. #46064 justified this with an OpenAI background-mode stream resumed viastarting_after, where the resumed stream can replay events for already-completed items.Our client never sends
background: trueorstarting_afteron Responses requests and never trackssequence_number; parser state is built fresh per attempt viainitial(request), and a disconnect is a new request rather than a resumed stream. The WebSocket channel continues between turns withprevious_response_id, not mid-stream. So the replayed-event inputs these guards handle cannot reach the parser. The spec side agrees: acompleteditem receives no further updates andoutput_item.addedis emitted once per item.Neither Codex nor pi tracks completed ids or defends against replayed item events, for the same reason — neither resumes streams.
What changes
completedMessagesandcompletedToolsfromParserStateandinitial, plus the branches that consulted or populated them.onOutputItemDonefor a message no longer early-returns when a different message is active; it finalizes its own item and clearsstate.messageonly if that item was the active one.output_item.doneas authoritative). Duplicateaddedfor a still-pending function call is still a no-op viastate.tools.completedCompactionsstays becauseresponse.completed.outputlegitimately re-lists compaction items during terminal recovery. Reasoning dedup viareasoningItemsis unchanged.doneevents from two fixtures whose remaining assertions still hold.Verification