Skip to content

Python: [BREAKING] Harden Foundry Hosting options - #10264

Closed
Eduard van Valkenburg (eavanvalkenburg) wants to merge 80 commits into
python-foundry-hosting-rcfrom
foundry-options-and-configuration
Closed

Eduard van Valkenburg (eavanvalkenburg) wants to merge 80 commits into
python-foundry-hosting-rcfrom
foundry-options-and-configuration

Conversation

@eavanvalkenburg

Copy link
Copy Markdown
Member

Motivation & Context

Foundry Hosting needs explicit option and background boundaries for the RC. This is the configuration and Invocations portion of the broader work in #10260.

Do not merge this PR alone. It breaks 17 Responses and native Responses tests until E's matching Responses integration lands with it. E's foundry-responses-integration branch includes this work and the required follow-up.

Description & Review Guide

  • What are the major changes? Omit caller generation options unless the developer opts in through prepare_options; validate protected host/run fields and provider-background settings; tighten Invocations configuration and workflow ownership checks; remove the legacy Invocations wire format and the shared reject_removed_host_settings compatibility helper.
  • What is the impact of these changes? Agent and client defaults remain intact. Invocations agent requests and the shared Responses option helper use opt-in forwarding for streaming and non-streaming calls. Native Invocations workflows continue to use explicitly parsed workflow kwargs. Invocations returns JSON or framed SSE rather than the removed legacy format. Responses factories run before their options hook; Invocations parses and prepares options before resolving the factory. E's integration supplies the Responses call-site, test, and documentation follow-up; its df055c710 also reverts a separate Responses-only copy of the removed-settings helper.
  • What do you want reviewers to focus on? The hook and protected-field boundary, provider-background validation, and the differences between agent and native-workflow execution. The settings and background direction follows the maintainer decisions in Python: [Team][Investigation] Explain ResponsesServerOptions and default_model #10012 and Python: [Team][Decision] Retain restrict or remove provider background support #10022.

For example, with an already configured agent:

from agent_framework_foundry_hosting import InvocationsHostServer

# Before: caller generation options were forwarded by default.
old_host = InvocationsHostServer(agent=agent)

# After: select the caller options to forward.
def select_options(request, options):
    return {name: options[name] for name in ("temperature",) if name in options}

host = InvocationsHostServer(agent=agent, prepare_options=select_options)

Related Issue

Relates to #10012, #10017, #10022, and #10023. This is a scoped contribution to #10260, which targets main; the issues remain open for the combined work.

AI Assistance

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

AI assistance details: Implementation, tests, and PR description.

Contribution Checklist

  • The code builds clean without any errors or warnings
    • Package build not run.
    • Passed: cd python && uv run --no-sync poe syntax -P foundry_hosting -C
    • Passed: cd python && uv run --no-sync poe pyright -P foundry_hosting
    • Passed: uvx --from ruff==0.17.3 ruff format --check python/packages/foundry_hosting
  • All unit tests pass, and I have added new tests where possible
    • Passed (441 tests): cd python && uv run pytest packages/foundry_hosting/tests/foundry_hosting/test_invocations_workflow.py packages/foundry_hosting/tests/foundry_hosting/test_host_options.py packages/foundry_hosting/tests/test_invocations.py packages/foundry_hosting/tests/test_foundry_hosting_imports.py packages/foundry_hosting/tests/test_request.py
    • Failed (17 Responses/native Responses tests pending E's integration): cd python/packages/foundry_hosting && uv run --no-sync pytest tests -m 'not integration' --no-cov --tb=short -q
    • E reported 1474 passed at df055c7100eccb0b42c89b56c179315c1b8fff5f: cd python && OTEL_SDK_DISABLED=true uv run --no-sync pytest -o addopts='--import-mode=importlib' -m 'not integration' packages/foundry_hosting/tests -q -p no:cacheprovider -n 8
  • The PR follows the Contribution Guidelines
  • This PR links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • 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.

…read-only approval translation

- Toolbox call_tool converts MCP -32006 consent into structured oauth_consent_request
  plus paired function_result, blocks later protected Toolbox calls in the host scope,
  sanitizes disallowed consent links.
- Approval conversion uses private read-only _ApprovalLookup; tracker uses staging
  _ApprovalRecorder awaited before yield; missing generated id raises RuntimeError.
Reverts 716f830. Removing the guard was outside the consent/translation scope;
steering behavior stays owned by the constructor/options owners.
Delete FunctionApprovalStore, FoundryFunctionApprovalStore and
FunctionApprovalStoreProvider from _state_store.py; session-backed
approval authority replaces them. Drop the matching legacy tests while
keeping session/checkpoint scope coverage.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@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 (9 commit(s)): e76e87e6de2a, 8a713288bfd6, 5a2bf847c6f0, dd9c10e7080d, 3cc4905f7f0a, 4c50dcb8f867, 3d0afc855f13, 15adafd2b0e1, bde8bbe95977
Model: gpt-5.6-sol

Overview

The change establishes explicit option-selection, protected-field validation, bounded workflow output, and request-owned workflow resource checks, with broad streaming and non-streaming coverage. The remaining gap is in the new foreground background-option guard: core appends context-provider chat middleware after that guard, so such middleware can still enable provider background and bypass the intended hosting boundary.

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/foundry_hosting/agent_framework_foundry_hosting/_shared.py

…responses-integration

# Conflicts:
#	python/packages/foundry_hosting/agent_framework_foundry_hosting/_invocations_shared.py
#	python/packages/foundry_hosting/agent_framework_foundry_hosting/_shared.py
#	python/packages/foundry_hosting/tests/foundry_hosting/test_background_middleware.py
Separate Invocations/Responses agent and workflow hosts. Agent hosts
forward only caller messages by default; agent default_options apply and
prepare_options is the explicit opt-in. Workflow hosts require a parser;
workflow options come only from the parsed turn.

This branch was successfully deployed

1 active deployment
github-app-auth — cb8d8a7f Deployed Nov 11, 2026 by eavanvalkenburg via add_label #27601
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change Usage: [PRs], Target: all PRs that introduce changes that are not backward compatible 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.

1 participant