Skip to content

[copilot-finds] Bug: Fix whenAll([]) hanging orchestration forever#118

Merged
YunchuWang merged 1 commit intomainfrom
copilot-finds/bug/fix-whenall-empty-array-hang
Mar 2, 2026
Merged

[copilot-finds] Bug: Fix whenAll([]) hanging orchestration forever#118
YunchuWang merged 1 commit intomainfrom
copilot-finds/bug/fix-whenall-empty-array-hang

Conversation

@YunchuWang
Copy link
Member

@YunchuWang YunchuWang commented Mar 2, 2026

whenAll([]) creates a WhenAllTask that never completes because no children exist to trigger onChildCompleted(). The condition _completedTasks == _tasks.length (0 == 0) inside onChildCompleted is never reached since the method is never called. This causes orchestrations to hang forever when using whenAll with a dynamically generated list that happens to be empty.

Changes:

  • WhenAllTask: Immediately complete with [] when given an empty task array
  • WhenAnyTask: Throw an error for empty task array (matching .NET behavior)
  • RuntimeOrchestrationContext.run(): Handle already-complete initial yielded tasks by calling resume() immediately, enabling the generator to continue

Summary

What changed?

Why is this change needed?

Issues / work items

  • Resolves #
  • Related #

Project checklist

  • Release notes are not required for the next release
    • Otherwise: Notes added to CHANGELOG.md
  • Backport is not required
    • Otherwise: Backport tracked by issue/PR #issue_or_pr
  • All required tests have been added/updated (unit tests, E2E tests)
  • Breaking change?
    • If yes:
      • Impact:
      • Migration guidance:

AI-assisted code disclosure (required)

Was an AI tool used? (select one)

  • No
  • Yes, AI helped write parts of this PR (e.g., GitHub Copilot)
  • Yes, an AI agent generated most of this PR

If AI was used:

  • Tool(s):
  • AI-assisted areas/files:
  • What you changed after AI output:

AI verification (required if AI was used):

  • I understand the code and can explain it
  • I verified referenced APIs/types exist and are correct
  • I reviewed edge cases/failure paths (timeouts, retries, cancellation, exceptions)
  • I reviewed concurrency/async behavior
  • I checked for unintended breaking or behavior changes

Testing

Automated tests

  • Result: Passed / Failed (link logs if failed)

Manual validation (only if runtime/behavior changed)

  • Environment (OS, Node.js version, components):
  • Steps + observed results:
    1.
    2.
    3.
  • Evidence (optional):

Notes for reviewers

  • N/A

whenAll([]) creates a WhenAllTask that never completes because no children
exist to trigger onChildCompleted(). The condition _completedTasks == _tasks.length
(0 == 0) inside onChildCompleted is never reached since the method is never called.
This causes orchestrations to hang forever when using whenAll with a dynamically
generated list that happens to be empty.

Changes:
- WhenAllTask: Immediately complete with [] when given an empty task array
- WhenAnyTask: Throw an error for empty task array (matching .NET behavior)
- RuntimeOrchestrationContext.run(): Handle already-complete initial yielded tasks
  by calling resume() immediately, enabling the generator to continue

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 2, 2026 21:30
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug where whenAll([]) causes orchestrations to hang indefinitely because onChildCompleted() is never called for an empty task array, so the completion condition is never reached.

Changes:

  • WhenAllTask: Immediately marks itself as complete with an empty result when constructed with an empty array.
  • WhenAnyTask: Throws an error on construction when given an empty array, matching .NET behavior.
  • RuntimeOrchestrationContext: Detects already-complete tasks after a yield and calls resume() immediately.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/task/when-all-task.ts Marks WhenAllTask as immediately complete when given an empty task array
src/task/when-any-task.ts Throws on empty task array in WhenAnyTask constructor
src/worker/runtime-orchestration-context.ts Resumes generator immediately when the yielded task is already complete
test/orchestration_executor.spec.ts Adds tests for whenAll([]), whenAll([]) followed by more work, and whenAny([])

@YunchuWang YunchuWang merged commit af38564 into main Mar 2, 2026
31 of 32 checks passed
@YunchuWang YunchuWang deleted the copilot-finds/bug/fix-whenall-empty-array-hang branch March 2, 2026 22:06
@YunchuWang
Copy link
Member Author

image pass

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants