Fix WhenAllTask constructor resetting _completedTasks counter#143
Open
YunchuWang wants to merge 2 commits intomainfrom
Open
Fix WhenAllTask constructor resetting _completedTasks counter#143YunchuWang wants to merge 2 commits intomainfrom
YunchuWang wants to merge 2 commits intomainfrom
Conversation
Fixes #131 The WhenAllTask constructor redundantly re-initialized _completedTasks and _failedTasks to 0 after calling super(tasks). Since CompositeTask's constructor already initializes these fields and then processes pre-completed children via onChildCompleted(), the reset wiped out the correct count, causing WhenAllTask to never complete when some children were already complete at construction time. Also removes _failedTasks reset (dead code - never incremented anywhere). Added 8 unit tests for WhenAllTask covering: - Empty task array - All pending children completing - Fail-fast on child failure - Pre-completed children (the bug scenario) - All children pre-completed - Pre-failed child - Post-fail-fast completion - Pending tasks count tracking
…tion or class' Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes issue #131 where WhenAllTask's constructor reset _completedTasks to 0 after calling super(tasks), which caused WhenAllTask to never complete when constructed with pre-completed children. The CompositeTask base class constructor correctly initializes counters to 0 and then processes pre-completed children via onChildCompleted(). The redundant re-initialization in the subclass wiped out that count.
Changes:
- Removed the redundant
this._completedTasks = 0andthis._failedTasks = 0lines from theWhenAllTaskconstructor and added an explanatory comment - Added a comprehensive test file (
when-all-task.spec.ts) with 8 unit tests covering empty arrays, pending children, fail-fast, pre-completed children (the bug scenario), and pending tasks tracking
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
packages/durabletask-js/src/task/when-all-task.ts |
Removed redundant counter re-initialization after super() call, added explanatory comment |
packages/durabletask-js/test/when-all-task.spec.ts |
New test file with 8 unit tests covering WhenAllTask behavior including the regression scenario from #131 |
|
|
||
| import { WhenAllTask } from "../src/task/when-all-task"; | ||
| import { CompletableTask } from "../src/task/completable-task"; | ||
|
|
There was a problem hiding this comment.
The Task import is unused in this test file — only WhenAllTask and CompletableTask are referenced. It should be removed to keep the imports clean.
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.
Problem
Fixes #131
The
WhenAllTaskconstructor resets_completedTasksto0after callingsuper(tasks). TheCompositeTaskbase constructor processes already-complete children viaonChildCompleted(), correctly incrementing_completedTasks. The subsequent reset inWhenAllTaskdiscards this count, causing the task to never complete when some children are already complete at construction time.Root Cause
In
when-all-task.ts, lines 14-15:When
WhenAllTaskis constructed with a mix of already-complete and pending tasks:CompositeTaskcorrectly counts the already-complete children (e.g.,_completedTasks = K)WhenAllTaskresets_completedTasks = 0N - Ktasks complete,_completedTasksreachesN - Kinstead ofN_completedTasks == _tasks.lengthis never trueWhenAllTasknever completes, causing the orchestration to hangFix
Removed the redundant
this._completedTasks = 0andthis._failedTasks = 0lines. The base classCompositeTaskalready initializes both fields to0before processing pre-completed children.Tests
Added 8 unit tests in
when-all-task.spec.ts:All 839 unit tests pass.