Skip to content

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

Closed

Description

Description

The Foundry chat client's reasoning replay attachment assumes a single-message response, which #9768 broke open: responses can now produce multiple assistant messages (one per provider output message, e.g. preamble + follow-up), and a trailing reasoning item is parsed into the last message.

_parse_response_from_openai in python/packages/foundry/agent_framework_foundry/_chat_client.py only calls _attach_foundry_reasoning_replay_item(chat_response.messages[0].contents, item):

  • if the reasoning content actually lives in a later message, the id lookup in messages[0] misses and the miss branch appends a duplicate empty text_reasoning content to the first message
  • the real reasoning content in the later message keeps no replay payload
  • stateless replay then groups two contents under the same provider reasoning id, and the visible transcript gains a spurious empty reasoning item attached to the wrong message

Repro

Non-streaming response with output = [message(message_0, "A"), message(message_1, "B"), reasoning(id="rs_1", response_id=..., summary=[], content=[])]:

messages[0] = [text "A", text_reasoning rs_1 (empty, replay payload)]   # duplicate appended here
messages[1] = [text "B", text_reasoning rs_1 (real, NO replay payload)] # owner missed

Verified on main: the replay-grouped contents for rs_1 contain the duplicate first, and the owning content has no __foundry_reasoning_replay_item__ metadata. The streaming path attaches per update and is not affected.

Expected

The attachment should search all messages for the reasoning content that owns the id (most recent first) and only fall back to appending on the last message — where trailing reasoning items are parsed in the first place.

Environment

Activity

  1. added
    pythonUsage: [Issues, PRs], Target: Python
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Nov 1, 2026
  2. changed the title [-]Foundry reasoning replay data attaches to the wrong message for multi-message responses[/-] [+]Python: Foundry reasoning replay data attaches to the wrong message for multi-message responses[/+] on Nov 1, 2026
  3. nikhilred2619 commented on Nov 1, 2026

    @nikhilred2619

    Hi Wilson_Jiang (@Wilson0511), thanks for reporting this.

    I went through the issue, and the reasoning replay mismatch across multiple assistant messages looks like an important problem to address.

    I'd be happy to work on updating the attachment logic so it finds the matching reasoning content across messages instead of assuming it belongs to the first one. I can also add regression tests for multi-message responses, the fallback behavior, and stateless replay.

    Is anyone already working on this? If not, would you be open to me preparing a PR?

    Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pythonUsage: [Issues, PRs], Target: PythontriageUsage: [Issues], Target: All issues that still need to be triaged

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions