Skip to content

Python: Foundry Hosted Agent Resiliency Support - #7670

Draft
Tao Chen (TaoChenOSU) wants to merge 19 commits into
mainfrom
taochen/lra-refresh
Draft

Python: Foundry Hosted Agent Resiliency Support#7670
Tao Chen (TaoChenOSU) wants to merge 19 commits into
mainfrom
taochen/lra-refresh

Conversation

@TaoChenOSU

@TaoChenOSU Tao Chen (TaoChenOSU) commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Motivation & Context

Add support for resilient tasks in Foundry Hosted Agent.

Description & Review Guide

  • What are the major changes?
    • Add support for resilient_background=True in ResponsesHostServer
    • A sample showing how a workflow can be recovered after a crash (force crash locally).
  • What is the impact of these changes?
    • A new feature, no breaking changes
  • What do you want reviewers to focus on?
    • The handling of workflow checkpoints

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.

@TaoChenOSU Tao Chen (TaoChenOSU) self-assigned this Aug 14, 2026
@TaoChenOSU Tao Chen (TaoChenOSU) added the python Usage: [Issues, PRs], Target: Python label Aug 14, 2026
Copilot AI balanced review requested due to automatic review settings August 14, 2026 18:57
@TaoChenOSU Tao Chen (TaoChenOSU) added foundry Usage: [Issues, PRs], Target: all Foundry integrations hosting Usage: [Issues, PRs], Target: all hosting related solutions labels Aug 14, 2026
@github-actions github-actions Bot changed the title Foundry Hosted Agent Resiliency Support Python: Foundry Hosted Agent Resiliency Support Aug 14, 2026
@agent-framework-automation agent-framework-automation Bot added the documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs label Aug 14, 2026
@github-actions

github-actions Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/foundry_hosting/agent_framework_foundry_hosting
   _responses.py73610985%111–113, 174–175, 189, 192–193, 252, 261, 331, 375–376, 440, 490, 550, 562, 578–579, 584–587, 595–596, 607, 639–640, 650, 694–697, 702, 705, 725–726, 1080, 1092, 1544–1545, 1549, 1594, 1596, 1598, 1600, 1604, 1612, 1615–1619, 1621, 1631, 1635, 1648, 1682–1687, 1691–1692, 1700–1706, 1736–1737, 1739–1740, 1742, 1747, 1755–1756, 1758, 1763–1767, 1769, 1776–1777, 1779–1780, 1786, 1788–1792, 1802, 1808, 1832, 1838, 1844, 1846, 1848–1851, 1859, 1861
   _state_store.py1240100% 
TOTAL46801437590% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
9449 36 💤 0 ❌ 0 🔥 2m 26s ⏱️

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

Adds resilient background recovery for Python Foundry-hosted workflow agents and a countdown sample demonstrating the feature.

Changes:

  • Adds workflow checkpoint and response-stream recovery integration.
  • Refactors response handling and cancellation plumbing.
  • Adds a resilient hosted-agent sample and deployment assets.

Reviewed changes

Copilot reviewed 10 out of 12 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
_responses.py Implements resilient workflow recovery and shared response handling.
test_responses.py Updates tests for the refactored handler signature.
foundry_hosting/README.md Minor formatting correction.
Sample main.py Defines the resilient countdown workflow.
Sample README.md Documents running and invoking the sample.
Sample requirements.txt Declares framework dependencies.
Sample Dockerfile Packages the sample container.
Sample agent.yaml Configures the hosted agent.
Sample agent.manifest.yaml Defines deployment metadata and resources.
Sample .env.example Lists required environment variables.
Sample .dockerignore Excludes local Python artifacts and secrets.
Suppressed comments (1)

python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py:643

  • The previous implementation rejected an unknown previous_response_id; this refactor silently starts a fresh workflow when no checkpoint is found. That breaks response chaining by returning an unrelated successful response instead of reporting the missing predecessor. Restore the missing-checkpoint validation.
                latest_checkpoint = await restore_checkpoint_storage.get_latest(workflow_name=self._agent.workflow.name)
                if latest_checkpoint is not None:
                    latest_checkpoint_id = latest_checkpoint.checkpoint_id

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py Outdated
Comment on lines +428 to +432
inner = self._handle_inner_workflow(
request, context, response_event_stream, tracker, cancellation_signal
)
else:
inner = self._handle_inner_agent(request, context, response_event_stream, tracker, cancellation_signal)
Comment thread python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py Outdated
Comment thread python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py Outdated
Comment thread python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py Outdated

@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 (18 commit(s)): ff8450b9fe0f, 4cf73d533ca7, 14cf002f7a00, 3df40fd8b17f, 10ab3c334565, 8838c1ede111, 649443c48221, 19303b75a6f4, 95f0ac3181f5, 8d038e37f6c9, 828e5df4263c, 172a5289eef1, 6db0df3f6fc6, 7ac2a9bcf86b, df0d18152f5a, 8b5da3a5e724, b0ac69de72e0, d9e6d5a49eb8
Model: gpt-5.6-sol

Overview

The review found 6 verified inline finding(s).

Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
6 verified findings remained after source verification (3 high, 3 medium) across 3 files. Details are attached to the affected lines below.

Affected areas: python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py, python/samples/04-hosting/foundry-hosted-agents/responses/resilient_long_running_workflow/main.py, python/samples/04-hosting/foundry-hosted-agents/responses/resilient_long_running_workflow/requirements.txt

Comment thread python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py Outdated
Comment thread python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py Outdated
# that fulfill them via :meth:`WorkflowAgent._process_pending_requests`.
if latest_checkpoint is not None:
async for _ in self._agent.run(
if latest_checkpoint is not None:

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.

When a caller supplies previous_response_id but that scope has no checkpoint, this now falls through and starts a fresh workflow with the continuation input. The previous behavior failed explicitly; silently resetting state can repeat workflow side effects or interpret a continuation as a new run. Please retain the missing-checkpoint error for response chaining while still allowing genuinely new workflow requests.


# Resiliency check
self._resilient_background = bool(options and options.resilient_background)
if self._resilient_background and not self._is_workflow_agent:

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.

The public contract says resilient background mode is supported only for workflows, but this warning leaves the invalid configuration active. On recovery, the non-workflow path restarts the original request, which can duplicate tool calls or other external side effects. Please reject this combination during server construction rather than executing an unsupported recovery mode.

"""Ask the model for a target and forward valid positive integers."""
response = await self._agent.run(messages, options={"response_format": CounterTarget})
extraction = response.value
if not isinstance(extraction, CounterTarget) or extraction.target is None or extraction.target <= 0:

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.

This accepts an unbounded attacker-controlled counter, while each iteration sleeps and self-enqueues on the server's singleton workflow instance. A very large value keeps that instance active, causes every concurrent request to fail the core single-run guard, and resilient recovery carries the monopolizing run across restarts. Please enforce a bounded execution budget or maximum counter before starting the workflow.

@TaoChenOSU

Copy link
Copy Markdown
Contributor Author

An issue discovered while working on this feature: #7677

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 foundry Usage: [Issues, PRs], Target: all Foundry integrations hosting Usage: [Issues, PRs], Target: all hosting related solutions python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants