Python: discard pending State on failed/cancelled superstep (#7859) - #8306
Open
LI (ktz03) wants to merge 5 commits into
Open
Python: discard pending State on failed/cancelled superstep (#7859)#8306LI (ktz03) wants to merge 5 commits into
LI (ktz03) wants to merge 5 commits into
Conversation
Call State.discard() on runner failure and cancellation paths so staged writes cannot leak into a later successful run on the same Workflow. Fixes microsoft#7859.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Cleanup can still be skipped during event streaming and cancellation outside the polling block.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Prevents failed workflow supersteps from leaking staged Python state into later runs.
Changes:
- Discards pending state on failure and cancellation paths.
- Adds a workflow-reuse regression test for failures.
File summaries
| File | Description |
|---|---|
_runner.py |
Adds pending-state cleanup paths. |
test_runner.py |
Tests state isolation after failure. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 3
- Review effort level: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
- Scope cancel/BaseException cleanup across the full superstep until commit - Discard pending state before yielding failure events - Add cancellation regression that stages state then reuses the workflow
- Discard in finally so raising executor cleanup cannot skip it - Defer executor_failed yields until after discard - Block Workflow.run reuse while superstep cleanup is in progress
- Discard in finally so raising executor cleanup cannot skip it - Defer executor_failed yields until after discard - Block Workflow.run reuse while superstep cleanup is in progress
Reject concurrent cancel/run while ResponseStream cleanup or another exclusive entry holds the workflow, and hold _exclusive_run_hold for the cancel continuation.
Author
|
Eduard van Valkenburg (@eavanvalkenburg) Updated PR body to the repository template and addressed the latest review feedback on this head — please re-review when convenient. |
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
State.set()stages writes in_pending, but a failed or cancelled superstep previously left those writes intact. Because aWorkflowreuses the same runner/state acrossrun()calls, a later successful run couldcommit()stale pending writes from a prior failed/cancelled superstep.Fixes #7859.
Description & Review Guide
finallyso raising executor cleanup cannot skip it); deferexecutor_failedyields until after discard; blockWorkflow.runreuse while cleanup is in progress; lockcancel_pending_requestswith the same active/cleanup hold asrun().RunnerImpl.run_until_convergencecleanup ordering andWorkflow.cancel_pending_requests/_is_run_active.Related Issue
Fixes #7859
No other open PR targets this issue.
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.