Skip to content

Conversation

@ParidelPooya
Copy link
Contributor

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

- Use ContextOptions.ReplayChildren instead of magic string marker
- Add summaryGenerator config for custom payload summaries
- Default to empty string for large payloads without summaryGenerator
- Update tests to match new ReplayChildren behavior
- Improve observability and maintainability of large payload handling
Copy link
Member

@yaythomas yaythomas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@ParidelPooya ParidelPooya merged commit 7e856ec into development Sep 3, 2025
1 check passed
@ParidelPooya ParidelPooya deleted the feat/replay-children-implementation branch September 3, 2025 22:25
ParidelPooya added a commit that referenced this pull request Oct 10, 2025
# 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>
ParidelPooya added a commit that referenced this pull request Oct 12, 2025
# 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>
ParidelPooya added a commit that referenced this pull request Oct 24, 2025
# 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>
ParidelPooya added a commit that referenced this pull request Oct 26, 2025
# 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>
ParidelPooya added a commit that referenced this pull request Nov 2, 2025
# 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>
ParidelPooya added a commit that referenced this pull request Nov 6, 2025
# 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>
ParidelPooya added a commit that referenced this pull request Nov 6, 2025
# 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>
ParidelPooya added a commit that referenced this pull request Nov 6, 2025
# 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>
ParidelPooya added a commit that referenced this pull request Nov 7, 2025
# 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants