fix(flow): reset cancellation flag at the start of each execution - #97
Open
XuQuanxin04 wants to merge 1 commit into
Open
fix(flow): reset cancellation flag at the start of each execution#97XuQuanxin04 wants to merge 1 commit into
XuQuanxin04 wants to merge 1 commit into
Conversation
cancel() set self._cancelled = True, but that flag was only ever read in _execute() and never reset. Because run(), resume() and rerun_step() all share the same _execute() path on a LightFlow instance, a single cancel() call permanently poisoned the instance: every subsequent run skipped all of its steps with "cancelled before execution", even when cancellation was requested after a run had already finished. Reset the flag when a new execution begins. In-flight cancellation is unaffected because the flag is still re-checked before every step. Co-Authored-By: Claude <noreply@anthropic.com>
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.
Summary
LightFlow.cancel()setsself._cancelled = True, but that flag was only read in_execute()and never reset. Becauserun(),resume(), andrerun_step()all go through the same_execute()path on a reusableLightFlowinstance, a singlecancel()call permanently poisoned the instance — every subsequent run skipped all of its steps with"cancelled before execution", even when cancellation was requested after a run had already finished.Reproduction
Fix
Reset
self._cancelled = Falseat the start of_execute(). In-flight cancellation is unaffected — the flag is still re-checked before every step, so acancel()from another thread during a run still skips the remaining steps of that run.Compatibility
agent.run("hello")behavior is unchanged.stream=Truebehavior is unchanged.cancel()behavior is preserved (added a test for it).Tests
python -m compileall -q LightAgentPYTHONPATH=. python -m pytest -q tests/test_v065_core.py tests/test_v070_tracing.py tests/test_memory_policy.py— 57 passedtests/test_lightflow.py:test_lightflow_cancel_during_run_skips_remaining_steps_of_that_run— guards the existing in-flight cancel behavior.test_lightflow_cancel_between_runs_does_not_poison_the_next_run— regression test for this bug.tests/test_lightflow.py: 16 passed.