Commit 2d39ddc
feat: replace ADAPTIVE_EMPTY_RESULT with ReplayChildren flag (#5)
# ReplayChildren Implementation for Run-in-Child-Context Handler
This change replaces the previous `ADAPTIVE_EMPTY_RESULT` marker
approach with `ReplayChildren` flag mechanism for handling large
payloads in child context operations.
## Key Changes
### 1. **ChildConfig Interface Enhancement**
- Added `summaryGenerator?: (result: T) => string` option
- summaryGenerator Will be used internall to create a summary for
ctx.map and ctx.parallel when result is big
- **Note**: `summaryGenerator` receives the **raw result** (before
serialization)
### 2. **Checkpoint Behavior Update**
- **Before**: Used magic string `"__LARGE_PAYLOAD__"` as payload marker
- **After**: Uses `ContextOptions: { ReplayChildren: true }` flag with
empty string payload (or custom summary)
### 3. **Replay Detection Logic**
- **Before**: `if (result === ADAPTIVE_EMPTY_RESULT)`
- **After**: `if (stepData?.ContextDetails?.ReplayChildren)`
### 4. **Data Flow Details**
- **Size Check**: Uses **serialized result** (after
`serdes.serialize()`) to determine if payload > 256KB
- **summaryGenerator**: Receives **raw result** (before serialization)
for flexible summary creation
## Workflow Diagram
```
┌─────────────────────────────────────────────────────────────────────────────┐
│ Child Context Execution Flow │
└─────────────────────────────────────────────────────────────────────────────┘
┌─────────────────┐
│ Execute Child │
│ Context │
└─────────┬───────┘
│
┌─────────▼───────┐
│ Raw Result (T) │
│ │
└─────────┬───────┘
│
┌─────────▼───────┐
│ Apply Serdes │
│ Serialization │
│ result → string │
└─────────┬───────┘
│
┌─────────▼───────┐
│ Check Serialized│
│ Payload Size │
│ > 256KB? │
└─────┬───────┬───┘
│ │
NO │ │ YES
│ │
┌───────────────▼─┐ ┌─▼──────────────────┐
│ Normal │ │ Large Payload │
│ Checkpoint │ │ Handling │
│ │ │ │
│ Payload: │ │ ReplayChildren: │
│ serialized data │ │ true │
│ ReplayChildren: │ │ │
│ undefined │ │ │
└───────────────┬─┘ └─┬──────────────────┘
│ │
│ ┌───▼──────────────────┐
│ │ summaryGenerator │
│ │ provided? │
│ │ (gets RAW result) │
│ └───┬──────────┬───────┘
│ │ │
│ YES │ │ NO
│ │ │
│ ┌───▼────┐ ┌───▼────┐
│ │Custom │ │Empty │
│ │Summary │ │String │
│ │from │ │"" │
│ │raw data│ │ │
│ └───┬────┘ └───┬────┘
│ │ │
└───────┼──────────┘
│
┌─────────────▼─────────────┐
│ Checkpoint Saved │
└─────────────┬─────────────┘
│
┌─────────────▼─────────────┐
│ On Replay... │
└─────────────┬─────────────┘
│
┌─────────────▼─────────────┐
│ Check ReplayChildren │
│ flag in ContextDetails │
└─────┬───────────┬─────────┘
│ │
FALSE│ │TRUE
│ │
┌───────────────▼─┐ ┌─────▼──────────────┐
│ Return Cached │ │ Re-execute Child │
│ Result from │ │ Context Function │
│ Checkpoint │ │ (Reconstruct │
│ (deserialize) │ │ Full Result) │
└─────────────────┘ └────────────────────┘
```
## Data Flow Summary
1. **Execute** child context function → Raw result `T`
2. **Serialize** result using serdes → `string`
3. **Check size** of serialized string
4. **If large**: Call `summaryGenerator(rawResult)` → custom summary
5. **Checkpoint** with ReplayChildren flag and summary/empty payload
6. **On replay**: Check ReplayChildren flag to decide re-execution
### Checklist
- [Y] I have filled out every section of the PR template
- [Y] I have thoroughly tested this change
### Testing
#### Unit Tests
Yes
Co-authored-by: Pooya Paridel <parpooya@amazon.com>1 parent 1dfb9be commit 2d39ddc
File tree
4 files changed
+86
-16
lines changed- lambda-durable-functions-sdk-js/src
- handlers/run-in-child-context-handler
- types
4 files changed
+86
-16
lines changedLines changed: 57 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
202 | 202 | | |
203 | 203 | | |
204 | 204 | | |
| 205 | + | |
205 | 206 | | |
206 | 207 | | |
207 | 208 | | |
208 | | - | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
209 | 213 | | |
210 | 214 | | |
211 | 215 | | |
| |||
807 | 811 | | |
808 | 812 | | |
809 | 813 | | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
810 | 866 | | |
Lines changed: 18 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | 27 | | |
31 | 28 | | |
32 | 29 | | |
| |||
91 | 88 | | |
92 | 89 | | |
93 | 90 | | |
94 | | - | |
| 91 | + | |
| 92 | + | |
95 | 93 | | |
96 | | - | |
97 | | - | |
| 94 | + | |
| 95 | + | |
98 | 96 | | |
99 | 97 | | |
100 | 98 | | |
101 | | - | |
| 99 | + | |
102 | 100 | | |
103 | 101 | | |
104 | 102 | | |
| |||
182 | 180 | | |
183 | 181 | | |
184 | 182 | | |
| 183 | + | |
| 184 | + | |
185 | 185 | | |
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
189 | 198 | | |
190 | 199 | | |
191 | 200 | | |
192 | | - | |
| 201 | + | |
193 | 202 | | |
194 | 203 | | |
195 | 204 | | |
196 | 205 | | |
197 | 206 | | |
198 | 207 | | |
199 | 208 | | |
200 | | - | |
201 | 209 | | |
202 | 210 | | |
203 | 211 | | |
| |||
208 | 216 | | |
209 | 217 | | |
210 | 218 | | |
| 219 | + | |
211 | 220 | | |
212 | 221 | | |
213 | 222 | | |
| |||
Lines changed: 8 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
298 | 298 | | |
299 | 299 | | |
300 | 300 | | |
301 | | - | |
302 | | - | |
303 | | - | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
304 | 305 | | |
305 | 306 | | |
306 | | - | |
| 307 | + | |
307 | 308 | | |
308 | 309 | | |
309 | 310 | | |
310 | | - | |
| 311 | + | |
311 | 312 | | |
312 | 313 | | |
313 | 314 | | |
314 | 315 | | |
315 | 316 | | |
316 | | - | |
| 317 | + | |
| 318 | + | |
317 | 319 | | |
318 | 320 | | |
319 | 321 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
187 | 187 | | |
188 | 188 | | |
189 | 189 | | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
190 | 193 | | |
191 | 194 | | |
192 | 195 | | |
| |||
0 commit comments