-
Notifications
You must be signed in to change notification settings - Fork 9
Description
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:
- Creates an orchestration with a specific instance ID (enqueuing it)
- Calls
reset()before the orchestration is dequeued - Creates a new orchestration with the same instance ID
- Verifies the new orchestration completes successfully
Without the fix, this test times out. With the fix, it passes.