From e1dde0440390349cddf6379ed87e3193e1772c3b Mon Sep 17 00:00:00 2001 From: Pooya Paridel Date: Fri, 5 Dec 2025 16:53:32 -0800 Subject: [PATCH 1/2] fix(sdk): remove 3-second timeout from checkpoint queue completion --- .../utils/checkpoint/checkpoint-manager.ts | 16 +----- .../checkpoint-queue-completion.test.ts | 52 ------------------- ...durable-execution-queue-completion.test.ts | 31 ----------- 3 files changed, 1 insertion(+), 98 deletions(-) diff --git a/packages/aws-durable-execution-sdk-js/src/utils/checkpoint/checkpoint-manager.ts b/packages/aws-durable-execution-sdk-js/src/utils/checkpoint/checkpoint-manager.ts index 70db7b00..dd79cd53 100644 --- a/packages/aws-durable-execution-sdk-js/src/utils/checkpoint/checkpoint-manager.ts +++ b/packages/aws-durable-execution-sdk-js/src/utils/checkpoint/checkpoint-manager.ts @@ -41,7 +41,6 @@ export class CheckpointManager implements Checkpoint { reject: (error: Error) => void; }> = []; private queueCompletionResolver: (() => void) | null = null; - private queueCompletionTimeout: NodeJS.Timeout | null = null; private readonly MAX_PAYLOAD_SIZE = 750 * 1024; // 750KB in bytes private isTerminating = false; private static textEncoder = new TextEncoder(); @@ -152,17 +151,8 @@ export class CheckpointManager implements Checkpoint { return; } - return new Promise((resolve, reject) => { + return new Promise((resolve) => { this.queueCompletionResolver = resolve; - - // Set a timeout to prevent infinite waiting - this.queueCompletionTimeout = setTimeout(() => { - this.queueCompletionResolver = null; - this.queueCompletionTimeout = null; - // Clear the queue since it's taking too long - this.clearQueue(); - reject(new Error("Timeout waiting for checkpoint queue completion")); - }, 3000); // 3 second timeout }); } @@ -393,10 +383,6 @@ export class CheckpointManager implements Checkpoint { private notifyQueueCompletion(): void { if (this.queueCompletionResolver) { - if (this.queueCompletionTimeout) { - clearTimeout(this.queueCompletionTimeout); - this.queueCompletionTimeout = null; - } this.queueCompletionResolver(); this.queueCompletionResolver = null; } diff --git a/packages/aws-durable-execution-sdk-js/src/utils/checkpoint/checkpoint-queue-completion.test.ts b/packages/aws-durable-execution-sdk-js/src/utils/checkpoint/checkpoint-queue-completion.test.ts index 9b19c1b3..7384bede 100644 --- a/packages/aws-durable-execution-sdk-js/src/utils/checkpoint/checkpoint-queue-completion.test.ts +++ b/packages/aws-durable-execution-sdk-js/src/utils/checkpoint/checkpoint-queue-completion.test.ts @@ -67,58 +67,6 @@ describe("CheckpointManager Queue Completion", () => { await expect(waits).resolves.toEqual([undefined, undefined, undefined]); }); - - it("should timeout after 3 seconds if queue doesn't complete", async () => { - jest.useFakeTimers(); - - const mockCheckpoint = jest.fn().mockImplementation( - () => new Promise(() => {}), // Never resolves - ); - (checkpointManager as any).storage = { checkpoint: mockCheckpoint }; - - // Add item to queue - checkpointManager.checkpoint("test-step", {}); - - const waitPromise = checkpointManager.waitForQueueCompletion(); - - // Fast-forward time by 3 seconds - jest.advanceTimersByTime(3000); - - await expect(waitPromise).rejects.toThrow( - "Timeout waiting for checkpoint queue completion", - ); - - jest.useRealTimers(); - }); - - it("should clear queue on timeout", async () => { - jest.useFakeTimers(); - - const mockCheckpoint = jest.fn().mockImplementation( - () => new Promise(() => {}), // Never resolves - ); - (checkpointManager as any).storage = { checkpoint: mockCheckpoint }; - - // Add items to queue - checkpointManager.checkpoint("test-step-1", {}); - checkpointManager.checkpoint("test-step-2", {}); - - expect((checkpointManager as any).queue.length).toBe(2); - - const waitPromise = checkpointManager.waitForQueueCompletion(); - - // Fast-forward time by 3 seconds - jest.advanceTimersByTime(3000); - - await expect(waitPromise).rejects.toThrow( - "Timeout waiting for checkpoint queue completion", - ); - - // Queue should be cleared - expect((checkpointManager as any).queue.length).toBe(0); - - jest.useRealTimers(); - }); }); describe("clearQueue", () => { diff --git a/packages/aws-durable-execution-sdk-js/src/with-durable-execution-queue-completion.test.ts b/packages/aws-durable-execution-sdk-js/src/with-durable-execution-queue-completion.test.ts index dee4b8c3..4903c34d 100644 --- a/packages/aws-durable-execution-sdk-js/src/with-durable-execution-queue-completion.test.ts +++ b/packages/aws-durable-execution-sdk-js/src/with-durable-execution-queue-completion.test.ts @@ -104,37 +104,6 @@ describe("withDurableExecution Queue Completion", () => { waitSpy.mockRestore(); }); - it("should handle waitForQueueCompletion timeout gracefully", async () => { - // Mock waitForQueueCompletion to reject with timeout error after 3 seconds - const waitSpy = jest - .spyOn(CheckpointManager.prototype, "waitForQueueCompletion") - .mockImplementation( - () => - new Promise((_, reject) => - setTimeout( - () => - reject( - new Error("Timeout waiting for checkpoint queue completion"), - ), - 3000, - ), - ), - ); - - const mockHandler = jest.fn().mockResolvedValue("success"); - const wrappedHandler = withDurableExecution(mockHandler); - - const startTime = Date.now(); - await wrappedHandler(mockEvent, mockContext); - const endTime = Date.now(); - - // Should complete within timeout period (3 seconds + buffer for test overhead) - expect(endTime - startTime).toBeLessThan(7000); - expect(waitSpy).toHaveBeenCalled(); - - waitSpy.mockRestore(); - }, 10000); - it("should handle waitForQueueCompletion errors gracefully", async () => { const waitSpy = jest .spyOn(CheckpointManager.prototype, "waitForQueueCompletion") From 3163bfd9892f1e3e0af6a3c30c22fca7bc4e128b Mon Sep 17 00:00:00 2001 From: Pooya Paridel Date: Fri, 5 Dec 2025 18:41:30 -0800 Subject: [PATCH 2/2] fix(examples): uncomment checkpoint size limit test assertions - Uncommented assertEventSignatures call that was disabled due to timeout issue - Uncommented proper operation count verification with status filter - Test now works correctly with timeout removal from issue #365 --- ...run-in-child-context-checkpoint-size-limit.test.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/aws-durable-execution-sdk-js-examples/src/examples/run-in-child-context/checkpoint-size-limit/run-in-child-context-checkpoint-size-limit.test.ts b/packages/aws-durable-execution-sdk-js-examples/src/examples/run-in-child-context/checkpoint-size-limit/run-in-child-context-checkpoint-size-limit.test.ts index 8f858469..c0b5c1b4 100644 --- a/packages/aws-durable-execution-sdk-js-examples/src/examples/run-in-child-context/checkpoint-size-limit/run-in-child-context-checkpoint-size-limit.test.ts +++ b/packages/aws-durable-execution-sdk-js-examples/src/examples/run-in-child-context/checkpoint-size-limit/run-in-child-context-checkpoint-size-limit.test.ts @@ -20,15 +20,12 @@ createTests({ // Verify totalIterations matches actual operations created expect(result.totalIterations).toBe( - // TODO: https://github.com/aws/aws-durable-execution-sdk-js/issues/365 - // execution.getOperations({ - // status: "SUCCEEDED", - // }).length, - execution.getOperations().length, + execution.getOperations({ + status: "SUCCEEDED", + }).length, ); - // TODO: https://github.com/aws/aws-durable-execution-sdk-js/issues/365 - // assertEventSignatures(execution.getHistoryEvents(), historyEvents); + assertEventSignatures(execution.getHistoryEvents(), historyEvents); }, 120000); }, });