Skip to content

Fix cyclic flows silently breaking when persistence ID is passed in inputs#4501

Merged
joaomdmoura merged 10 commits intomainfrom
joaomdmoura/fix-flow-with-loop-restarting
Feb 18, 2026
Merged

Fix cyclic flows silently breaking when persistence ID is passed in inputs#4501
joaomdmoura merged 10 commits intomainfrom
joaomdmoura/fix-flow-with-loop-restarting

Conversation

@joaomdmoura
Copy link
Collaborator

Fix _is_execution_resuming flag incorrectly suppressing cyclic re-execution in persisted flows

Summary

Flows using @persist() with kickoff(inputs={"id": ...}) to reload state would silently terminate after the first cycle iteration instead of completing all iterations

Root cause: _is_execution_resuming was set to True even when _completed_methods was empty (nothing to actually resume), and was only cleared after the entire flow finished — causing the resumption short-circuit path to intercept every cyclic re-entry

Guarded the flag so it's only set when there are completed methods to replay through, and added a regression test combining persistence + ID input + cyclic router flow

joaomdmoura and others added 9 commits February 16, 2026 11:50
- Introduced `FlowInputRequestedEvent` and `FlowInputReceivedEvent` to manage user input requests and responses during flow execution.
- Added `InputProvider` protocol and `InputResponse` dataclass for customizable input handling.
- Enhanced `Flow` class with `ask()` method to request user input, including timeout handling and state checkpointing.
- Updated `FlowConfig` to support custom input providers.
- Created `input_provider.py` for default input provider implementations, including a console-based provider.
- Added comprehensive tests for `ask()` functionality, covering basic usage, timeout behavior, and integration with flow machinery.
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
- Removed unnecessary variable assignments for the result of `flow.kickoff()` in two test cases, improving code clarity.
- Updated assertions to ensure the expected execution log entries are present after the flow kickoff, enhancing test reliability.
- Introduced a new context variable, `current_flow_method_name`, to store the name of the currently executing flow method, defaulting to "unknown".
- Updated the Flow class to set and reset this context variable during method execution, enhancing the ability to track method calls without stack inspection.
- Removed the obsolete `_resolve_calling_method_name` method, streamlining the code and improving clarity.
- Introduced a new `InputHistoryEntry` TypedDict to structure user input history for the `ask()` method, capturing details such as the question, user response, method name, timestamp, and associated metadata.
- Updated the `_input_history` attribute in the Flow class to utilize the new `InputHistoryEntry` type, improving type safety and clarity in input history management.
- Updated the `ask()` method to improve timeout management by manually managing the `ThreadPoolExecutor`, preventing potential deadlocks when the provider call exceeds the timeout duration.
- Added clarifications in the documentation regarding the behavior of the timeout and the underlying request handling, ensuring better understanding for users.
- Introduced flow memory reset capabilities in the `reset_memories_command`, allowing for both crew and flow memory resets.
- Added a new utility function `_reset_flow_memory` to handle memory resets for individual flow instances, improving modularity and clarity.
- Updated the `get_flows` utility to discover flow instances from project files, enhancing the CLI's ability to manage flow states.
- Expanded test coverage to validate the new flow memory reset features, ensuring robust functionality and error handling.
…yclic flow persistence

- Updated the logic for setting the `_is_execution_resuming` flag to ensure it only activates when there are completed methods to replay, preventing incorrect suppression of cyclic re-execution during state reloads.
- Added a regression test to validate that cyclic router flows complete all iterations when persistence is enabled and an 'id' is passed in inputs, ensuring robust handling of flow execution in these scenarios.
@joaomdmoura joaomdmoura merged commit 8df499d into main Feb 18, 2026
44 checks passed
@joaomdmoura joaomdmoura deleted the joaomdmoura/fix-flow-with-loop-restarting branch February 18, 2026 06:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant