Skip to content

[copilot-finds] Bug: WhenAllTask constructor resets _completedTasks counter, causing hang with pre-completed children #131

@github-actions

Description

@github-actions

Problem

The WhenAllTask constructor resets _completedTasks to 0 after calling super(tasks). The CompositeTask base constructor processes already-complete children via onChildCompleted(), correctly incrementing _completedTasks. The subsequent reset in WhenAllTask discards this count.

File: packages/durabletask-js/src/task/when-all-task.ts, lines 14-15

Root Cause

The initialization of _completedTasks and _failedTasks in WhenAllTask's constructor is redundant — CompositeTask already initializes both fields to 0 before iterating children. The re-initialization in WhenAllTask runs after the base class loop, wiping out any increments from pre-completed children.

Impact

When WhenAllTask is constructed with a mix of already-complete and pending tasks:

  1. CompositeTask correctly counts the already-complete children (e.g., _completedTasks = K)
  2. WhenAllTask resets _completedTasks = 0
  3. When the remaining N - K tasks complete, _completedTasks reaches N - K instead of N
  4. The completion check _completedTasks == _tasks.length (N - K == N) is never true
  5. The WhenAllTask never completes, causing the orchestration to hang indefinitely

This can occur whenever an orchestrator reuses a previously completed task reference in a whenAll call.

Proposed Fix

Remove the redundant this._completedTasks = 0 and this._failedTasks = 0 lines from the WhenAllTask constructor. The base class CompositeTask already handles initialization before processing pre-completed children.

Note: _failedTasks is also dead code — it is declared and initialized but never incremented anywhere in the codebase.

Metadata

Metadata

Assignees

No one assigned

    Labels

    copilot-findsFindings from daily automated code review agent

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions