Skip to content

Commit 90cc9ac

Browse files
authored
docs(power): semantics Deep Dive example mismatched
* fix semantics * semantics fix
1 parent 2fe1b23 commit 90cc9ac

2 files changed

Lines changed: 21 additions & 16 deletions

File tree

aws-lambda-durable-functions-power/steering/advanced-patterns.md

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,28 +105,33 @@ def handler(event: dict, context: DurableContext) -> str:
105105
```typescript
106106
import { StepSemantics } from '@aws/durable-execution-sdk-js';
107107

108-
// AtMostOncePerRetry - For non-idempotent operations
109-
// Step executes at most once per retry attempt
110-
// If step fails partway through, it won't re-execute the same attempt
108+
// AtLeastOncePerRetry (DEFAULT) - For operations that can execute multiple times
109+
// Step may execute multiple times per retry attempt
110+
// Use when idempotency is handled externally
111111
await context.step(
112112
'update-database',
113113
async () => {
114114
// This is idempotent - safe to retry
115115
return await updateUserRecord(userId, data);
116116
},
117-
{ semantics: StepSemantics.AtMostOncePerRetry }
117+
{ semantics: StepSemantics.AtLeastOncePerRetry }
118118
);
119119

120-
// AtLeastOncePerRetry (DEFAULT) - For operations that can execute multiple times
121-
// Step may execute multiple times per retry attempt
122-
// Use when idempotency is handled externally
120+
// AtMostOncePerRetry - For non-idempotent operations
121+
// Step executes at most once per retry attempt
122+
// If step fails partway through, it won't re-execute the same attempt
123123
await context.step(
124-
'send-notification',
124+
'charge-payment',
125125
async () => {
126-
// External system handles deduplication
127-
return await sendEmail(email, message);
126+
// Non-idempotent - duplicates would double-charge the customer
127+
return await chargePayment(customerId, amount);
128128
},
129-
{ semantics: StepSemantics.AtLeastOncePerRetry }
129+
{
130+
semantics: StepSemantics.AtMostOncePerRetry,
131+
// Pair with shouldRetry: false to guarantee at-most-once overall,
132+
// since the default retry strategy still allows multiple retry attempts.
133+
retryStrategy: () => ({ shouldRetry: false }),
134+
}
130135
);
131136
```
132137

aws-lambda-durable-functions-power/steering/step-operations.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ retry_config = RetryStrategyConfig(
186186

187187
## Step Semantics
188188

189-
### AT_LEAST_ONCE (Default)
189+
### AtLeastOncePerRetry (default)
190190

191-
Step executes at least once, may execute multiple times on failure/retry.
191+
Step executes at least once on each retry attempt. If the step succeeds but the checkpoint fails (e.g. due to a sandbox crash), the step will re-execute on replay. Use for idempotent operations that can tolerate duplicate execution.
192192

193193
**TypeScript:**
194194

@@ -202,9 +202,9 @@ const result = await context.step(
202202
);
203203
```
204204

205-
### AT_MOST_ONCE
205+
### AtMostOncePerRetry
206206

207-
Step executes at most once, never retries. Use for non-idempotent operations.
207+
Step executes at most once per retry attempt. If a crash happens between the pre-step checkpoint and step completion, the step is skipped on replay rather than re-executed. The step can still run across multiple retry attempts. To guarantee at-most-once overall, pair with `retryStrategy: () => ({ shouldRetry: false })`.
208208

209209
**TypeScript:**
210210

@@ -360,4 +360,4 @@ except Exception as error:
360360
4. **Use appropriate retry strategies** based on operation type
361361
5. **Handle errors explicitly** - don't let them propagate unexpectedly
362362
6. **Use custom serialization** for complex types
363-
7. **Choose correct semantics** (AT_LEAST_ONCE vs AT_MOST_ONCE)
363+
7. **Choose correct semantics** (`AtLeastOncePerRetry` vs `AtMostOncePerRetry`)

0 commit comments

Comments
 (0)