Repository navigation
Fix eviction hang when an already-cancelled activity is cancelled again - #1947
Merged
tconley1428 merged 3 commits intoOct 9, 2026
Merged
Conversation
jtwillis92
force-pushed
the
fix-eviction-recancel-hang
branch
from
October 8, 2026 18:43
c470ec6 to
a496674
Compare
Contributor
Author
|
Codex review (2 rounds, approved) I ran a Codex adversarial review on this change. It checked:
Round 1 approved
Round 2 approved Approved at |
jtwillis92
marked this pull request as ready for review
October 8, 2026 19:20
tconley1428
reviewed
Oct 8, 2026
tconley1428
approved these changes
Oct 9, 2026
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.
Fixes #1938.
Since #1814,
_ActivityHandle._request_cancelreturns early when a cancel command was already sent for the current_seq. On eviction,_apply_remove_from_cachecancels every task, and an activity handle task parked in_await_temporal_operationcalls_request_cancelagain. Up to 1.32.0 that path always called_add_command(), which raises_WorkflowBeingEvictedErrorwhile deleting and ends the task. With the early return nothing raises, so the task uncancels and waits on a future that never resolves. Eviction then fails withEviction processed, but 1 tasks remain(2 when the workflow itself is still awaiting the handle), retries every 2s forever, the run's workflow tasks time out on that worker, andWorker.shutdown()hangs.To fix it,
_request_cancelnow skips the dedup while the instance is deleting, so_add_command()raises as it did before 1.33.0. Outside eviction the dedup is unchanged, so #1813 stays fixed, and nothing is emitted during eviction since_add_command()raises first. Local activities share_ActivityHandleand are covered by the same change. Child workflow, Nexus operation, external signal and timer cancellation have no same-sequence dedup like the activity handle (a timer only skips the command once it is no longer pending), so they were not affected.The retry loop in
_handle_cache_evictionis what turns the stuck task into the shutdown hang. That loop is intentional (it keeps a workflow whose tasks are still alive from being torn down by GC), so it is left as is.test_workflow_cancel_activity_then_evictcovers three shapes:TRY_CANCEL, then a workflow task failure in the same activationWAIT_CANCELLATION_COMPLETEDon a worker withmax_cached_workflows=0(the repro from the issue comments)The workflow only cancels after the activity reports that it started (the test signals it), so the cancel always reaches a running activity. Each case asserts the workflow completes,
_could_not_evict_countstays 0 and worker shutdown finishes. All 3 fail on main at the 60s pytest timeout with atasks remainerror whose stacks include the parked_ActivityHandle, and pass with the fix.Validation, run locally on Linux x86_64 with Python 3.11. I didn't have a Rust toolchain on this machine, so I ran against the prebuilt 1.34.0 bridge (this is a Python-only change, and unmodified main passes
tests/worker/test_workflow.pyon that bridge).pytest tests/worker/test_workflow.py: 234 passed, 2 skipped (main: 231 passed, 2 skipped)pytest tests/worker/test_workflow.py -k test_workflow_cancel_activity_then_evict: 3 passed, run twice (about 9s each)pytest tests/worker/test_workflow.py -k test_workflow_cancel_activity --workflow-environment time-skipping: 6 passedpytest tests/worker/test_activity.py: 57 passedruff check --select I,ruff format --check,pyright,mypy,basedpyrightandpydocstyle: cleanI also ran the repro script from the issue against a dev server. Main times out with the run stuck
RUNNING,could_not_evict_count: 1and a hung shutdown, while the fix printsresult: done,could_not_evict_count: 0andworker shutdown: drained, same as 1.32.0. The issue's other shape (aWAIT_CANCELLATION_COMPLETEDcancel, then eviction viamax_cached_workflows=1plus a second workflow) and variants with a local activity or a permanent task failure behave the same way, a stuck eviction and hung shutdown on main and a clean eviction and shutdown with the fix.