Skip to content

[copilot-finds] Bug: V2 entity execution includes all operationInfos on framework error due to falsy zero #224

@github-actions

Description

@github-actions

Problem

In _executeEntityInternal() (packages/durabletask-js/src/worker/task-hub-grpc-worker.ts, line 972), the operationInfos slicing logic uses resultsCount || operationInfos.length:

const infosToInclude = operationInfos.slice(0, resultsCount || operationInfos.length);

When a framework-level exception occurs during V2 entity batch execution (e.g., entity factory throws), the resulting EntityBatchResult has zero individual results. Because 0 is falsy in JavaScript, 0 || operationInfos.length evaluates to operationInfos.length, causing all operationInfos to be included in the response even though there are no corresponding results.

The comment above the line explicitly states: "Take only as many operationInfos as there are results" — but the code violates this intent when resultsCount === 0.

Root Cause

Classic JavaScript truthiness bug: 0 || fallback evaluates to fallback because 0 is falsy. This means the "zero results" case is conflated with the "undefined/null" case.

Proposed Fix

Replace resultsCount || operationInfos.length with resultsCount directly. Since resultsCount comes from .length, it is always a number (never null/undefined), so no fallback is needed.

Impact

Severity: Low-to-medium. Affects the V2 entity execution path when a framework-level exception occurs (entity factory throws, entity constructor fails, etc.). The sidecar receives incorrect operationInfos alongside the batch failure details.

Affected scenarios:

  • V2 entity batch execution with framework-level errors (not per-operation errors)
  • The DTS backend, which uses operationInfos for response routing, may receive misleading data

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