Skip to content

feat(sdk): add experimental on_pause hook to steps - #1008

Merged
ParidelPooya merged 7 commits into
mainfrom
feat/step-on-pause
Dec 4, 2026
Merged

ParidelPooya merged 7 commits into
mainfrom
feat/step-on-pause

Conversation

@ParidelPooya

Copy link
Copy Markdown
Contributor

Issue #, if available

None.

Description of changes

A step can pause the execution on a failed attempt (RetryDecision.pause, pause_every). After the pause, the invocation ends. So no later step and no code after the step can run, and a developer cannot act on the pause from code. EventBridge PAUSED events carry no step name or reason, so they cannot target one step.

This PR adds an experimental on_pause option:

  • StepConfig.on_pause: a sync callable (StepPauseInfo) -> None. The SDK calls it after it paused the execution.
  • StepPauseInfo: durable_execution_arn, step_id, step_name (None for an unnamed step), attempt (the failed attempt) and error (the error of that attempt).
  • WaitForCallbackConfig.on_pause: passed to the submitter step, because the submitter step can pause through retry_strategy.
  • Both options and StepPauseInfo are marked "Experimental; may change or be removed in a future release.", like pause.

Behavior:

  1. The SDK calls on_pause only after the PauseDurableExecution call succeeded, and before the invocation ends. The SDK waits for it.
  2. The SDK does not call it when the attempt does not pause, when the pause call fails, when the client cannot pause, or when should_retry is False.
  3. If on_pause raises, the SDK logs a warning through the context logger, and the invocation ends with the execution paused. The error does not fail the step.
  4. on_pause is not checkpointed and does not run on replay. So it runs at most once per pause. Its work can be lost if the invocation crashes or times out during the call.
  5. Its time counts toward the function timeout.
  6. The SDK does not validate the option.

Docs: the StepConfig docstring and the README say the hook runs at most once, point to the EventBridge Durable Execution Status Change event with status PAUSED as a backup signal, and say the execution role needs permission for what the hook calls (for example sqs:SendMessage).

Example: step_with_on_pause sends the execution ARN to an SQS queue from on_pause. Its resume_handler is a sample queue consumer that calls ResumeDurableExecution. The catalog entry has integration: false, like step_with_pause_every, because the example needs a queue that the user creates.

Tests:

  • tests/operation/step_on_pause_test.py: the hook gets the right info after a pause, and runs after the pause call. It does not run when the pause fails, when the client cannot pause, without a pause, when should_retry is False, or on replay (pending retry and succeeded step). A raising hook is logged and the execution stays paused (named and unnamed step). A pause without a hook logs no warning. wait_for_callback passes the hook to the submitter step.
  • test/step/test_step_with_on_pause.py: the local test runner pauses the execution and calls the hook once with the execution ARN. Attempt 2 does not run until the test resumes the execution. The testing package needed no change, because its client already supports pause.

Review rounds (independent reviewer, given only the spec and the diff):

  1. The README example never paused (default max_attempts=3 with pause_every=5), and the warning of an unnamed step had no test. Both fixed.
  2. The on_pause is not None check had no test that fails without it. Fixed with a test. The example now says the user creates the queue and sets PAUSED_QUEUE_URL.
  3. The docs did not say that a resume from a fast consumer can cancel the pause. Fixed in the docstring, the README and the example, plus the SQS permissions of the consumer.
  4. The round-3 text said the status is always PAUSING during the hook. The Lambda docs say it can still be RUNNING. The text now says a resume while the invocation runs can cancel the pause or fail with ResourceConflictException. The sample consumer now handles one message per batch.
  5. The example test resumed while the paused invocation still ran. The test now checks that the execution stays paused before it resumes. A probe that resumes early makes the test fail.
  6. No findings.

Design

