Repository navigation
fix(threads): preserve iterator-backed message content during replay - #2086
Open
bowenzhu21 wants to merge 2 commits into
Open
bowenzhu21 wants to merge 2 commits into
bowenzhu21 wants to merge 2 commits into
Conversation
Retain one-shot content blocks when messages are staged, so a recovered thread or a fork can send the original blocks again.
bowenzhu21
marked this pull request as ready for review
November 26, 2026 19:49
This branch has not been deployed
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.
Summary
On SDK 2.14.0, a beta message thread sends both text blocks from
iter(blocks)on its first request. If the server loses the thread or rejects threading, the SDK replays the message with"content": []. With this change, the replay sends the same two blocks as the original request.The thread consumes a one-shot content iterator when it stages the message and saves the blocks in a shallow copy of the message dictionary. This also lets a fork replay a deferred message. Ordinary lists keep their existing behavior, including edits after staging.
Related PR #2072 addresses iterators passed as tool definitions. This change covers message content. The equivalent inputs in TypeScript and Go use arrays and slices.
Tests
The regression tests inspect the outgoing HTTP bodies for sync lost-thread recovery, async unthreaded fallback, and a fork created while a streamed turn has a deferred message. On upstream
f1edcd7d, all three iterator cases failed and both list controls passed. All five pass with this change../scripts/test tests/lib/threads -k 'original_message_blocks or deferred_message_blocks' -n0On
8429e950the full Linux suite passed on Python 3.10 with Pydantic v2 (15,165 passed, 41 skipped). The thread tests also passed on Python 3.14 and with Pydantic v1. Formatting, lint, type, package, and compatibility checks passed.Release note
Fix a bug that could drop iterator-backed message content when replaying or forking a message thread.