Commit 18bfef4
authored
fix: propagate cancellation to scopes and awaits registered after cancel (#770)
* fix: propagate cancellation to scopes and awaits registered after cancel
Scope cancellation was a one-shot pass over the onCancel handlers: any
cancellation-aware resource registered after cancel() had already run was
never notified. As a result a nested scope created under an already
cancelled parent was born uncancelled, and an await registered in an
already cancelled scope blocked forever (the workflow got stuck).
Introduce a register-or-fire-immediately helper (addOnCancel) used by the
public onCancel(), onAwait() and createScope(); store the cancellation
reason so late handlers receive it; and guard onException()/onResult()
against a double close pass. This matches the Go/Java/TS SDKs, where
cancellation is sticky and observed at registration time.
Adds acceptance tests covering nested-scope inheritance, fail-fast await,
the public onCancel hook, and a faithful replica of the issue reproduction
(each one hangs without the fix).
Fixes #769
* test: add assertions for trailed runLocked behavior
* feat(workflow): gate cancellation propagation behind a feature flag
Make the sticky scope-cancellation behavior opt-in via
FeatureFlags::$propagateCancellationToNewScopes (default false = previous
behavior). When enabled, a nested scope, await or onCancel handler registered
after the surrounding scope was already cancelled is notified immediately
instead of being missed.
- Scope reads the flag at addOnCancel() and nextPromise().
- Acceptance suite enables it in RuntimeBuilder::init() alongside the other flags.
- Add a unit test covering both flag states.1 parent 9a0f42d commit 18bfef4
7 files changed
Lines changed: 473 additions & 18 deletions
File tree
- src
- Internal/Workflow/Process
- Worker
- tests
- Acceptance
- App
- Extra/Workflow
- Unit/Internal/Workflow/Process
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
87 | 88 | | |
88 | 89 | | |
89 | 90 | | |
| 91 | + | |
| 92 | + | |
90 | 93 | | |
91 | 94 | | |
92 | 95 | | |
| |||
191 | 194 | | |
192 | 195 | | |
193 | 196 | | |
194 | | - | |
| 197 | + | |
195 | 198 | | |
196 | 199 | | |
197 | 200 | | |
| |||
217 | 220 | | |
218 | 221 | | |
219 | 222 | | |
| 223 | + | |
220 | 224 | | |
221 | 225 | | |
222 | 226 | | |
| |||
280 | 284 | | |
281 | 285 | | |
282 | 286 | | |
283 | | - | |
| 287 | + | |
284 | 288 | | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
| 289 | + | |
289 | 290 | | |
290 | 291 | | |
291 | 292 | | |
| |||
329 | 330 | | |
330 | 331 | | |
331 | 332 | | |
332 | | - | |
333 | | - | |
| 333 | + | |
334 | 334 | | |
335 | 335 | | |
336 | 336 | | |
| |||
371 | 371 | | |
372 | 372 | | |
373 | 373 | | |
374 | | - | |
| 374 | + | |
375 | 375 | | |
376 | 376 | | |
377 | 377 | | |
| |||
390 | 390 | | |
391 | 391 | | |
392 | 392 | | |
393 | | - | |
394 | | - | |
395 | | - | |
| 393 | + | |
396 | 394 | | |
397 | 395 | | |
398 | 396 | | |
| |||
460 | 458 | | |
461 | 459 | | |
462 | 460 | | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
463 | 475 | | |
464 | 476 | | |
465 | 477 | | |
466 | | - | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
467 | 482 | | |
468 | 483 | | |
469 | 484 | | |
| |||
525 | 540 | | |
526 | 541 | | |
527 | 542 | | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
528 | 548 | | |
529 | 549 | | |
530 | 550 | | |
| |||
537 | 557 | | |
538 | 558 | | |
539 | 559 | | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
540 | 565 | | |
541 | 566 | | |
542 | 567 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
67 | 81 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| 91 | + | |
91 | 92 | | |
92 | 93 | | |
93 | 94 | | |
| |||
0 commit comments