Skip to content

Python: Attach Foundry reasoning replay data to the message that owns it - #9931

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 2 commits into
microsoft:mainfrom
Wilson0511:fix/foundry-reasoning-attach-multi-message
Nov 2, 2026
Merged

Eduard van Valkenburg (eavanvalkenburg) merged 2 commits into
microsoft:mainfrom
Wilson0511:fix/foundry-reasoning-attach-multi-message

Conversation

@Wilson0511

@Wilson0511 Wilson_Jiang (Wilson0511) commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

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_messages searches 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 on main (two rs_trailing contents, 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).
  • Full python/packages/foundry suite: 466 passed, 29 skipped, 0 failed — same as main (the two prior collection errors were a missing local agent-framework-ag-ui install, unrelated).

🤖 Generated with ZCode
Co-Authored-By: ZCode noreply@zcode.dev

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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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>
Merged via the queue into microsoft:main with commit 96646c5 Nov 2, 2026
50 checks passed

This branch was previously deployed

1 inactive deployment
github-app-auth — 2f67e387 Deployed Nov 1, 2026 by Wilson0511 via add_label #26785
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: Foundry reasoning replay data attaches to the wrong message for multi-message responses

3 participants