Skip to content

[copilot-finds] Bug: getMethodNameForAction() missing SENDEVENT, SENDENTITYMESSAGE, and TERMINATEORCHESTRATION cases, crashing non-determinism error handler #233

@github-actions

Description

@github-actions

Problem

getMethodNameForAction() in packages/durabletask-js/src/worker/index.ts (line 36-55) only handles 4 of the 7 valid OrchestratorAction types: SCHEDULETASK, CREATETIMER, CREATESUBORCHESTRATION, and COMPLETEORCHESTRATION.

The three missing cases are:

  • SENDEVENT (produced by context.sendEvent())
  • SENDENTITYMESSAGE (produced by context.callEntity(), context.signalEntity(), context.lockEntities())
  • TERMINATEORCHESTRATION

Root Cause

When orchestration code is changed between runs (a non-determinism scenario), the orchestration executor calls getWrongActionTypeError() which in turn calls getMethodNameForAction() to produce a descriptive NonDeterminismError message. If the mismatched action is a SENDEVENT, SENDENTITYMESSAGE, or TERMINATEORCHESTRATION type, getMethodNameForAction() falls through to the default case and throws a generic Error("Unknown action type: N") instead of returning the method name.

This means the user sees an unhelpful "Unknown action type: 5" crash instead of the intended diagnostic message like "A previous execution called callActivity with ID=1, but the current execution is instead trying to call sendEvent...".

Scenario

  1. Version 1 of an orchestrator calls context.callActivity("myActivity") at sequence ID 1
  2. An instance starts running and completes the activity
  3. Code is updated: version 2 calls context.sendEvent("instance", "event") at sequence ID 1
  4. On replay, history has TaskScheduled at ID=1, but _pendingActions[1] is now a SENDEVENT action
  5. handleTaskScheduled() detects the mismatch and calls getWrongActionTypeError(1, "callActivity", sendEventAction)
  6. getMethodNameForAction(sendEventAction) throws Error("Unknown action type: 5") instead of returning "sendEvent"

The same pattern applies to entity orchestrations that use callEntity/signalEntity/lockEntities.

Proposed Fix

Add the three missing cases to the switch statement in getMethodNameForAction().

Impact

Severity: Medium — Affects error diagnostics for non-determinism in orchestrations using entities or sendEvent. Users get an unhelpful crash error instead of the proper NonDeterminismError that explains the history mismatch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    copilot-findsFindings from daily automated code review agent

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions