Repository navigation
feat(sdk): add AT_LEAST_ONCE_ASYNC and default_step_semantics - #996
Merged
Merged
Conversation
An AT_LEAST_ONCE_ASYNC step queues its SUCCEED checkpoint and returns at once. RETRY and FAIL are still awaited. The batcher now sends the checkpoints still queued when it is told to stop. So the SUCCEED is saved before the invocation returns. A batch that fails without the handler seeing it fails the invocation instead of reporting SUCCEEDED.
AT_MOST_ONCE and AT_LEAST_ONCE are the new names. They keep the old values, so nothing on the wire changes. AT_MOST_ONCE_PER_RETRY and AT_LEAST_ONCE_PER_RETRY stay as deprecated aliases of the same members. Code, tests, examples and docs use the new names.
durable_execution takes default_step_semantics. It sets the semantics of every step whose StepConfig sets none, in every context of the execution. A step's own step_semantics wins. The default stays AT_LEAST_ONCE. StepConfig.step_semantics now defaults to None, which means the execution default.
The microvm and agentcore session ID steps feed a client token or a runtime session to later steps. They now set AT_LEAST_ONCE themselves, so default_step_semantics=AT_LEAST_ONCE_ASYNC cannot make them async. They use the deprecated AT_LEAST_ONCE_PER_RETRY name, so the core requirement stays >=3.0.0.
An AT_LEAST_ONCE_ASYNC step can return, and the handler can then raise before the step's SUCCEED is sent. If that checkpoint then failed, the invocation answered FAILED for the handler error, so the execution ended without the step's result. After the batcher stops, an invocation-scope checkpoint failure now raises, so Lambda retries the invocation. An execution-scope failure, such as a validation error, still answers FAILED. A handler error keeps its own FAILED answer then.
The handler sets default_step_semantics=AT_LEAST_ONCE_ASYNC. The step that makes the idempotency key sets AT_LEAST_ONCE itself. A wait ends the first invocation, so the second invocation replays the saved steps.
The StepSemantics docstring, the StepConfig docstring, the README and the example say AT_LEAST_ONCE_ASYNC is experimental, as the pause option does. default_step_semantics, AT_LEAST_ONCE and AT_MOST_ONCE are not experimental.
A handler can suspend while an AT_LEAST_ONCE_ASYNC SUCCEED is still queued, for example on a replayed wait. close() sends it, and when that call failed the invocation still answered PENDING. A permanent failure then let each later invocation rerun the step, and a retryable one waited for the timer. The late-failure check now covers PENDING too, except when the token was withdrawn. Both cases now match AT_LEAST_ONCE: FAILED, or a raised CheckpointError that Lambda retries.
This comment has been minimized.
This comment has been minimized.
_apply_late_checkpoint_failure only receives SUCCEEDED, FAILED or PENDING output from invoke_handler. So the status filter at its top never returns early, and this change removes it.
This comment has been minimized.
This comment has been minimized.
StepConfig.step_semantics keeps its type StepSemantics and its default AT_LEAST_ONCE, as on main. So StepConfig().step_semantics.value works. StepConfig records privately whether the caller set the field. So DurableContext.step applies default_step_semantics only to a step that did not set it, and an explicit AT_LEAST_ONCE wins. The flag is an init field, so dataclasses.replace keeps it.
Add a test for the overflow part of the batcher's stop condition. An async SUCCEED that does not fit next to a START goes to the overflow queue. Stop is signaled while the START is in flight, so only the overflow queue has work. The test runs the real batch loop in a thread and checks that the SUCCEED is sent before the thread stops.
This comment has been minimized.
This comment has been minimized.
dataclasses.replace cannot tell an explicit AT_LEAST_ONCE from the default. Tell users to build StepConfig with step_semantics set to pin AT_LEAST_ONCE under an async execution default.
Declaring AT_MOST_ONCE and AT_LEAST_ONCE first made them the canonical members. That changed .name of the PerRetry members and the order of list(StepSemantics). Declare the PerRetry members first, as on main, and make the new names aliases with the same values. Add a test for .name, identity, and iteration order.
The checkpoint thread sets the revoked flag or the failed flag, then leaves its loop. So both are never set, and the early return for a revoked token could not change the answer.
This comment has been minimized.
This comment has been minimized.
dataclasses.replace passes the stored step_semantics to the copy, so an explicit AT_LEAST_ONCE looked unset and an async execution default replaced it. The set flag is no longer an init field: __post_init__ sets it from the value it gets, so every replaced config counts as set. A replaced config can then only lose the execution default, never turn async when the caller pinned AT_LEAST_ONCE.
This comment has been minimized.
This comment has been minimized.
yaythomas
requested changes
Nov 27, 2026
The session ID pin tests read StepConfig.step_semantics. StepConfig stores AT_LEAST_ONCE for both a set and an unset field, and the tests ran under the default semantics. So they passed without the pin. The tests now run the session under default_step_semantics set to AT_LEAST_ONCE_ASYNC. They delay the answer to the session ID's SUCCEED checkpoint. The AgentCore test checks that the session handler starts only after the answer. The MicroVM test checks that the launch has not run before the answer. Each test fails when its pin is removed.
This comment has been minimized.
This comment has been minimized.
Sizing an update for a checkpoint batch can raise, for example when PassThroughSerDes leaves bytes in the payload. This ran outside the batcher's failure handling. So the error was not observed, waiters were not woken, and an unsaved AT_LEAST_ONCE_ASYNC SUCCEED could still answer SUCCEEDED. Move the failure handling into _fail_checkpointing and call it for both a failed API call and a failed batch collection. The operation that failed to size is failed with the rest of the batch.
Contributor
Codex AI reviewNo actionable findings in the current diff. Tests were not executed under the read-only review constraints. The PR’s documented service-retry assumption remains unverified. Reviewed commit |
yaythomas
approved these changes
Nov 27, 2026
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #, if available
Ports aws-durable-execution-sdk-js#1296 to Python.
Description of changes
What
StepSemantics.AT_LEAST_ONCE_ASYNC, marked experimental like the pause option. The step queues its SUCCEED checkpoint and returns at once.AT_LEAST_ONCEstill waits for the SUCCEED checkpoint. So the new mode has lower latency.AT_LEAST_ONCE. RETRY and FAIL are still awaited.on_invocation_end.Why it keeps at-least-once
durable_executionstops the batcher and waits for it. So the SUCCEED is sent before the invocation returns SUCCEEDED, FAILED or PENDING.Trade-off
Renames
AT_MOST_ONCEandAT_LEAST_ONCEare the new names. They keep the old values, so nothing on the wire changes.AT_MOST_ONCE_PER_RETRYandAT_LEAST_ONCE_PER_RETRYstay the canonical members, declared first as onmain.AT_MOST_ONCEandAT_LEAST_ONCEare enum aliases of them.StepSemantics.AT_LEAST_ONCE_PER_RETRY is StepSemantics.AT_LEAST_ONCEis true, so existing code keeps working..name,reprandlist(StepSemantics)report the old names, as onmain.@deprecatedor a warning without a custom metaclass. So the deprecation is a comment and a docstring note.AGENTS.mdasks to coordinate changes there. They still work through the aliases.Default step semantics
durable_executiontakesdefault_step_semantics. It sets the semantics of every step whoseStepConfigdoes not setstep_semantics, in every context of the execution: child contexts,mapitems,parallelbranches, and steps that extensions create.step_semanticswins. The default staysAT_LEAST_ONCE.StepConfig.step_semanticskeeps its type and itsAT_LEAST_ONCEdefault.StepConfigrecords privately whether the caller set the field, andDurableContext.stepapplies the execution default only when it is not set.Options considered for how a step takes the default
step_semanticsdefaults toNoneStepConfig().step_semantics.valueand code typed asStepSemantics.StepConfigis passedStepConfig(retry_strategy=...)would skip the execution default, which is surprising.dataclasses.replacecounts as set, so it can only lose the default, never turn async.Extensions
AT_LEAST_ONCE_PER_RETRYthemselves. The microvm ID becomes the launch's client token, and the agentcore ID becomes the runtime session. Sodefault_step_semantics=AT_LEAST_ONCE_ASYNCcannot launch a second MicroVM on replay.>=3.0.0.Differences from the JavaScript change
create_checkpointraisesOrphanedChildExceptionfor an orphaned operation in both modes (state.py,_reject_if_parent_done), so the async step does not return, and the branch unwinds. So that fix does not apply.maporparallelitem keeps running new async steps. In Python, an abandoned branch is rejected only for operations it started before the parent completed, in both modes. So this mode does not change that behavior, and the docs do not add the note.Example
step_semantics_async_defaultsetsdefault_step_semantics=AT_LEAST_ONCE_ASYNC. Its order ID step setsAT_LEAST_ONCEitself, because the ID is the idempotency key of the charge. A wait ends the first invocation, so the second invocation replays the saved steps.Tests
tests/operation/step_at_least_once_async_test.pyruns handlers throughdurable_executionwith a slow fake client and the real batcher thread. It checks that:AT_LEAST_ONCEstill waits;CheckpointError;on_invocation_end;default_step_semanticsreaches the root, a child context and map items, and a step's own semantics wins.tests/e2e/default_step_semantics_int_test.pyruns an async-default handler with a wait on the local test runner. Every step is SUCCEEDED in the history, and each step ran once.context_test.pychecks howDurableContext.stepresolves the semantics.config_test.pychecks that the new names are the same members, that.nameandlist(StepSemantics)matchmainplusAT_LEAST_ONCE_ASYNC, and thatStepConfig().step_semanticsisAT_LEAST_ONCE.context_test.pyalso checks that an explicitAT_LEAST_ONCEwins over an async execution default, and that A config made withdataclasses.replacecounts the field as set, so it keeps its value and does not take the execution default.state_test.pychecks that an async SUCCEED left only in the overflow queue at stop is sent before the batcher thread stops.DurableContext.stepfails 4 tests. Removing the extension pins fails both extension tests. Removing the overflow check from the stop condition fails the overflow test. Each change to the set-flag logic inStepConfigfails 1 to 7 tests.test_create_raises_when_boto3_cannot_build_the_client, also fails onmainon the same machine. Type checks andhatch fmt --checkpass for every package.Design
ExecutionState.close()to flush the queue. It waits forever in a state whose batcher thread is not running, as in many unit tests, and it costs an API call.close(). Existing tests patchclosewith a one-argument function.durable_executionkeyword.Assumptions
Migration
StepConfig.step_semanticskeeps its type and default. The execution default applies when the step does not set it.Decisions not covered by the issue or the design note
durable_execution, because it is the only execution-level setting point.test_step_config_defaultsuses the new nameAT_LEAST_ONCE.test_collect_checkpoint_batch_shutdown_pathandtest_stop_settles_pending_refresh_and_sends_queued_itemsnow expect queued checkpoints to be sent at stop.test_step_with_name_and_configpasses an explicit semantics, because a config without one is now copied with the default. Thestep_semantics_at_most_onceexample returns the new name.Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Review notes
AT_LEAST_ONCE: FAILED for a permanent failure, a raisedCheckpointErrorfor a retryable one. A withdrawn token still answers PENDING.on_invocation_end..nameandlist(StepSemantics)keep the old names, andlist(StepSemantics)addsAT_LEAST_ONCE_ASYNCat the end. The new names are the same members, and lookup by the old name or value still works.StepConfig.step_semanticskeeps its defaultAT_LEAST_ONCE. An explicit value, alsoAT_LEAST_ONCE, wins over the execution default.