Skip to content

Python: fix Foundry background local tool replay - #8670

Merged
westey (westey-m) merged 3 commits into
microsoft:mainfrom
eavanvalkenburg:check-issue-7538
Sep 24, 2026
Merged

westey (westey-m) merged 3 commits into
microsoft:mainfrom
eavanvalkenburg:check-issue-7538

Conversation

@eavanvalkenburg

Copy link
Copy Markdown
Member

Motivation & Context

Microsoft Foundry background responses with local tools already complete through service-side continuation when store=True. With store=False, a completed background response can instead return a provider-native reasoning item without encrypted_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

  • What are the major changes?
    • Derive stateless replay validation from the reasoning items the provider serializer can actually reconstruct.
    • Add a private provider hook for non-encrypted reasoning replay.
    • Preserve an allowlisted completed Foundry reasoning payload for non-streaming and streaming responses.
    • Add unit coverage for successful replay, incomplete-payload rejection, and streaming .done precedence, plus a live Foundry integration test for store=True and store=False.
  • What is the impact of these changes?
    • Foundry background local-tool loops with store=False now complete successfully and execute each local tool once.
    • Existing service-side continuation and generic OpenAI encrypted-reasoning replay remain unchanged.
  • What do you want reviewers to focus on?
    • The replay payload validation and the requirement that streaming replay uses the completed .done item rather than the earlier .added skeleton.

Related Issue

Fixes #7538

No other open PR targets this issue.

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 the title prefix in sync automatically.

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.

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 High severity · 1 Medium severity · 1 Low severity

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.

@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)): 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

@westey-m
westey (westey-m) added this pull request to the merge queue Sep 24, 2026
Merged via the queue into microsoft:main with commit 6233788 Sep 24, 2026
48 of 49 checks passed

This branch was previously deployed

1 inactive deployment
github-app-auth — 538606d8 Deployed Sep 24, 2026 by eavanvalkenburg via add_label #23703
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]: Background Responses tool loop fails when chaining tool output to a completed background response

3 participants