Skip to content

Python: align Foundry hosting response conversion - #7965

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 4 commits into
microsoft:mainfrom
eavanvalkenburg:eavanvalkenburg-foundry-parser-alignment
Sep 1, 2026
Merged

Python: align Foundry hosting response conversion#7965
Eduard van Valkenburg (eavanvalkenburg) merged 4 commits into
microsoft:mainfrom
eavanvalkenburg:eavanvalkenburg-foundry-parser-alignment

Conversation

@eavanvalkenburg

Copy link
Copy Markdown
Member

Motivation & Context

Foundry hosting converted some structured arguments and results with Python string representations, which can produce invalid JSON on the wire and erased falsey function results. MCP result serialization also differed depending on whether a matching call was still active, while supported shell execution limits were dropped during response conversion. These inconsistencies make replayed items and hosted response events less faithful to Agent Framework Content values.

Description & Review Guide

  • What are the major changes? Use one JSON-safe argument/result serializer, preserve falsey results, align correlated and uncorrelated MCP output serialization, retain supported shell timeout/output limits, remove an unreachable duplicate result branch, and delegate shared output-item parsing to the input-item converter.
  • What is the impact of these changes? Structured values remain valid JSON, 0 and False survive conversion, MCP outputs are consistent, shell settings round-trip through Agent Server 2.1 models, and the duplicated parser logic is reduced without changing public APIs or dependencies.
  • What do you want reviewers to focus on? Please verify the serializer semantics and the behavior-neutral delegation between the generated input and output item shapes.

Related Issue

N/A — focused follow-up cleanup.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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

Aligns Foundry hosting response conversion with JSON-safe serialization and preserves shell execution metadata.

Changes:

  • Unifies argument/result serialization and preserves falsey values.
  • Consolidates input/output item conversion logic.
  • Adds regression tests for serialization, MCP output, and shell limits.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
_responses.py Updates response serialization and item conversion.
test_responses.py Adds conversion and round-trip coverage.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@github-actions github-actions Bot 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.

MAF Automated Review — Iteration 1

Result: Findings reported
Scope: full PR (1 commit(s)): e5c2c5fe9824
Model: gpt-5.6-sol

Overview

The PR successfully centralizes JSON-safe conversion, preserves falsey function results and shell limits, and adds focused parity tests for correlated and uncorrelated MCP output. The shared conversion path also preserves approval storage and the specialized OutputItem cases. Two MCP output boundaries remain: arbitrary values permitted by the public Any contract can now fail serialization, and uncorrelated mappings with a text field can lose accompanying structured data.

Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
2 verified findings remained after source verification (2 medium) across 1 file. Details are attached to the affected lines below.

Affected areas: python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py

Comment thread python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py Outdated
Keep dataclass and to_dict conversion while encoding unsupported result values via their string representation. Only unwrap recognized MCP text content so structured mappings retain every field.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Resolve Foundry response conversion conflicts while retaining upstream call-id validation and cache-write usage support.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/foundry_hosting/agent_framework_foundry_hosting
   _responses.py77810087%116–118, 234, 299–300, 314, 317–318, 385, 394, 471, 503, 518–521, 585, 635, 697, 709, 725–726, 731–734, 738–740, 745, 753, 756, 767, 812, 822, 833–835, 849–851, 854, 888–891, 896, 899, 919–920, 1017, 1088–1091, 1095–1097, 1102–1106, 1111, 1118, 1133–1139, 1149, 1155, 1159, 1183, 1192–1193, 1197, 1695–1696, 1700, 1745, 1747, 1749, 1751, 1755, 1763, 1766–1770, 1772, 1841, 1843, 1854–1855, 1862
TOTAL48348448490% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
9870 36 💤 0 ❌ 0 🔥 2m 47s ⏱️

@github-actions github-actions Bot 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.

MAF Automated Review — Iteration 2

Result: No findings
Scope: 22 net-new commit(s): dc7714295fff, 52a376453994, 34d1ac70b2fc, 178f365dc69e, 44c8cf6a2012, 6ed829cf713e, f7e78c689bb9, 341d0ec35bbc, 947d933f2385, de02975ee606, 6d532cf77e26, edfe115ea06b, 1aca2a95e3b9, 4c0bff8b77d5, a617392cc79b, 5996105a1bf2, d2a934d53530, 018dea570b84, 11d628d60ff2, 6a0773ba2180, 1a40758bfa86, a49a59772cf6
Model: gpt-5.6-sol

Overview

The change centralizes JSON-safe conversion, preserves falsey values and structured MCP output, retains shell limits, and delegates shared output parsing to the input converter. Focused tests cover unsupported leaf values, structured mappings, replay metadata, MCP correlation, and streaming lifecycle behavior. No new Critical, High, or Medium issue remains after reconciling the implementation with those guards and the supplied prior feedback.

Reviewed the supplied incremental change set across correctness, security/reliability, architecture, and failure behavior.
No publishable findings remained after source verification for this scope.

Fall back to a JSON-encoded string when structured result encoding raises TypeError or ValueError, while preserving arbitrary user-code exceptions.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: aab30b40-e3c5-41b4-84c1-1b27d7ddf351
Merged via the queue into microsoft:main with commit 362972a Sep 1, 2026
37 checks passed
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.

3 participants