Skip to content

Python: Hosted Responses lose CostControl budget failure metadata #8487

Open

Description

@banibrata-de

When a Foundry-hosted Agent Framework Responses agent receives a streaming model failure caused by a CostControl budget block, the raw model response includes x-ms-budget-cause: budget_exceeded and related budget headers. The OpenAI streaming SDK later raises a generic APIError from the SSE error event, and the hosting adapter currently emits a generic response.failed with error.code: server_error.

Expected behavior:

  • Preserve the allowlisted CostControl response headers across the streaming exception boundary.
  • Emit response.failed.error.code as budget_exceeded.
  • Include compact CostControl details in response metadata so streaming and non-streaming Responses clients can render the correct budget-block experience.

The outer Responses HTTP status should remain protocol-compatible; this issue concerns the terminal failure body and metadata.

Activity

  1. changed the title [-]Hosted Responses lose CostControl budget failure metadata[/-] [+]Python: Hosted Responses lose CostControl budget failure metadata[/+] on Sep 18, 2026
  2. added
    reproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow
    on Sep 18, 2026
  3. github-actions commented on Sep 18, 2026

    @github-actions
    Contributor

    🤖 Automated triage reproduction notes (agent-authored — trust but verify)

    Agent analysis

    Repro: python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py::ResponsesHostServer._emit_failure emits a generic failure when an exception carries response_headers containing x-ms-budget-cause: budget_exceeded. Minimal repro: raise such an exception from an agent ResponseStream, then POST to the Foundry Responses endpoint with either stream=False or stream=True; both return HTTP 200 with error.code: server_error and no CostControl metadata.

    • Failing test: python/packages/foundry_hosting/tests/test_responses.py
    • Files examined: python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py, python/packages/foundry_hosting/tests/test_responses.py, python/packages/openai/agent_framework_openai/_chat_client.py, python/packages/openai/agent_framework_openai/_exceptions.py, python/packages/foundry_hosting/pyproject.toml
    • Tests run: TestResponseFailedSurfacing::test_budget_failure_emits_typed_error_and_cost_control_metadata, TestResponseFailedSurfacing::test_non_streaming_run_failure_emits_response_failed, TestResponseFailedSurfacing::test_streaming_run_failure_emits_response_failed
    • Current version: 1.0.0b260910
  4. added
    foundryUsage: [Issues, PRs], Target: all Foundry integrations
    hostingUsage: [Issues, PRs], Target: all hosting related solutions
    and removed
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Sep 18, 2026
  5. eavanvalkenburg commented on Oct 27, 2026

    @eavanvalkenburg
    Member

    This looks worth considering in the MAF hosting integration. Darren Cohen (@dargilco), I have added you as an owner; could you have a look and advise on the appropriate scope?

    We should keep this narrowly scoped to a safe, allowlisted budget-exhaustion classification and bounded metadata, preserving the existing sanitized public failures and Responses transport contract rather than exposing arbitrary exception bodies or headers.

    For context, the earlier #8488 is closed unmerged, with outstanding feedback about retaining headers when Azure tracing wraps streaming responses, including the retrieve path. Azure/azure-sdk-for-python#49073 merged generic failure-metadata support, but selecting safe public fields and reliably carrying those headers through the adapter still need assessment. Please review those boundaries before we settle the implementation direction; this is consideration, not a commitment to implementation or timing.

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

Metadata

Metadata

Labels

foundryUsage: [Issues, PRs], Target: all Foundry integrationshostingUsage: [Issues, PRs], Target: all hosting related solutionspythonUsage: [Issues, PRs], Target: PythonreproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions