Skip to content

refactor: remove dead _failedTasks field and unused async-pageable.ts - #284

Open
YunchuWang wants to merge 2 commits into
mainfrom
yunchuwang-remove-dead-code-composite-task
Open

refactor: remove dead _failedTasks field and unused async-pageable.ts#284
YunchuWang wants to merge 2 commits into
mainfrom
yunchuwang-remove-dead-code-composite-task

Conversation

@YunchuWang

@YunchuWang YunchuWang commented Jul 7, 2026

Copy link
Copy Markdown
Member

Summary

Dead-code cleanup in the core SDK. No behavior change — build, lint, and the full core test suite (66 suites / 1165 tests) all pass after merging main.

What & why

1. Removed the _failedTasks field from CompositeTask

_failedTasks was declared and initialized to 0 in the constructor but never incremented or read anywhere in the repository. The only occurrences were the declaration, the constructor init, and a stale comment:

packages/durabletask-js/src/task/composite-task.ts:12:  _failedTasks: number;
packages/durabletask-js/src/task/composite-task.ts:19:    this._failedTasks = 0;
packages/durabletask-js/src/task/when-all-task.ts:14:  // ...references _failedTasks

Neither WhenAllTask.onChildCompleted() nor WhenAnyTask.onChildCompleted() ever touched it. The field was misleading: it implied failed children were tracked separately, when in reality CompositeTask counts every settled child — successful and failed — in the single _completedTasks counter. A separate failure counter was never needed.

This still holds after #301 changed WhenAllTask from fail-fast to wait-all: the wait-all path derives failures by filtering _tasks for isFailed at completion time, so it has no use for a running failure count either.

2. Fixed the stale comment in WhenAllTask

The constructor comment warned against re-initializing _completedTasks or _failedTasks. With _failedTasks gone, the comment now references only _completedTasks so it stays accurate.

3. Deleted the dead src/utils/async-pageable.ts (91 lines)

This file contained an AsyncPageable class / Page interface / PageFetcher type that was never imported by any file. The real pagination implementation lives in src/orchestration/page.ts, which is exported from index.ts and consumed by client.ts and the export-history client. Verified before deleting:

  • No file references it by path (grep "async-pageable" → only the file itself).
  • Every AsyncPageable / createAsyncPageable import resolves to orchestration/page.ts (note: async-pageable.ts didn't even export createAsyncPageable).
  • It was not re-exported from any barrel (there is no utils/index.ts).

The core build stays green after deletion, confirming nothing depended on it.

4. Added tests documenting the real behavior

To capture the intent that _failedTasks misleadingly implied was separate:

  • when-all-task.spec.ts — verifies completedTasks reaches 2 for one successful and one failed child (single counter, no separate failure count), and that the WhenAll only settles once every child is terminal.
  • when-any-task.spec.ts — verifies WhenAnyTask settles on the first completed child regardless of success/failure and does not track failures separately (a later successful child does not override an already-settled failed child).

Merge with main

main moved WhenAllTask from fail-fast to wait-all with AggregateError (#301), which conflicted with the test added here. Resolution: all of main's tests are kept verbatim, and the _failedTasks documentation test was rewritten for wait-all semantics. Only the two source-file edits and the two added tests remain as this PR's net diff against main.

Review feedback

  • @halspang: the third child task in the new WhenAll test was unused — removed, the test now uses only the two children it actually exercises.

Verification

  • npm run build:core — clean compile (confirms deleting async-pageable.ts broke nothing).
  • npx eslint on all changed files — exit 0.
  • npx jest --runInBand (full core suite) — 66 suites, 1165 tests, all pass.

Fixes #217

The `_failedTasks` field on `CompositeTask` was declared and initialized to
0 but never incremented or read anywhere in the repo (confirmed by grep).
Neither `WhenAllTask.onChildCompleted()` nor `WhenAnyTask.onChildCompleted()`
touched it. It misleadingly implied failed children were tracked separately
from `_completedTasks`, when in fact `WhenAllTask` counts every settled child
-- successful or failed -- in the single `_completedTasks` counter. Removed
the field and updated the now-stale comment in `WhenAllTask` that referenced it.

`src/utils/async-pageable.ts` was an unimported `AsyncPageable` class
superseded by the real pagination implementation in `src/orchestration/page.ts`
(exported from index.ts and used by client.ts and the export-history client).
No file referenced it by path or symbol, and it was not re-exported from any
barrel, so deleting it is safe -- the core build stays green.

Added unit tests documenting the real behavior: `WhenAllTask.completedTasks`
counts both successful and failed child completions, and `WhenAnyTask` settles
on the first completed child regardless of success/failure without tracking
failures separately. No behavior change.

Fixes #217

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 7, 2026 21:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Dead-code cleanup in the core DurableTask JS SDK to reduce confusion and better document actual composite task semantics, without changing runtime behavior.

Changes:

  • Removed the unused _failedTasks field from CompositeTask and updated the related stale comment in WhenAllTask.
  • Deleted the unused src/utils/async-pageable.ts implementation (pagination is provided by src/orchestration/page.ts).
  • Added unit tests to document that WhenAllTask.completedTasks counts both successful and failed child completions, and that WhenAnyTask settles on the first completed (even failed) child without later override.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/durabletask-js/src/task/composite-task.ts Removes dead _failedTasks field from composite task state.
packages/durabletask-js/src/task/when-all-task.ts Updates constructor comment to match current composite task behavior.
packages/durabletask-js/src/utils/async-pageable.ts Deletes unused pageable implementation to avoid duplicate/confusing pagination code.
packages/durabletask-js/test/when-all-task.spec.ts Adds regression test documenting completedTasks increments for both success and failure.
packages/durabletask-js/test/when-any-task.spec.ts Adds regression test documenting first-settled-child behavior even when the first completion is a failure.

Comment thread packages/durabletask-js/test/when-all-task.spec.ts
kaibocai
kaibocai previously approved these changes Jul 27, 2026
Resolves the conflict in when-all-task.spec.ts. main switched WhenAllTask from
fail-fast to wait-all with AggregateError (#301), so all of main's tests are kept
as-is and the _failedTasks documentation test is rewritten for wait-all semantics:
it now asserts the shared counter reaches 2 (one success + one failure) and that
the task only completes once every child is settled.

Also addresses review feedback: the third child task in that test was unused, so
the test now uses the two children it actually exercises.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 6b0b5f1d-9362-4a4e-9675-e6a7149d8fbc
Copilot AI review requested due to automatic review settings July 27, 2026 16:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@YunchuWang
YunchuWang requested a review from halspang July 27, 2026 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[copilot-finds] Improve: Dead _failedTasks field in CompositeTask and dead async-pageable.ts file

4 participants