Skip to content

Commit b28bdc9

Browse files
committed
fix wait for condition attempt count
1 parent c69d777 commit b28bdc9

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

packages/aws-durable-execution-sdk-js/src/handlers/wait-for-condition-handler/wait-for-condition-handler.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ describe("WaitForCondition Handler", () => {
366366
const config: WaitForConditionConfig<string> = {
367367
waitStrategy: (state, attempt) => {
368368
expect(state).toBe("ready");
369-
expect(attempt).toBe(2); // Should use attempt from system
369+
expect(attempt).toBe(3); // Should increment attempt count
370370
return { shouldContinue: false };
371371
},
372372
initialState: "initial",
@@ -395,7 +395,7 @@ describe("WaitForCondition Handler", () => {
395395
const config: WaitForConditionConfig<string> = {
396396
waitStrategy: (state, attempt) => {
397397
expect(state).toBe("ready");
398-
expect(attempt).toBe(2); // Should use attempt from system
398+
expect(attempt).toBe(3); // Should increment attempt count
399399
return { shouldContinue: false };
400400
},
401401
initialState: "initial",
@@ -424,7 +424,7 @@ describe("WaitForCondition Handler", () => {
424424
const config: WaitForConditionConfig<string> = {
425425
waitStrategy: (state, attempt) => {
426426
expect(state).toBe("ready");
427-
expect(attempt).toBe(2); // Should still use system attempt number
427+
expect(attempt).toBe(3); // increment on next wait retry
428428
return { shouldContinue: false };
429429
},
430430
initialState: "initial",
@@ -453,7 +453,7 @@ describe("WaitForCondition Handler", () => {
453453
const config: WaitForConditionConfig<string> = {
454454
waitStrategy: (state, attempt) => {
455455
expect(state).toBe("ready");
456-
expect(attempt).toBe(3); // Should use system attempt number
456+
expect(attempt).toBe(4); // increment on next wait retry
457457
return { shouldContinue: false };
458458
},
459459
initialState: "initial",
@@ -652,7 +652,7 @@ describe("WaitForCondition Handler", () => {
652652
"step-1",
653653
"parent-123", // parentId from handler setup
654654
expect.any(Function), // The wrapped check function
655-
2, // currentAttempt (1) + 1 = 2
655+
1, // currentAttempt = 1 (initial attempt only)
656656
DurableExecutionMode.ExecutionMode,
657657
);
658658
});
@@ -707,7 +707,7 @@ describe("WaitForCondition Handler", () => {
707707
"step-1",
708708
"parent-123", // parentId should be passed through
709709
expect.any(Function),
710-
2, // currentAttempt (1) + 1 = 2
710+
1, // currentAttempt = 1 (initial attempt only)
711711
DurableExecutionMode.ExecutionMode,
712712
);
713713
});

packages/aws-durable-execution-sdk-js/src/handlers/wait-for-condition-handler/wait-for-condition-handler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ export const executeWaitForCondition = async <T, Logger extends DurableLogger>(
307307
}
308308

309309
// Get the current attempt number (1-based for wait strategy consistency)
310-
const currentAttempt = existingOperation?.StepDetails?.Attempt || 1;
310+
const currentAttempt = (existingOperation?.StepDetails?.Attempt ?? 0) + 1;
311311

312312
// Checkpoint START for observability (fire and forget) - only if not already started
313313
const stepData = context.getStepData(stepId);
@@ -336,7 +336,7 @@ export const executeWaitForCondition = async <T, Logger extends DurableLogger>(
336336
stepId,
337337
parentId,
338338
() => check(currentState, waitForConditionContext),
339-
currentAttempt + 1,
339+
currentAttempt,
340340
DurableExecutionMode.ExecutionMode,
341341
);
342342
} finally {

0 commit comments

Comments
 (0)