fix: Use strict undefined check for taskId in completion event handlers#157
Merged
YunchuWang merged 2 commits intomainfrom Mar 11, 2026
Merged
Conversation
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>
Contributor
There was a problem hiding this comment.
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
handleCompletedTaskandhandleSubOrchestrationCompletedto usetaskId !== undefinedinstead ofif (taskId). - Added tests intended to cover completion events where
taskScheduledIdis unmatched or equals0.
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
handleSubOrchestrationCompletedstill silently ignores completion events when no matching pending task is found (or when the event has no taskScheduledId), whereashandleCompletedTasklogs an unexpected event in that case. Consider adding the sameWorkerLogs.orchestrationUnexpectedEvent(...)+ early return here for consistency and easier troubleshooting (guarded by!ctx._isReplaying).
if (taskId !== undefined) {
subOrchTask = ctx._pendingTasks[taskId];
delete ctx._pendingTasks[taskId];
}
… the regression fix
kaibocai
approved these changes
Mar 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #148
Bug: In
orchestration-executor.ts, thehandleCompletedTaskandhandleSubOrchestrationCompletedmethods use truthy checks (if (taskId)) to guard task lookups. SincetaskIdis anumber | undefined, this incorrectly treatstaskId === 0as "no taskId" because0is falsy in JavaScript. This is inconsistent withhandleFailedTaskandhandleTimerFiredin the same file, which correctly useif (taskId !== undefined).Changes
packages/durabletask-js/src/worker/orchestration-executor.ts— Changed both truthy checks fromif (taskId)toif (taskId !== undefined), matching the pattern used byhandleFailedTaskandhandleTimerFiredpackages/durabletask-js/test/orchestration_executor.spec.ts— Added tests verifying taskId 0 is handled correctly in completion event handlersTesting
All tests pass. Lint clean.