Skip to content

fix: Use strict undefined check for taskId in completion event handlers#157

Merged
YunchuWang merged 2 commits intomainfrom
copilot-finds/bug/fix-truthy-check-on-task-id
Mar 11, 2026
Merged

fix: Use strict undefined check for taskId in completion event handlers#157
YunchuWang merged 2 commits intomainfrom
copilot-finds/bug/fix-truthy-check-on-task-id

Conversation

@YunchuWang
Copy link
Member

Summary

Fixes #148

Bug: In orchestration-executor.ts, the handleCompletedTask and handleSubOrchestrationCompleted methods use truthy checks (if (taskId)) to guard task lookups. Since taskId is a number | undefined, this incorrectly treats taskId === 0 as "no taskId" because 0 is falsy in JavaScript. This is inconsistent with handleFailedTask and handleTimerFired in the same file, which correctly use if (taskId !== undefined).

Changes

  • packages/durabletask-js/src/worker/orchestration-executor.ts — Changed both truthy checks from if (taskId) to if (taskId !== undefined), matching the pattern used by handleFailedTask and handleTimerFired
  • packages/durabletask-js/test/orchestration_executor.spec.ts — Added tests verifying taskId 0 is handled correctly in completion event handlers

Testing

All tests pass. Lint clean.

The handleCompletedTask and handleSubOrchestrationCompleted methods used
truthy checks (`if (taskId)`) to guard task lookups. Since taskId is a
number, this incorrectly treats taskId 0 as 'no taskId' because 0 is
falsy in JavaScript. This is inconsistent with handleFailedTask and
handleTimerFired in the same file, which correctly use
`if (taskId === undefined)`.

Change both checks to `if (taskId !== undefined)` so that taskId 0 is
treated as a valid (though likely unmatched) identifier rather than
being silently skipped.

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

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 subtle correctness issue in the orchestration event handlers where a truthy check on taskId could incorrectly treat taskId === 0 as “missing,” potentially skipping task lookups and completions. This aligns completion handling with existing strict-undefined guards used elsewhere in the executor and addresses issue #148.

Changes:

  • Updated handleCompletedTask and handleSubOrchestrationCompleted to use taskId !== undefined instead of if (taskId).
  • Added tests intended to cover completion events where taskScheduledId is unmatched or equals 0.

Reviewed changes

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

File Description
packages/durabletask-js/src/worker/orchestration-executor.ts Uses a strict undefined check for taskId in completion handlers to avoid treating 0 as “no id”.
packages/durabletask-js/test/orchestration_executor.spec.ts Adds new test cases around completion events with unmatched IDs and taskScheduledId = 0.
Comments suppressed due to low confidence (1)

packages/durabletask-js/src/worker/orchestration-executor.ts:400

  • handleSubOrchestrationCompleted still silently ignores completion events when no matching pending task is found (or when the event has no taskScheduledId), whereas handleCompletedTask logs an unexpected event in that case. Consider adding the same WorkerLogs.orchestrationUnexpectedEvent(...) + early return here for consistency and easier troubleshooting (guarded by !ctx._isReplaying).
    if (taskId !== undefined) {
      subOrchTask = ctx._pendingTasks[taskId];
      delete ctx._pendingTasks[taskId];
    }

@YunchuWang YunchuWang merged commit 29455dd into main Mar 11, 2026
28 checks passed
@YunchuWang YunchuWang deleted the copilot-finds/bug/fix-truthy-check-on-task-id branch March 11, 2026 20:58
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: Truthy check on taskId in completion event handlers silently skips taskId 0

3 participants