Skip to content

Fix retry handler treating undefined/null/NaN/Infinity as retry signal#142

Open
YunchuWang wants to merge 1 commit intomainfrom
copilot-finds/bug/fix-retry-handler-undefined-return-infinite-loop
Open

Fix retry handler treating undefined/null/NaN/Infinity as retry signal#142
YunchuWang wants to merge 1 commit intomainfrom
copilot-finds/bug/fix-retry-handler-undefined-return-infinite-loop

Conversation

@YunchuWang
Copy link
Member

The tryHandleRetry method used a negative check (retryResult !== false) to determine if a custom retry handler wanted to retry. This treated any non-false value — including undefined, null, NaN, and Infinity — as a retry signal, causing infinite retry loops or invalid timer creation.

Changed to a positive check that only accepts explicit true or finite numbers: retryResult === true || (typeof retryResult === 'number' && Number.isFinite(retryResult)).

Added 6 new unit tests covering: undefined return, null return, positive delay (number), zero delay, NaN, and Infinity.

Fixes #140

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

The tryHandleRetry method used a negative check (retryResult !== false)
to determine if a custom retry handler wanted to retry. This treated any
non-false value — including undefined, null, NaN, and Infinity — as a
retry signal, causing infinite retry loops or invalid timer creation.

Changed to a positive check that only accepts explicit true or finite
numbers: retryResult === true || (typeof retryResult === 'number' &&
Number.isFinite(retryResult)).

Added 6 new unit tests covering: undefined return, null return, positive
delay (number), zero delay, NaN, and Infinity.

Fixes #140

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 6, 2026 00:41
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 runtime bug in the core orchestration executor retry flow where a custom async retry handler returning any value other than strict false (e.g., undefined, null, NaN, Infinity) was incorrectly treated as a “retry” signal, potentially causing infinite retries or invalid retry timers.

Changes:

  • Update tryHandleRetry to retry only when the handler returns true or a finite number.
  • Add unit tests validating no-retry behavior for undefined/null/NaN/Infinity and correct behavior for finite numeric delays (including 0).

Reviewed changes

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

File Description
packages/durabletask-js/src/worker/orchestration-executor.ts Tightens retry-handler result validation to prevent unintended retries and invalid timer creation.
packages/durabletask-js/test/orchestration_executor.spec.ts Adds coverage for invalid retry-handler returns and finite-delay retry behavior.

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.

[copilot-finds] Bug: Retry handler returning undefined/null/NaN/Infinity causes infinite retry loop or invalid timer

2 participants