Repository navigation
fix(fork): wait for branches to be cancelled before the fork returns - #591
Conversation
|
Thanks @mrsimonemms, added in 11da2ca: On |
Codex PR Review
No blocking issues. Ship it. Test execution could not be verified: the read-only environment prevents Go from creating its module cache. |
|
Thanks for the review. Applied in f009001: fork branches now start with For context, with the SDK version in |
|
Thanks. I'm going to do the automated review again. Because Zigflow uses rebased commits, can you squash all these into a single commit please?
|
When a workflow was cancelled while a non-competing fork was running, the await on the cancelled context returned at once and the fork closed in the same workflow task that requested the branch cancellations. The parent close policy then terminated the branches before they received the cancellation, so they ended as TERMINATED and their tasks never observed it. The fork now waits for every branch future to resolve on a disconnected context before returning the cancellation. Branches are started with WaitForCancellation so each future resolves only once its branch has closed. Competing forks were not affected because their branches use the REQUEST_CANCEL parent close policy. Adds unit tests for branch cancellation and cancellation cleanup, a cancel-fork e2e test, and a Gotchas line in the fork docs. Signed-off-by: Yash B Joshi <68319416+YJ-928@users.noreply.github.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
f009001 to
78e08c8
Compare
|
@mrsimonemms squashed into a single commit, 78e08c8. The code is unchanged from what you reviewed, the tests pass and the automated review is clean. No rush on the merge, thanks for taking the time to review it. |

Description
When a workflow is cancelled while a non-competing
forkis running, the fork's branches end asTERMINATEDrather thanCANCELED, and the tasks inside them never observe the cancellation, so nodev.zigflow.task.cancelledevent is emitted for them.This is a follow-up to #588. The fork waits for its branches with
workflow.Awaiton the workflow context. Once that context is cancelled the await returns at once, so the fork closes in the same workflow task that requests the branch cancellations. A non-competing fork uses the defaultTERMINATEparent close policy, so the branches are terminated before the cancellation reaches them. Competing forks are not affected because their branches useREQUEST_CANCEL.This change waits for every branch future to resolve on a disconnected context before the fork returns the cancellation. A child workflow future only resolves once the child has closed, so every branch has been cancelled by the time the workflow closes. The Gotchas section of the fork docs now says what cancelling the workflow does to the branches.
Related issue
Relates to #587. Follow-up to #588, which fixed it.
How to test
Unit test
go test ./pkg/zigflow/tasks/ -run TestForkTaskBuilderExecWaitsForBranchesWhenWorkflowCancelled -vOn
mainthis fails because neither branch observes the cancellation. With this change it passes.Manually
Start a worker with
zigflow run -f workflow.yaml, then:temporal workflow start --task-queue zigflow --type fork-cancel --workflow-id fork-cancel # wait a few seconds for both branches to start temporal workflow cancel --workflow-id fork-cancel temporal workflow list temporal workflow show --workflow-id fork-cancel_fork_left --output jsonOn
main,fork-cancelisCanceledbutfork-cancel_fork_leftandfork-cancel_fork_rightareTerminated. Their history ends withWorkflowExecutionTerminated, with the reasonby parent close policy. With this change all three areCanceled.Checklist
Fixes #...,Closes #...orRelates to #...