Repository navigation
Python: fix Foundry background local tool replay - #8670
Conversation
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Replay validation can accept malformed payloads or associate reused reasoning IDs with the wrong tool group.
Get a fresh assessment by requesting another Copilot review.
Review effort: Balanced
Findings: 1
Open (3)
What changed in this PR
Enables stateless replay of Foundry background responses containing provider-native reasoning items.
Changes:
- Adds a provider-specific reasoning replay hook.
- Preserves completed Foundry reasoning payloads in streaming and non-streaming paths.
- Adds replay validation and regression/integration tests.
| File | Description |
|---|---|
python/packages/openai/agent_framework_openai/_chat_client.py |
Generalizes stateless reasoning replay. |
python/packages/foundry/agent_framework_foundry/_chat_client.py |
Captures and restores Foundry reasoning payloads. |
python/packages/foundry/tests/foundry/test_foundry_chat_client.py |
Tests replay, streaming precedence, and background tool loops. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
MAF Automated Review — Iteration 1
Result: Findings reported
Scope: full PR (1 commit(s)): 87352e37c193
Model: gpt-5.6-sol-fast
Overview
The PR preserves an allowlisted completed Foundry reasoning payload and uses the streaming .done item, while generic OpenAI replay remains fail-closed and focused tests cover successful and rejected replay. However, deriving validation from a global set of replayable reasoning IDs weakens the documented group-atomic invariant: a payload from one logical tool group can make another group with the same ID pass validation and serialize incorrectly.
Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
1 verified finding remained after source verification (1 medium) across 1 file. Details are attached to the affected lines below.
Affected areas: python/packages/openai/agent_framework_openai/_chat_client.py



Motivation & Context
Microsoft Foundry background responses with local tools already complete through service-side continuation when
store=True. Withstore=False, a completed background response can instead return a provider-native reasoning item withoutencrypted_content. Agent Framework executed the local tool once, then rejected the follow-up before transport because stateless replay only recognized encrypted reasoning.Foundry accepts the original completed reasoning item as the replay representation. This change preserves and replays that item so background local-tool loops work in both storage modes without duplicating tool execution.
Description & Review Guide
.doneprecedence, plus a live Foundry integration test forstore=Trueandstore=False.store=Falsenow complete successfully and execute each local tool once..doneitem rather than the earlier.addedskeleton.Related Issue
Fixes #7538
No other open PR targets this issue.
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and the title prefix in sync automatically.