Enhance task execution with cycle control and retry mechanisms#42
Merged
Conversation
…to task execution
Collaborator
Author
|
@claude plz review this PR. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds first-class examples, tests, and refactors to centralize cycle (iteration) and retry control in the Graflow workflow engine via dedicated controllers, with retries now opt-in by default.
Changes:
- Introduces
CycleController-backed iteration behavior (next_iteration,cycle_count,max_cycles,can_iterate) with expanded tests. - Introduces
RetryControllerand@task(max_retries=...)with expanded unit/integration tests; updates default retry behavior todefault_max_retries=0. - Adds new example scripts and documentation for iteration and retry workflows.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
graflow/core/context.py |
Delegates cycle/retry state to controllers; refactors next_iteration() and per-task controller configuration. |
graflow/core/engine.py |
Adds engine-level retry loop that re-enqueues failed tasks. |
graflow/core/cycle.py |
Refactors cycle logic into CycleController with explicit limit checking. |
graflow/core/retry.py |
Adds RetryController for retry budgets, counts, and last-error tracking. |
graflow/core/task.py |
Extends TaskWrapper to carry max_cycles/max_retries through construction/pickling. |
graflow/core/decorators.py |
Extends @task(...) API to accept max_cycles and max_retries. |
graflow/exceptions.py |
Adds RetryLimitExceededError. |
examples/07_dynamic_tasks/task_iterations.py |
New iteration-focused example script. |
examples/07_dynamic_tasks/task_retries.py |
New retry-focused example script. |
examples/07_dynamic_tasks/README.md |
Documents new examples and recommended learning order. |
tests/core/test_cycle_controller.py |
New unit tests for CycleController. |
tests/core/test_next_iteration.py |
New integration tests for next_iteration() behavior through the engine. |
tests/core/test_cycle_controller_integration.py |
Converts prior script-like file into pytest assertions for integration coverage. |
tests/core/test_retry_controller.py |
New unit tests for RetryController. |
tests/core/test_retry_integration.py |
New integration tests validating engine retry lifecycle and context visibility. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Exception already stored by handler, just re-raise | ||
| # Retry logic: re-enqueue task if retries remain | ||
| retry_ctrl = context.retry_controller | ||
| base_task_id = task_id # retry uses the original task_id |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
Comment on lines
282
to
283
| # No retries left — re-raise | ||
| raise exceptions.as_runtime_error(e) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
myui
force-pushed
the
cycle_controller_fix
branch
from
April 3, 2026 08:25
5cbdfb3 to
0c4f691
Compare
Collaborator
Author
|
@claude review this PR. |
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.
This pull request introduces two new example scripts—
task_iterations.pyandtask_retries.py—with accompanying documentation, and refactors the core cycle and retry control logic in the workflow engine to centralize and clarify iteration and retry management. The changes make the cycle and retry mechanisms more robust and easier to use, and update the default retry behavior to be opt-in rather than opt-out.Key changes:
New Examples and Documentation
task_iterations.pyandtask_retries.pyexample scripts, each with detailed docstrings and usage instructions, to demonstrate iterative task execution and automatic retries, respectively. TheREADME.mdwas updated to include these examples, their concepts, and recommended order of study. [1] [2] [3] [4]Cycle (Iteration) Control Refactor
CycleController, making it the single source of truth. Task execution context now delegates cycle-related properties and checks (likecycle_count,max_cycles,can_iterate()) to the controller. [1] [2] [3] [4] [5]Retry Control Refactor
RetryController(imported and instantiated inExecutionContext) to manage retry counts and limits, mirroring the pattern used for cycles. Task execution context delegates retry-related properties to this controller. [1] [2] [3] [4]max_retriesare now set on the controller at execution time, ensuring correct retry behavior for each task.Default Behavior and API Changes
default_max_retriesfrom 3 to 0, making retries opt-in rather than opt-out, which is safer and more predictable for most workflows. [1] [2]These changes improve the reliability, clarity, and usability of dynamic task iteration and retry features in the workflow engine.