Skip to content

Python: fix(foundry-hosting): root hosted checkpoints under durable home dire…#7220

Open
PratikWayase wants to merge 1 commit into
microsoft:mainfrom
PratikWayase:fix/hosted-workflowagent-checkpoint-restore
Open

Python: fix(foundry-hosting): root hosted checkpoints under durable home dire…#7220
PratikWayase wants to merge 1 commit into
microsoft:mainfrom
PratikWayase:fix/hosted-workflowagent-checkpoint-restore

Conversation

@PratikWayase

Copy link
Copy Markdown
Contributor

Motivation & Context

Previously, ResponsesHostServer.__init__ rooted the hosted checkpoint store at the absolute path /.checkpoints (the filesystem root). When a WorkflowAgent session compute was stopped and reached idle, a continuation request would recreate the compute, but the workflow checkpoint was not restored. Because the checkpoint was written to the ephemeral root path, it was lost, causing the workflow to restart from its initial state instead of resuming from the pending request_info approval step.

Description & Review Guide

What are the major changes?

  1. Added _resolve_checkpoint_root(is_hosted) static method: When hosted, this method roots the store at {$HOME}/.checkpoints (reading the HOME environment variable, default /home/session) instead of /.checkpoints.
  2. Added defensive guard: The method validates that HOME is not unset, blank, or the filesystem root (e.g., /). If it is, it falls back to /home/session/.checkpoints to guarantee the store never lands under the read-only root, reintroducing the bug.
  3. Updated __init__: The checkpoint path assignment now calls _resolve_checkpoint_root(self.config.is_hosted) instead of using the raw CHECKPOINT_STORAGE_PATH constant.
  4. Added 6 unit tests: covering local mode, hosted mode with valid HOME, missing HOME, and unusable HOME values (/, empty, whitespace).

What is the impact of these changes?

  • Hosted WorkflowAgent checkpoints now persist to the platform's durable $HOME volume, surviving across requests and compute recreation (idle → active).
  • Non-hosted/local usage is unchanged (continues to use {cwd}/.checkpoints).

What do you want reviewers to focus on?

  • The _resolve_checkpoint_root logic, specifically the HOME=/ guard, which prevents writing to /.checkpoints even if the environment variable is misconfigured.
  • Confirmation that the critical self._is_workflow_agent = True assignment was correctly preserved during the refactor.

Related Issue

Fixes #7137

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.

Copilot AI review requested due to automatic review settings July 20, 2026 17:38
@giles17 giles17 added the python Usage: [Issues, PRs], Target: Python label Jul 20, 2026
@github-actions github-actions Bot changed the title fix(foundry-hosting): root hosted checkpoints under durable home dire… Python: fix(foundry-hosting): root hosted checkpoints under durable home dire… Jul 20, 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

This PR fixes hosted WorkflowAgent checkpoint persistence in the Python Foundry hosting implementation by ensuring hosted checkpoints are stored under a durable home directory rather than the ephemeral filesystem root, so workflows can resume correctly after session compute recreation.

Changes:

  • Added ResponsesHostServer._resolve_checkpoint_root(is_hosted) to select {cwd}/.checkpoints for local mode and $HOME/.checkpoints (with a safe fallback) for hosted mode.
  • Updated ResponsesHostServer.__init__ to use the new resolver for _checkpoint_storage_path while preserving workflow-agent initialization behavior.
  • Added unit tests validating local vs hosted checkpoint path resolution, including missing/unusable HOME cases.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py Introduces checkpoint root resolution logic and updates server initialization to use it in hosted mode.
python/packages/foundry_hosting/tests/test_responses.py Adds tests covering hosted/local checkpoint storage path behavior and edge cases around HOME.

Comment on lines +404 to +413
home = os.environ.get("HOME", "").strip()
if home and home != "/":
try:
resolved = Path(home).resolve()
if str(resolved) != str(resolved.root):
return str(resolved / ".checkpoints")
except (OSError, ValueError):
pass

return "/home/session/.checkpoints"
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]: Hosted WorkflowAgent checkpoint is not restored after session compute recreation

3 participants