diff --git a/packages/durabletask-js/src/testing/in-memory-backend.ts b/packages/durabletask-js/src/testing/in-memory-backend.ts index 66cb406..f693061 100644 --- a/packages/durabletask-js/src/testing/in-memory-backend.ts +++ b/packages/durabletask-js/src/testing/in-memory-backend.ts @@ -256,7 +256,7 @@ export class InMemoryOrchestrationBackend { ): void { const instance = this.instances.get(instanceId); if (!instance) { - throw new Error(`Orchestration instance '${instanceId}' not found`); + return; // Instance may have been purged or the backend reset } if (instance.completionToken !== completionToken) { diff --git a/packages/durabletask-js/test/in-memory-backend.spec.ts b/packages/durabletask-js/test/in-memory-backend.spec.ts index 81a82a8..2ee1028 100644 --- a/packages/durabletask-js/test/in-memory-backend.spec.ts +++ b/packages/durabletask-js/test/in-memory-backend.spec.ts @@ -473,6 +473,17 @@ describe("In-Memory Backend", () => { expect((backend as any).instanceTimers.has(id1)).toBe(false); }); + it("should silently ignore completeOrchestration for purged instances", () => { + // Verifies that completeOrchestration returns silently when the instance + // has been deleted (e.g., via purge or reset), consistent with how + // completeActivity handles missing instances. + + // Should not throw — instance simply doesn't exist + expect(() => { + backend.completeOrchestration("nonexistent-instance", 1, []); + }).not.toThrow(); + }); + it("should allow reusing instance IDs after reset", async () => { const orchestrator: TOrchestrator = async (_: OrchestrationContext, input: number) => { return input * 2;