Skip to content

fix: skip async invoke self-cancel on own done.invoke#627

Merged
fgmacedo merged 2 commits into
fgmacedo:developfrom
loRes228:develop
Jun 12, 2026
Merged

fix: skip async invoke self-cancel on own done.invoke#627
fgmacedo merged 2 commits into
fgmacedo:developfrom
loRes228:develop

Conversation

@loRes228

Copy link
Copy Markdown
Contributor

On the async engine, when a state exits on its own done.invoke, InvokeManager._cancel
calls invocation.task.cancel() unconditionally — but that task is the current task
and the machine gets stuck.

The sync branch already handles exactly this (step 4 skips the join when
invocation.thread is not threading.current_thread()"skip if we ARE that thread").
The async branch just missed the symmetric guard. This adds it:

         # 3) Cancel the async task (raises CancelledError at next await).
-        if invocation.task is not None and not invocation.task.done():
+        if (
+            invocation.task is not None
+            and invocation.task is not asyncio.current_task()
+            and not invocation.task.done()
+        ):  
             invocation.task.cancel()

@fgmacedo

Copy link
Copy Markdown
Owner

Hi @loRes228 , how are you? Thanks for pointing out and the fix.

Can you please add a regression test that reproduces the issue?

@codecov

codecov Bot commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (34d51cf) to head (e20c88e).

Additional details and impacted files
@@            Coverage Diff            @@
##           develop      #627   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           42        42           
  Lines         4976      4976           
  Branches       812       812           
=========================================
  Hits          4976      4976           
Flag Coverage Δ
unittests 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@loRes228

Copy link
Copy Markdown
Contributor Author

Hi @loRes228 , how are you? Thanks for pointing out and the fix.

Can you please add a regression test that reproduces the issue?

Hi, ofc

@sonarqubecloud

Copy link
Copy Markdown

@fgmacedo fgmacedo merged commit 51a54a3 into fgmacedo:develop Jun 12, 2026
10 checks passed
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.

2 participants