Skip to content

feat(sdk): add experimental pause from a retry decision - #938

Open
ParidelPooya wants to merge 1 commit into
mainfrom
feat/pause-on-retry
Open

ParidelPooya wants to merge 1 commit into
mainfrom
feat/pause-on-retry

Conversation

@ParidelPooya

Copy link
Copy Markdown
Contributor

Closes #897

What

A retry decision can ask the SDK to pause the execution after a failed step attempt. The step saves its RETRY checkpoint, calls PauseDurableExecution, and ends the invocation as PENDING. After ResumeDurableExecution, the step runs its next attempt. This matches the JavaScript, Python, Go and Rust SDKs.

ctx.step("charge-payment", Result.class, stepCtx -> charge(),
        StepConfig.builder()
                .retryStrategy(RetryStrategies.exponentialBackoff(
                        20, Duration.ofSeconds(30), Duration.ofSeconds(300), 2.0, JitterStrategy.HALF, 5))
                .build());

Why (design note)

  1. Problem. A Java step can only retry or fail. Customers want a failed step to pause the execution, fix the cause, and resume from the saved retry instead of starting a new execution.
  2. Cause. RetryDecision has only shouldRetry and delay, and DurableExecutionClient has no pause call.
  3. Options considered.
    • A separate pause strategy next to RetryStrategy. It duplicates the retry decision and lets the two disagree.
    • Reusing the local runner's manual pause. The deployed SDK still could not pause.
    • An optional pause flag on the existing retry decision, plus pauseEvery overloads of the existing strategy factories. This adds no second decision path.
  4. Chosen option. The pause flag on RetryDecision. It is the smallest change and the same shape as the other SDKs.
  5. Removes. Nothing. Existing signatures stay.

Behavior

  • Order: RETRY checkpoint, PauseDurableExecution, then the invocation ends as PENDING.
  • RetryDecision.retry(delay, pause) and shouldPause() are new. pauseEvery overloads exist on exponentialBackoff, both linearBackoff forms and fixedDelay. They pause on attempts pauseEvery, 2 * pauseEvery, and so on, and keep the configured delay and jitter. A pauseEvery of 0 or less never pauses.
  • DurableExecutionClient.pauseExecution is a default method that throws UnsupportedOperationException. A custom client that does not override it keeps today's behavior: a warning, then a normal retry.
  • If the pause call fails, the SDK logs a warning and the step retries as usual.
  • The ClientToken is the SHA-256 hex of pause:<execution ARN>:<step operation id>:<attempt>.
  • An AT_MOST_ONCE attempt interrupted by an earlier invocation does not pause. Only a failure thrown by the step function in this invocation can pause.
  • The local in-memory client uses its existing paused state, so LocalDurableTestRunner.runUntilComplete() returns PENDING and resumeExecution() continues.
  • All new public APIs are marked experimental.
  • Docs: docs/core/steps.md covers behavior, permissions (lambda:PauseDurableExecution, and kms:Decrypt with a customer managed key) and the local runner.

Decisions the issue did not cover

  • pauseExecution is a default method on DurableExecutionClient, so existing custom clients still compile.
  • The pause reason is Step "<name or id>" failed attempt <n>.
  • withRetry ignores pause, as in the other SDKs. The submitter step of waitForCallback pauses, because it runs as a step with its stepConfig.
  • The pause ends the invocation at once. A step still running in another parallel or map branch stops, and after the resume an at-least-once step runs again. This is documented and covered by an integration test.
  • The SDK suspends the invocation directly after the pause call. It does not wait for a token-less checkpoint answer.
  • ObservedClient in lmi-tests delegates pauseExecution and traces it.
  • No input validation for pauseEvery, as for the other retry options.
  • No conformance test is added, per CONTRIBUTING.md. A conformance test for pause on retry may be worth adding in the conformance repository.

Tests

  • RetryDecisionTest, RetryStrategiesTest: the flag, every pauseEvery overload, jitter kept, non-positive values.
  • StepOperationPauseTest: RETRY checkpoint, then pause, then suspension (in order), pause failure falls back to retry, no pause without the flag, no pause for an interrupted AT_MOST_ONCE replay, unnamed step label, token stable and unique per execution, step and attempt.
  • LambdaDurableFunctionsClientTest, LocalMemoryExecutionClientTest, ObservedClientTest: the client side.
  • PauseOnRetryIntegrationTest (local runner): pause, resume and continue with an explicit pause decision and with pauseEvery, plus a pause in one parallel branch while a sibling runs.
  • No existing test expectation was edited.
  • Local result: 2446 tests pass across sdk, sdk-testing, sdk-integration-tests and lmi-tests. spotless:check is clean.

Unverified

  • Behavior against the real service. The tests use the local in-memory client and a mocked Lambda client. The request fields and permissions follow the pause and resume documentation, and the token format follows the other SDKs. No deployed function was paused.

Review rounds

Each round used a new independent reviewer that saw only the diff, the issue and the repository rules.

  1. Round 1 found that a pause stops sibling work in other branches, and that tests were missing for linearBackoff with jitter and for token uniqueness. The behavior is now documented and tested, and both tests were added.
  2. Round 2 found that ObservedClient did not delegate pauseExecution, a dead condition in withPauseEvery, missing @apiNote markers, and tests for an unnamed step and for the sibling behavior. All fixed.
  3. Round 3 found that no test fixed the RETRY, pause, suspend order, and that the docs example never ended. Both fixed. A suggestion to drop the SHA-256 try/catch was rejected, because the checked exception must be handled and the 64-character token matches the other SDKs.
  4. Round 4 found that the docs did not say withRetry ignores pause. Fixed.
  5. Round 5 found nothing.

A retry decision can now ask the SDK to pause the execution after a failed
step attempt. The step saves its RETRY checkpoint, calls
PauseDurableExecution, and ends the invocation as PENDING. After
ResumeDurableExecution, the step runs its next attempt.

- RetryDecision.retry(delay, pause) and shouldPause().
- pauseEvery overloads on the exponential, linear and fixed-delay retry
  strategies. They keep the configured delay and jitter.
- DurableExecutionClient.pauseExecution, a default method that throws
  UnsupportedOperationException. The Lambda client calls
  PauseDurableExecution with a SHA-256 ClientToken of the execution ARN, the
  step id and the attempt. A failed or unsupported pause logs a warning and
  the step retries as usual.
- The local in-memory client pauses the local execution, so the local test
  runner pauses and resumes.
- An AT_MOST_ONCE attempt interrupted by an earlier invocation does not pause.
- Docs for permissions, behavior and the local test runner.

All new public APIs are marked experimental.
@ParidelPooya
ParidelPooya requested a review from a team December 3, 2026 00:45

This branch has not been deployed

No deployments
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.

Pause the execution from a retry decision

1 participant