Repository navigation
Python: Attach Foundry reasoning replay data to the message that owns it - #9931
Merged
Eduard van Valkenburg (eavanvalkenburg) merged 2 commits intoNov 2, 2026
Conversation
microsoft#9768 made multi-message responses possible (one Message per provider output message, trailing reasoning parsed into the last message), but the Foundry replay attachment only searched messages[0]: a reasoning item owned by a later message appended a duplicate empty reasoning content to the first message while the real reasoning content kept no replay payload, so stateless replay grouped two contents for the same provider id and the visible transcript gained a spurious empty reasoning item. Search every message (most recent first) and append to the last message when nothing matches. The streaming path already attaches per update and is unchanged. 🤖 Generated with ZCode Co-Authored-By: ZCode <noreply@zcode.dev>
Wilson_Jiang (Wilson0511)
temporarily deployed
to
github-app-auth
November 1, 2026 09:41 — with
GitHub Actions
Inactive
Wilson_Jiang (Wilson0511)
requested review from
Darren Cohen (dargilco),
Jose Alvarez (jpalvarezl) and
sophia-ramsey
as code owners
November 1, 2026 09:41
Wilson_Jiang (Wilson0511)
temporarily deployed
to
github-app-auth
November 1, 2026 09:41 — with
GitHub Actions
Inactive
Wilson_Jiang (Wilson0511)
temporarily deployed
to
github-app-auth
November 1, 2026 09:41 — with
GitHub Actions
Inactive
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The regression test does not assert that rs_trailing belongs to response.messages[1], allowing it to pass even if the content and its replay payload move to the wrong message.
1 open issue
What changed in this PR
Fixes #9930 by attaching Foundry reasoning replay metadata to its owning message in multi-message responses, preserving the message boundaries introduced by #9768.
Changes:
- Search messages newest-first for matching reasoning content, falling back to the last message only when no match exists.
- Add regression coverage for duplicate reasoning content and missing replay metadata. Streaming behavior remains unchanged.
| File | Description |
|---|---|
python/packages/foundry/tests/foundry/test_foundry_chat_client.py |
Adds a multi-message reasoning replay regression test. |
python/packages/foundry/agent_framework_foundry/_chat_client.py |
Attaches non-streaming replay metadata across message boundaries. |
Review effort: Balanced
…sion test Review follow-up on microsoft#9931: also assert that the rs_trailing content lives in message_1, since the flattened checks would pass even if the reasoning (with its replay payload) were attached to message_0. 🤖 Generated with ZCode Co-Authored-By: ZCode <noreply@zcode.dev>
Wilson_Jiang (Wilson0511)
temporarily deployed
to
github-app-auth
November 1, 2026 10:01 — with
GitHub Actions
Inactive
Eduard van Valkenburg (eavanvalkenburg)
approved these changes
Nov 2, 2026
This branch was previously 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.

Fixes #9930
Description
#9768 made multi-message responses possible (one Message per provider output message, trailing reasoning parsed into the last message), but the Foundry replay attachment only searched
messages[0]: a reasoning item owned by a later message appended a duplicate empty reasoning content to the first message while the real reasoning content kept no replay payload. Stateless replay then grouped two contents for the same provider id and the visible transcript gained a spurious empty reasoning item.New
_attach_foundry_reasoning_replay_item_to_messagessearches every message (most recent first) and only appends to the last message when nothing matches — where trailing reasoning is parsed. The streaming path already attaches per update and is unchanged.RegressionCheck
test_multi_message_response_attaches_reasoning_replay_to_owning_message: fails onmain(twors_trailingcontents, the first-message one empty, the owning one without replay data) and passes here (exactly one reasoning content, in the owning message, with replay payload; message texts["A", "B"]preserved).python/packages/foundrysuite: 466 passed, 29 skipped, 0 failed — same asmain(the two prior collection errors were a missing localagent-framework-ag-uiinstall, unrelated).🤖 Generated with ZCode
Co-Authored-By: ZCode noreply@zcode.dev