Skip to content

[copilot-finds] Bug: InMemoryOrchestrationBackend.reset() does not clear orchestrationQueueSet #125

@github-actions

Description

@github-actions

Problem

InMemoryOrchestrationBackend.reset() clears the orchestrationQueue array but does not clear the orchestrationQueueSet (Set<string>). When reset() is called while orchestrations are still queued (not yet dequeued by getNextOrchestrationWorkItem), the Set retains stale instance IDs. Any subsequent createInstance() call with the same instance ID silently fails to enqueue the new orchestration because enqueueOrchestration() checks the Set and skips the insert.

File: packages/durabletask-js/src/testing/in-memory-backend.ts, line 384

Root Cause

The enqueueOrchestration() method uses orchestrationQueueSet.has(instanceId) as a deduplication guard. When reset() empties the queue array but leaves the Set intact, this guard incorrectly reports already-queued IDs as present, preventing new orchestrations from being enqueued.

Affected scenario: any test suite that calls backend.reset() between test cases and reuses instance IDs. The second test's orchestration would hang indefinitely because it is never enqueued for processing.

Fix

A fix with tests is available on branch copilot-finds/bug/fix-inmemory-backend-reset-orchestration-queue-set.

The fix adds this.orchestrationQueueSet.clear() to the reset() method, alongside the existing this.orchestrationQueue.length = 0.

Testing

Added a new test should allow reusing instance IDs after reset that:

  1. Creates an orchestration with a specific instance ID (enqueuing it)
  2. Calls reset() before the orchestration is dequeued
  3. Creates a new orchestration with the same instance ID
  4. Verifies the new orchestration completes successfully

Without the fix, this test times out. With the fix, it passes.

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