Skip to content

feat: add linear retry strategy#468

Open
nanookclaw wants to merge 2 commits into
aws:mainfrom
nanookclaw:fix/linear-retry-strategy
Open

feat: add linear retry strategy#468
nanookclaw wants to merge 2 commits into
aws:mainfrom
nanookclaw:fix/linear-retry-strategy

Conversation

@nanookclaw

Copy link
Copy Markdown

Summary

Adds a linear retry strategy for Java SDK parity with the JavaScript SDK change referenced in #462.

The new RetryStrategies.linearBackoff(maxAttempts, initialDelay, increment) factory computes retry delays as initialDelay + increment * (attempt - 1), preserving the SDK's existing 1-based attempt and attempt >= maxAttempts stop behavior. It also adds RetryStrategies.Presets.LINEAR, which uses six total attempts with retry delays of 1s, 2s, 3s, 4s, and 5s.

Focused unit coverage checks the custom progression, preset progression, max-attempt stop behavior, and validation for invalid maxAttempts, null durations, and sub-second durations.

Closes #462

Verification

  • git diff --check
  • docker run --rm -v "$PWD":/workspace -w /workspace maven:3.9-eclipse-temurin-17 mvn spotless:apply
  • docker run --rm -v "$PWD":/workspace -w /workspace maven:3.9-eclipse-temurin-17 mvn -pl sdk test -Dtest=RetryStrategiesTest

@nanookclaw nanookclaw requested a review from a team June 19, 2026 03:12
* @param increment Amount to add to the delay after each retry attempt
* @return RetryStrategy implementing linear backoff
*/
public static RetryStrategy linearBackoff(int maxAttempts, Duration initialDelay, Duration increment) {

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.

This should be more consistent with exponentialBackoff and have a maxDelay and jitterStrategy

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.

Do we want a jitter for this strategy?

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.

Looks like reference JS implementation doesn't have it #513, but the python SDK just added an implementation with jitter #484.

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.

Nevermind, they're aligned now #652

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.

Yeah, basically the preset LINEAR may not need a jitter but the RetryStrategy factory linearBackoff should support customizable jitter

);

/** Linear retry strategy: 6 total attempts (1 initial + 5 retries) with 1s, 2s, 3s, 4s, and 5s delays. */
public static final RetryStrategy LINEAR = linearBackoff(6, Duration.ofSeconds(1), Duration.ofSeconds(1));

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.

This should match the format (with comments ) of the Default above.

@zhongkechen

Copy link
Copy Markdown
Contributor

e2e failed for credential issues:

Retry validateCredentials: attempt 1 of 12 failed: Credentials could not be loaded, please check your action inputs: Could not load credentials from any providers. Retrying after 35ms.

@nanookclaw

Copy link
Copy Markdown
Author

Thanks for the review. I pushed fb73e27 with the follow-up changes:

  • Added the configurable linearBackoff(maxAttempts, initialDelay, maxDelay, increment, jitter) overload.
  • Kept the existing 3-arg linearBackoff compatibility path deterministic/uncapped.
  • Updated Presets.LINEAR to call the capped overload with JitterStrategy.NONE and a 5s max delay.
  • Added tests for capping, jitter bounds, invalid maxDelay/jitter args, max-attempt boundary, maxDelay < initialDelay, and cap-before-overflow behavior.

Verification run locally via Docker Maven:

  • mvn -pl sdk test -Dtest=RetryStrategiesTest,RetryDecisionTest
  • mvn -pl sdk spotless:check
  • mvn -pl sdk test
  • git diff --check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

Add linear retry strategy with configurable increment

3 participants