Skip to content

Python: Fix Foundry reasoning MCP compaction#6907

Open
godququ5-code wants to merge 1 commit into
microsoft:mainfrom
godququ5-code:godququ5/issue-6883
Open

Python: Fix Foundry reasoning MCP compaction#6907
godququ5-code wants to merge 1 commit into
microsoft:mainfrom
godququ5-code:godququ5/issue-6883

Conversation

@godququ5-code

@godququ5-code godququ5-code commented Jul 3, 2026

Copy link
Copy Markdown

Summary

  • Preserve Foundry reasoning output as text_reasoning with the provider reasoning id when reconstructing response history.
  • Treat mcp_server_tool_call as a tool-call assistant item during compaction so reasoning + MCP call pairs stay atomic.
  • Add focused regressions for both Foundry reasoning reconstruction paths and sliding-window MCP compaction.

Fixes #6883

Root cause

Foundry response reconstruction converted reasoning summaries into ordinary text content, dropping the reasoning id. Core compaction also only recognized function_call assistant messages as tool-call items, so an MCP call following a reasoning item could be grouped separately and survive after its reasoning prefix was excluded.

Test plan

  • uv run pytest packages/core/tests/core/test_compaction.py packages/foundry_hosting/tests/test_responses.py -q
  • uv run prek run --files packages/core/agent_framework/_compaction.py packages/core/tests/core/test_compaction.py packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py packages/foundry_hosting/tests/test_responses.py

Note: the pytest command exits 0, but the local environment emits unrelated OpenTelemetry exporter shutdown noise against 127.0.0.1:7897 after the tests finish.

Copilot AI review requested due to automatic review settings July 3, 2026 19:40
@giles17 giles17 added the python Usage: [Issues, PRs], Target: Python label Jul 3, 2026
@github-actions github-actions Bot changed the title Fix Foundry reasoning MCP compaction Python: Fix Foundry reasoning MCP compaction Jul 3, 2026

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.

Pull request overview

Fixes Python response-history reconstruction and core compaction behavior so Foundry reasoning items and subsequent MCP tool calls remain correctly paired and valid for downstream APIs (avoiding “orphaned mcp_call” 400s in multi-turn reasoning flows).

Changes:

  • Preserve Foundry reasoning summaries as text_reasoning content (instead of plain text) while retaining the provider reasoning id.
  • Treat mcp_server_tool_call assistant messages as tool-call items during compaction grouping so reasoning + MCP call pairs stay atomic.
  • Add targeted regression tests covering both Foundry reasoning reconstruction paths and sliding-window MCP compaction grouping.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py Reconstruct reasoning summaries as text_reasoning while preserving reasoning IDs.
python/packages/foundry_hosting/tests/test_responses.py Adds assertions ensuring reconstructed reasoning content type and ID are preserved.
python/packages/core/agent_framework/_compaction.py Expands tool-call detection to include MCP server tool calls for proper grouping/compaction.
python/packages/core/tests/core/test_compaction.py Adds regression ensuring sliding-window compaction keeps reasoning + MCP calls in the same group.

@godququ5-code

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@godququ5-code godququ5-code marked this pull request as ready for review July 3, 2026 19:54
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: [Bug]: Orphaned mcp_call items cause HTTP 400 in multi-turn reasoning model flows

3 participants