Skip to content

Commit c0f22b6

Browse files
author
Alex Wang
committed
feat: Adding replay mode for child execution
- During child execution, if the result exceeded checkpoint api size limit, set replay mode to True - When replay, if replay mode is true, re-execute func instead of return the result from the payload
1 parent 0c61d98 commit c0f22b6

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

src/aws_durable_execution_sdk_python/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class CheckpointMode(Enum):
104104

105105

106106
@dataclass(frozen=True)
107-
class ChildConfig:
107+
class ChildConfig(Generic[T]):
108108
"""Options when running inside a child context."""
109109

110110
# checkpoint_mode: CheckpointMode = CheckpointMode.CHECKPOINT_AT_START_AND_FINISH

src/aws_durable_execution_sdk_python/operation/child.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def child_handler(
7979
raw_result: T = func()
8080
if checkpointed_result.is_replay_children():
8181
logger.debug(
82-
"ReplayChildren mode: Re-executing child context due to large payload: id: %s, name: %s",
82+
"ReplayChildren mode: Executed child context again on replay due to large payload. Exiting child context without creating another checkpoint. id: %s, name: %s",
8383
operation_identifier.operation_id,
8484
operation_identifier.name,
8585
)
@@ -90,22 +90,21 @@ def child_handler(
9090
operation_id=operation_identifier.operation_id,
9191
durable_execution_arn=state.durable_execution_arn,
9292
)
93-
payload_to_checkpoint = serialized_result
94-
replay_children = False
93+
replay_children: bool = False
9594
if len(serialized_result) > CHECKPOINT_SIZE_LIMIT:
9695
logger.debug(
9796
"Large payload detected, using ReplayChildren mode: id: %s, name: %s",
9897
operation_identifier.operation_id,
9998
operation_identifier.name,
10099
)
101100
replay_children = True
102-
payload_to_checkpoint = (
101+
serialized_result = (
103102
config.summary_generator(raw_result) if config.summary_generator else ""
104103
)
105104

106105
success_operation = OperationUpdate.create_context_succeed(
107106
identifier=operation_identifier,
108-
payload=payload_to_checkpoint,
107+
payload=serialized_result,
109108
sub_type=sub_type,
110109
context_options=ContextOptions(replay_children=replay_children),
111110
)

src/aws_durable_execution_sdk_python/state.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,7 @@ def is_replay_children(self) -> bool:
117117
op = self.operation
118118
if not op:
119119
return False
120-
context_details = op.context_details
121-
if not context_details:
122-
return False
123-
return context_details.replay_children
120+
return op.context_details.replay_children if op.context_details else False
124121

125122
def raise_callable_error(self) -> None:
126123
if self.error is None:

tests/operation/child_test.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def test_child_handler_not_started(
4242
mock_result.is_failed.return_value = False
4343
mock_result.is_started.return_value = False
4444
mock_result.is_replay_children.return_value = False
45+
mock_result.is_replay_children.return_value = False
4546
mock_state.get_checkpoint_result.return_value = mock_result
4647
mock_callable = Mock(return_value="fresh_result")
4748

@@ -374,7 +375,11 @@ def test_child_handler_large_payload_with_summary_generator():
374375
mock_state.get_checkpoint_result.return_value = mock_result
375376
large_result = "large" * 256 * 1024
376377
mock_callable = Mock(return_value=large_result)
377-
child_config: ChildConfig = ChildConfig(summary_generator=lambda x: "summary")
378+
379+
def my_summary(result: str) -> str:
380+
return "summary"
381+
382+
child_config: ChildConfig = ChildConfig[str](summary_generator=my_summary)
378383

379384
actual_result = child_handler(
380385
mock_callable,

0 commit comments

Comments
 (0)