-
Notifications
You must be signed in to change notification settings - Fork 10
Description
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:
handleSubOrchestrationFailed→handleFailedTaskhandleTaskCompleted→handleCompletedTask
This adds:
- Guard clause returning early when no matching task is found
- Warning log for unexpected events (via
WorkerLogs.orchestrationUnexpectedEvent) isEmptynormalization 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_previousTaskhappens to be complete from an unrelated event, the spuriousresume()call could advance the generator incorrectly, potentially causingNonDeterminismErroron 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.