Python: Add reset() to workflow - #1
Draft
ShiyunXu wants to merge 3 commits into
Draft
Conversation
Introduce Workflow.reset(), which restores a workflow instance to its captured initial state so the same instance can be re-run cleanly (e.g. in a hosted-agent session where the instance is created once). The initial state is captured once per instance as an in-memory baseline checkpoint before the first run; reset() is rejected while a run is active. Also harden Runner.capture_checkpoint_object() to accept optional metadata and to reject capture while in-flight executor messages are present (mid-superstep state is not a clean baseline), raising WorkflowCheckpointException. This is part of breaking down the changes in microsoft#6407 into smaller PRs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ShiyunXu
had a problem deploying
to
github-app-auth
August 25, 2026 06:08 — with
GitHub Actions
Failure
ShiyunXu
had a problem deploying
to
github-app-auth
August 25, 2026 06:08 — with
GitHub Actions
Failure
Describe the quiescence precondition (no in-flight executor messages) in terms of checkpoint coherence rather than any specific caller, so the contract does not assume the WorkflowExecutor is the only consumer. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ShiyunXu
had a problem deploying
to
github-app-auth
August 25, 2026 06:11 — with
GitHub Actions
Failure
Rather than the runner querying has_messages() to guard capture, put the message-quiescence check where the messages live: the context's create_checkpoint_object now rejects creation while in-flight executor messages are present. The persisting create_checkpoint path (superstep boundaries, which legitimately snapshot pending messages) shares a new private _build_checkpoint helper and is not guarded. The runner's capture_checkpoint_object just prepares executor state and delegates. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ShiyunXu
had a problem deploying
to
github-app-auth
August 25, 2026 06:15 — with
GitHub Actions
Failure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation & Context
When a workflow is hosted as an agent (e.g. in a Foundry hosted-agent session), the workflow instance is built once when the session starts. A new interaction that doesn't carry a conversation/previous-response id should start a fresh run without any residual state from prior interactions. Today that requires rebuilding the workflow from the builder, which isn't possible when the instance is long-lived.
This adds
Workflow.reset(), which restores a workflow instance to its captured initial state so the same instance can be reused for a clean run.Description & Review Guide
This is the next slice of breaking down microsoft#6407 into smaller PRs (following the runner/workflow refactor and the per-executor serialization PRs).
What are the major changes?
Workflow.reset(). It restores the instance to an in-memory baseline checkpoint captured once per instance ({"kind": "initial_in_memory"}) via_ensure_initial_checkpoint(). The baseline is captured lazily just before the first run (or on firstreset()if that comes first), so it always reflects the pristine just-built state.reset()is rejected withWorkflowExceptionwhile a run is active.Runner.capture_checkpoint_object()to accept optionalmetadataand to reject capture while in-flight executor messages are present, raisingWorkflowCheckpointException. Mid-superstep message state is not a clean, resumable baseline; capture is only valid when the runner is quiescent. Pendingrequest_infoevents are intentionally not blocked, since idle-with-pending-requests is a stable point.What is the impact of these changes?
reset()is additive.capture_checkpoint_object()now enforces the quiescence precondition it always implied.What do you want reviewers to focus on?
reset()) and thereset()active-run guard.Related Issue
Part of the microsoft#6407 breakdown.
Fixes #
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.