fix(workflow): run termination bookkeeping on a cancellation-safe context (EN-1224) - #187
fix(workflow): run termination bookkeeping on a cancellation-safe context (EN-1224)#187flemzord wants to merge 1 commit into
Conversation
…text When a Run workflow is cancelled, config.run returns a CanceledError and the run context is already cancelled. The subsequent UpdateStage / SendWorkflowStageTerminationEvent and UpdateInstance / SendWorkflowTerminationEvent activities were executed on that cancelled context, so they failed immediately: the instance/stage rows were left stuck "running" and no FAILED_WORKFLOW(_STAGE) event was published. Add terminationContext(), which returns the original context normally but a workflow.NewDisconnectedContext when the workflow has been cancelled, and use it for the terminal bookkeeping activities in both run() and Run. The normal (non-cancelled) path is unchanged (still uses the live context); covered by the existing end-to-end TestConfig.
|
Warning Review limit reached
More reviews will be available in 16 minutes and 40 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more credits in the billing tab to continue. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Superseded by #199, which consolidates this change with the related reliability and safety fixes on top of the current main branch. |
Problem (H4 — HIGH)
When a
Runworkflow is cancelled,config.runreturns aCanceledErrorand the run context is already cancelled. The terminal bookkeeping activities were then executed on that cancelled context:UpdateStage+SendWorkflowStageTerminationEvent(config.go)UpdateInstance+SendWorkflowTerminationEvent(run.go)They failed immediately, so the instance/stage rows were left stuck "running" forever and no
FAILED_WORKFLOW(_STAGE)event was published.Fix
Add
terminationContext(ctx)which returns:workflow.NewDisconnectedContextwhen the workflow has been cancelled, so the bookkeeping still runs.Use it for the terminal activities in both
run()andRun.Testing
The normal path is unchanged and remains covered by the end-to-end
TestConfig. A dedicated cancellation integration test would require registering a blocking stage inside theworkflowinternal test package, which creates an import cycle (workflow → stages/... → workflow); the fix is small and the cancellation behavior is asserted by reasoning. Happy to add an external-package test if preferred.Severity: HIGH.