Skip to content

fix(sdk): keep replay status when a virtual child has inner history - #997

Closed
MaxonT wants to merge 1 commit into
aws:mainfrom
MaxonT:contrib/889-auto
Closed

MaxonT wants to merge 1 commit into
aws:mainfrom
MaxonT:contrib/889-auto

Conversation

@MaxonT

@MaxonT MaxonT commented Nov 27, 2026

Copy link
Copy Markdown

Hi there, this patch is for the virtual child context handling in the durable execution SDK, so replay no longer ends early and resumed operations still get their notifications; please check the replay case.

Issue #, if available

Fixes #889

Description of changes

When the context is replaying, DurableContext._replay_aware flips it to NEW before an operation whose own checkpoint does not exist. A virtual child never checkpoints itself (_run_in_child_context passes is_virtual, and the container is rejected if a checkpoint exists), so that rule always fires for it. The parent flips to NEW, create_child_context copies NEW into the child, and the child's existing inner operations then skip the replay and update hook gate. is_replaying() is wrong inside the child, plugins miss on_operation_end for an inner operation that completed during suspension, and the durable logger stops de-duplicating.

The change: for a virtual child, the "brand-new operation" flip applies only when the container has no checkpoint and the child's first inner operation (OperationIdNamespace(operation_id).create_id_for_step(1), the id create_child_context gives its first operation) has no checkpoint either. Nothing else in _replay_aware changes. Map and parallel virtual branches already keep REPLAY in ConcurrentExecutor; this brings run_in_child_context(..., is_virtual=True) in line with them.

Design

Not needed: no new option and no public API change.

  • Simpler options considered (rule 2): not flipping at all for a virtual child. That would leave a virtual child with no history at all stuck in REPLAY until its first operation, so its early logs would be de-duplicated. The extra lookup is one condition.
  • Root cause (rule 5): the existence check treats a missing container checkpoint as new work, but a virtual container has no checkpoint by design.
  • Net change: 13 source lines in context.py, no public API members.

Assumptions

  • The first inner operation of a virtual child always has logical step 1 in the child's namespace, as in create_child_context (prefix is the container operation id). Evidence: identifier.py and context.py in this diff's context; the new test builds the inner id through create_child_context(..., is_virtual=True) and not through the new code path, so it would fail if the two disagreed.
  • Behaviour of the real Lambda durable execution service: unverified, no deployed run was made.

Decisions not covered by the issue or the design note

  • The look-ahead is limited to the first inner operation. Reason: that operation decides whether the child body starts in replay; later operations are already handled by their own _replay_aware calls.
  • Known limit: a virtual child whose first inner operation is itself a virtual child has no checkpoint at that inner id, so the lookup finds nothing and the outer container still flips to NEW. I did not widen the change to cover it and added no test for it; it would need a recursive lookup.
  • No change to _set_replay_status_new or to the post-operation flip: the existing check against the parent's next operation still applies after the virtual child returns.

Tests

  • New test_virtual_child_keeps_replay_status_while_inner_history_exists: before the fix it fails with assert [False] == [True]; with the fix it passes.
  • New test_virtual_child_without_inner_history_starts_new: covers the branch that keeps the old behaviour. Mutation check: replacing the new lookup with False fails the first test, and forcing brand_new = False fails the second.
  • packages/aws-durable-execution-sdk-python/tests: 2283 passed, 2 failed (state_test.py::test_collect_batch_wakes_for_refresh_before_poll_interval and ::test_collect_batch_adds_refresh_that_comes_due_during_async_window, timing tests). I re-ran the first on the unchanged base commit and it fails there too; I did not compare the second against base separately. ruff check and ruff format pass on the two touched files.
  • Not run: the OTel, examples and conformance packages, hatch run types:check, and any run against a deployed function.

Checklist

  • Every new branch has a test that fails without it (rule 4)
  • For a bug fix: the first commit adds a test that fails on the current code (rule 5). Both tests are in one commit; the failing output before the fix is quoted above.
  • Every edited test expectation is listed in the description, with the reason (rule 5): none edited, two tests added.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@MaxonT
MaxonT deployed to ai-pr-review-runtime November 27, 2026 15:29 — with GitHub Actions Active
@yaythomas

Copy link
Copy Markdown
Contributor

Thank you for contributing this, @MaxonT!

PR #909: an earlier fix for the same issue already fixed a case that this change doesn't have. This PR's new condition keeps replay status for a virtual child that is the first operation in its context. When a replayed operation comes before the virtual child, context.py:632, the check that runs after each operation looks for a checkpoint at the virtual child's own id. A virtual child never has one, so the check switches the context to NEW before the virtual child starts. Inside a virtual child that follows a replayed step or another virtual child, is_replaying() therefore still returns False, and plugins get no on_operation_end for a wait inside it that finished while the execution was suspended.

The final commit of that PR fixes this by making _next_operation_exists() also check the next operation's first inner operation, and adds tests for both cases. That PR was closed before it merged. It will be faster to open a new PR with that approach than to rework this one, so I'm closing this PR in favor of the new one.

This branch was successfully deployed

1 active deployment
ai-pr-review-runtime — 62e67e0d Deployed Nov 27, 2026 by MaxonT via notify / Generate notification summary #511
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Virtual child contexts exit replay early and omit resumed operation notifications

2 participants