Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,20 @@ def _replay_aware(
# - brand-new next op (no checkpoint): always flip to NEW.
# - non-terminal STEP-type op (brand-new or retrying): the user function
# is about to run real work, so flip to NEW before it.
if was_replaying and (not next_exists or (next_is_step and not next_terminal)):
# A virtual child never checkpoints itself, so its own checkpoint being
# absent says nothing: it is new only when its first inner operation
# has no history either.
brand_new: bool = not next_exists and not (
is_virtual
and operation_identifier is not None
and self.state.get_checkpoint_result(
OperationIdNamespace(
operation_identifier.operation_id
).create_id_for_step(1),
claim_end_hook=False,
).is_existent()
)
if was_replaying and (brand_new or (next_is_step and not next_terminal)):
self._set_replay_status_new()
try:
yield
Expand Down
42 changes: 42 additions & 0 deletions packages/aws-durable-execution-sdk-python/tests/context_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3303,6 +3303,48 @@ def on_operation_end(self, info):
assert child_body_calls == []


def test_virtual_child_keeps_replay_status_while_inner_history_exists():
"""A virtual child has no checkpoint of its own; its inner history keeps REPLAY."""
ctx = DurableContext(
state=_replay_state({}),
execution_context=ExecutionContext(durable_execution_arn="arn"),
replay_status=ReplayStatus.REPLAY,
)
container_id = ctx._peek_next_operation_id() # noqa: SLF001
probe = ctx.create_child_context(container_id, is_virtual=True)
inner_id = probe._create_step_id() # noqa: SLF001
ctx.state._operations[inner_id] = _wait_op( # noqa: SLF001
inner_id, OperationStatus.SUCCEEDED
)

seen: list[bool] = []
ctx.run_in_child_context(
lambda child: seen.append(child.is_replaying()),
name="virtual",
config=ChildConfig(is_virtual=True),
)

assert seen == [True]


def test_virtual_child_without_inner_history_starts_new():
"""A virtual child with no history for its first inner operation is new work."""
ctx = DurableContext(
state=_replay_state({}),
execution_context=ExecutionContext(durable_execution_arn="arn"),
replay_status=ReplayStatus.REPLAY,
)

seen: list[bool] = []
ctx.run_in_child_context(
lambda child: seen.append(child.is_replaying()),
name="virtual",
config=ChildConfig(is_virtual=True),
)

assert seen == [False]


def test_replay_aware_emits_update_hook_for_operation_updated_since_last_invocation():
"""Updated terminal operations emit operation_end, not replay start+end."""
captured: list[tuple[str, str, bool, OperationStatus]] = []
Expand Down