Skip to content

[copilot-finds] Bug: handleSubOrchestrationCompleted calls resume() unconditionally without guard clause #166

@github-actions

Description

@github-actions

Problem

In packages/durabletask-js/src/worker/orchestration-executor.ts, the handleSubOrchestrationCompleted method calls ctx.resume() unconditionally (line 407), even when no matching pending task is found for the incoming sub-orchestration completion event.

This is inconsistent with the equivalent activity completion handler (handleCompletedTask, lines 689–715), which correctly returns early when no matching task is found and logs a warning via WorkerLogs.orchestrationUnexpectedEvent.

The handleSubOrchestrationFailed handler is correct because it delegates to handleFailedTask, which has the same guard clause. Only handleSubOrchestrationCompleted was implemented inline and missed this guard.

Root Cause

handleSubOrchestrationCompleted was implemented independently rather than delegating to the shared handleCompletedTask method. The inline implementation omitted the guard clause that prevents resume() from being called when no matching pending task exists.

Proposed Fix

Refactor handleSubOrchestrationCompleted to delegate to handleCompletedTask, matching the pattern used by:

  • handleSubOrchestrationFailedhandleFailedTask
  • handleTaskCompletedhandleCompletedTask

This adds:

  1. Guard clause returning early when no matching task is found
  2. Warning log for unexpected events (via WorkerLogs.orchestrationUnexpectedEvent)
  3. isEmpty normalization for empty results (consistent with activity handler)

Impact

Severity: Medium (latent bug, defense-in-depth)

  • If an orphaned sub-orchestration completion event arrives (e.g., duplicate, malformed taskScheduledId) and _previousTask happens to be complete from an unrelated event, the spurious resume() call could advance the generator incorrectly, potentially causing NonDeterminismError on subsequent events.
  • Missing warning log means orphaned sub-orchestration completion events go unnoticed, making debugging harder.
  • Inconsistent handling between activity and sub-orchestration completion events reduces code maintainability.

Metadata

Metadata

Assignees

No one assigned

    Labels

    copilot-findsFindings from daily automated code review agent

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions