Skip to content

Python: Prevent orphaned local approval responses - #7462

Open
eavanvalkenburg wants to merge 2 commits into
microsoft:mainfrom
eavanvalkenburg:fix/hosted-approval-serialization
Open

Python: Prevent orphaned local approval responses#7462
eavanvalkenburg wants to merge 2 commits into
microsoft:mainfrom
eavanvalkenburg:fix/hosted-approval-serialization

Conversation

@eavanvalkenburg

Copy link
Copy Markdown
Member

Motivation & Context

Issue #7125 correctly identified that service-side continuation dropped the current hosted approval response. PR #7407 preserved that response, but the unconditional serializer now emits local FunctionTool approvals as MCP approval responses. Because no matching MCP approval request exists for local tools, the provider rejects the request as an orphaned approval and consumes the pending approval.

Description & Review Guide

  • What are the major changes?
    • Reuse the core hosted-approval classification in the OpenAI Responses serializer.
    • Preserve hosted approval responses during service-side continuation while omitting stored hosted requests.
    • Keep local approval requests and responses in the framework's in-process flow instead of serializing them as MCP items.
    • Add regression coverage for hosted and local approval controls with storage enabled and disabled, and update the function-calling specification and OpenAI package guidance.
  • What is the impact of these changes?
    • Hosted approval resume continues to send the user's decision to the service. Local approval flows no longer generate invalid orphaned MCP approval responses.
  • What do you want reviewers to focus on?
    • Confirm the hosted-versus-local boundary is applied consistently without changing unrelated Responses API continuation behavior.

Related Issue

Fixes #7125

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 <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 0efaca91-a0a7-46f4-9b81-022385607fe4
Copilot AI review requested due to automatic review settings July 31, 2026 14:41
@agent-framework-automation agent-framework-automation Bot added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python labels Jul 31, 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

Note

Copilot was unable to run its full agentic suite in this review.

Updates OpenAI chat message preparation to distinguish hosted vs local function-approval controls so only hosted approvals are serialized to MCP items (and local approvals remain in-process).

Changes:

  • Gate serialization of function_approval_request / function_approval_response on whether the approval is “hosted”.
  • Add regression test ensuring local approval controls are dropped for both storage and stateless requests.
  • Update docs/specs to clarify hosted vs local approval behavior and adjust related tests to include hosted markers.

Reviewed changes

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

File Description
python/packages/openai/agent_framework_openai/_chat_client.py Filters approval request/response contents based on hosted-approval detection during message preparation.
python/packages/openai/tests/openai/test_openai_chat_client.py Updates existing tests to mark hosted approvals and adds a new test to ensure local approvals are omitted.
python/packages/openai/AGENTS.md Clarifies hosted vs local approval serialization rules for service-side storage continuation.
docs/specs/004-python-function-calling-loop.md Updates spec table entries to reflect hosted-only serialization and omission of local approvals.

Comment thread python/packages/openai/agent_framework_openai/_chat_client.py
Comment thread python/packages/openai/agent_framework_openai/_chat_client.py
Comment thread python/packages/openai/agent_framework_openai/_chat_client.py
Comment thread python/packages/openai/AGENTS.md Outdated
@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/openai/agent_framework_openai
   _chat_client.py138912391%314, 327, 681–687, 696–699, 705–709, 717, 761–766, 770–773, 775–777, 784–786, 789, 846, 854, 877, 1094, 1153, 1155, 1157, 1159, 1225, 1239, 1319, 1329, 1334, 1377, 1489–1490, 1505, 1784, 1891, 1896–1897, 1980, 1990, 2017, 2023, 2033, 2039, 2044, 2050, 2055–2056, 2136, 2180, 2183–2186, 2200, 2210–2211, 2223, 2265, 2330, 2347, 2350, 2377–2379, 2418, 2435, 2438, 2500, 2507, 2544–2545, 2580, 2618–2619, 2637–2638, 2810–2811, 2829, 2915–2923, 3101, 3116, 3166, 3176–3178, 3205–3207, 3217–3218, 3224, 3239, 3372–3373
TOTAL47345452990% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
9744 34 💤 0 ❌ 0 🔥 2m 35s ⏱️

@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.

Automated Code Review

Reviewers: 5 | Confidence: 39% | Result: All clear

Reviewed: Correctness, Security Reliability, Test Coverage, Failure Modes, Design Approach


Automated review by eavanvalkenburg's agents

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

Copilot-Session: 0efaca91-a0a7-46f4-9b81-022385607fe4

@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.

Automated Code Review

Reviewers: 4 | Confidence: 35% | Result: All clear

Reviewed: Security Reliability, Test Coverage, Failure Modes, Design Approach


Automated review by eavanvalkenburg's agents

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

Labels

documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: function_approval_response is dropped from the request under service-side storage, so an approval-paused run never resumes

2 participants