Skip to content

[copilot-finds] Bug: processNewEventsForTracing only indexes pastEvents, silently dropping tracing spans for same-batch completions #229

@github-actions

Description

@github-actions

Problem

processNewEventsForTracing() in packages/durabletask-js/src/tracing/trace-helper.ts (line 464–478) builds its scheduling-event lookup maps only from pastEvents, not from newEvents. When a task is scheduled and completes within the same event batch (both events arrive as new events), the corresponding tracing span is silently missing.

This affects:

  • Activities: TaskScheduled + TaskCompleted/TaskFailed in the same batch
  • Sub-orchestrations: SubOrchestrationInstanceCreated + SubOrchestrationInstanceCompleted/SubOrchestrationInstanceFailed in the same batch
  • Timers: TimerCreated + TimerFired in the same batch

Root Cause

The lookup maps (taskScheduledEvents, subOrchCreatedEvents, timerCreatedEvents) are populated exclusively from pastEvents:

for (const event of pastEvents) {
    // ... populates maps
}

When a scheduling event appears in newEvents instead of pastEvents, it is never indexed. The subsequent completion event in newEvents looks up the scheduling event by ID and gets undefined, causing the span to be silently skipped.

Proposed Fix

Also iterate over newEvents when building the lookup maps, so scheduling events from both past and new event batches are indexed.

Impact

  • Severity: Medium — affects tracing/observability correctness, not data or execution correctness
  • Scenarios affected: Fast-completing activities, sub-orchestrations, or zero-delay timers where both the scheduling and completion events are delivered in the same event batch
  • Symptoms: Missing spans in distributed traces, making debugging of quick-executing tasks harder

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