Skip to content

Python: preserve functional workflow state on response-only HITL resume - #8300

Open
CoralGarden52 wants to merge 1 commit into
microsoft:mainfrom
CoralGarden52:fix/functional-workflow-response-only-state
Open

Python: preserve functional workflow state on response-only HITL resume#8300
CoralGarden52 wants to merge 1 commit into
microsoft:mainfrom
CoralGarden52:fix/functional-workflow-response-only-state

Conversation

@CoralGarden52

Copy link
Copy Markdown
Contributor

Motivation & Context

Functional workflow state is documented as persisting across HITL interruptions, but response-only resumes currently restore only cached step results. When a cached step wrote user state before requesting input, the resumed workflow completes with missing state and can silently produce an incorrect result.

This is reproducible through the public FunctionalWorkflow.run API on the upstream commit used for this change:

First run:  IDLE_WITH_PENDING_REQUESTS
Before fix, response-only resume: ['MISSING:seeded:ok']

The same scenario resumed with a checkpoint_id already preserved ok:seeded:ok, confirming that state persistence is intended. The issue is tracked in #8299, and the original functional workflow review in #4238 identified the same unresolved response-only state restoration gap.

Description & Review Guide

  • What are the major changes?

    • Snapshot the active user state alongside the existing response-only step cache when a functional workflow is interrupted.
    • Restore that state when resuming with responses={...} without a checkpoint.
    • Clear the replayed state on clean completion, matching the existing replay-cache lifecycle.
    • Add a regression test that writes state in a cached @step, pauses for HITL input, verifies the step is not executed again, and verifies the state remains available after response-only resume.
  • What is the impact of these changes?

    • Response-only HITL resumes now preserve state-dependent workflow behavior while retaining cached-step replay.
    • The verified post-fix result is ['ok:seeded:ok'] with seed_calls == 1.
    • Checkpoint restore behavior and the public API remain unchanged.
    • The focused workflow tests, the full core unit suite (5039 passed, 131 skipped, 2 xfailed), formatting, linting, and changed-file Pyright checks pass.
  • What do you want reviewers to focus on?

    • Whether the state snapshot/restore points cover both WorkflowInterrupted and normal completion without allowing stale state to cross independent workflow runs.
    • Whether the regression test accurately represents a cached step that initializes state before a response-only HITL resume.

Related Issue

Fixes #8299

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) — a workflow keeps the label and title prefix in sync automatically.

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.

🟢 Approval recommended

The implementation consistently extends the existing replay lifecycle and directly covers the reported regression.

Pull request overview

Preserves functional workflow user state during response-only HITL resumes.

Changes:

  • Saves, restores, and clears replay state alongside step caches.
  • Adds regression coverage confirming cached steps are not rerun and state remains available.
File summaries
File Description
python/packages/core/agent_framework/_workflows/_functional.py Adds response-only state persistence lifecycle.
python/packages/core/tests/workflow/test_functional_workflow.py Tests state restoration through cached-step replay.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Balanced

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

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]: Functional workflow response-only HITL resume loses user state

2 participants