See Rules for every change.

  • Design note (rule 3): the cross-SDK spec for the step onPause hook (owner: the maintainer who asked for this change). Its problem, behavior rules and tests are the "Description of changes" above.
  • Simpler options considered (rule 2):
    • No hook, use the EventBridge PAUSED event: the event carries no step name or reason, so it cannot target one step.
    • Code after the step: it never runs, because the invocation ends after the pause.
    • Code in the step function before it raises: the step does not know yet whether the retry strategy pauses or whether the pause call succeeds.
  • Root cause (rule 5): not a bug fix.
  • Net change: +34 lines in operation/step.py, +1 line in operation/callback.py, +54 lines in config.py (mostly docstrings). Public API: +1 class (StepPauseInfo), +2 fields (StepConfig.on_pause, WaitForCallbackConfig.on_pause).

Assumptions

  • A ResumeDurableExecution call while the paused invocation still runs can cancel the pause or return ResourceConflictException. Evidence: Pausing and resuming durable executions.
  • The hook works on Lambda as in the local runner. Unverified: no cloud run, because the example needs a queue.

Decisions not covered by the issue or the design note

  • StepPauseInfo lives in config.py next to StepConfig, and the root package does not export it, like StepConfig.
  • on_pause is keyword-only on both configs, so the positional order of the existing fields does not change.
  • The warning message names the step by name, or by operation id when the step has no name, like the existing pause-failure warning.
  • The hook catches Exception, not BaseException, like the pause-failure path.
  • The README example shows only the producer side. The example file also has the sample consumer.

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) (not a bug fix)
  • Every edited test expectation is listed in the description, with the reason (rule 5) (no existing test was edited)

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

A step can pause the execution on a failed attempt, and the invocation
then ends. So no code can act on the pause. StepConfig.on_pause runs
after the PauseDurableExecution call succeeded and before the
invocation ends. It gets a StepPauseInfo with the execution ARN, the
step id and name, the failed attempt and its error.
WaitForCallbackConfig.on_pause passes the hook to the submitter step.

An error from the hook is logged and the execution stays paused. The
hook is not checkpointed and does not run on replay.

Add an example that sends the execution ARN to an SQS queue.
The README example used the default max_attempts of 3 with
pause_every=5, so it never paused. Add a test for the warning of an
unnamed step whose on_pause raises.
Add a test that a pause without on_pause logs no warning. Say in the
example that the queue and PAUSED_QUEUE_URL are set up by the user.
on_pause runs while the status is PAUSING, and a resume in that status
cancels the pause. Say so in the API docs, the README and the example,
and list the SQS permissions of the sample consumer.
The status can still be RUNNING when on_pause runs, so a resume can
also fail with ResourceConflictException. The sample consumer now
handles one message per batch.
Wait for the paused invocation to end and check that attempt 2 does not
run before the resume.
@ParidelPooya ParidelPooya reopened this Dec 2, 2026
@ParidelPooya
ParidelPooya deployed to ai-pr-review-runtime December 2, 2026 19:51 — with GitHub Actions Active
@ParidelPooya
ParidelPooya deployed to ai-pr-review-runtime December 2, 2026 19:52 — with GitHub Actions Active
@github-actions

This comment has been minimized.

A fixed 0.3 s sleep could resume while the first invocation was still
running. The test now waits for InvocationCompleted before it checks
that the execution stays paused.
@ParidelPooya
ParidelPooya deployed to ai-pr-review-runtime December 2, 2026 20:23 — with GitHub Actions Active
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Codex AI review

One previously reported approach finding remains at packages/aws-durable-execution-sdk-python/src/aws_durable_execution_sdk_python/config.py:638. The earlier test-timing finding is resolved. Static review only; tests were not executed, and cloud behavior remains unverified.

Suppressed repeats

  • arf_v1_y5iid33irkwbjwhoh6pryzdrjw — deferred (maintainer verdict)

Reviewed commit 58aead433358b8571c7fbeca16002d5b8d3d012d. Workflow run

@yaythomas yaythomas left a comment

Copy link
Copy Markdown
Contributor

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 e3f8699 into main Dec 4, 2026
59 checks passed
@ParidelPooya
ParidelPooya deleted the feat/step-on-pause branch December 4, 2026 19:11

This branch was successfully deployed

1 active deployment
ai-pr-review-runtime — 58aead43 Deployed Dec 2, 2026 by ParidelPooya via ai-pr-review / Codex review / Generate Codex review #3584
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