Skip to content

docs(gax): document RetrySettings and ExponentialRetryAlgorithm contracts - #15335

Draft
lqiu96 wants to merge 2 commits into
googleapis:mainfrom
lqiu96:docs/gax-2a-retry-settings-behavior
Draft

lqiu96 wants to merge 2 commits into
googleapis:mainfrom
lqiu96:docs/gax-2a-retry-settings-behavior

Conversation

@lqiu96

@lqiu96 lqiu96 commented Dec 1, 2026

Copy link
Copy Markdown
Member

Updates RetrySettings and ExponentialRetryAlgorithm Javadocs in gax:

  • RetrySettings: fixes inaccurate failure-vs-timeout scaling and server-streaming timeout claims, clarifies maxAttempts total-attempt semantics (0, 1, and > 1), documents zero initialRpcTimeoutDuration and LRO per-poll RPC timeout behavior, and documents newBuilder(), setLogicalTimeout(), build(), and merge() contracts.
  • ExponentialRetryAlgorithm: documents initial attempt timeout capping, retry delay and RPC timeout scaling, and termination rules on the class, createNextAttempt(), and shouldRetry().

…acts

- Fix inaccurate RetrySettings class Javadoc claims on rpcTimeoutMultiplier and server-streaming timeouts.
- Clarify maxAttempts total-attempt semantics (0 vs 1 vs >1), zero initialRpcTimeoutDuration behavior, and Builder.merge/newBuilder defaults.
- Correct LRO polling RPC timeout claims and document ExponentialRetryAlgorithm scaling and termination rules.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request updates and refactors the Javadoc documentation in ExponentialRetryAlgorithm and RetrySettings to provide clearer, more accurate explanations of the retry logic, including the behavior of maximum attempts, RPC timeouts, and builder methods. The review feedback correctly identifies a discrepancy in the Javadoc for the merge method regarding how maxAttempts is handled during a merge, and suggests a correction to ensure the documentation matches the actual implementation.

Comment on lines +595 to +601
* Copies non-null duration fields, multipliers {@code >= 1.0}, {@code maxAttempts}, and {@code
* jittered} from {@code newSettings} onto this builder.
*
* <p>Because {@link RetrySettings#newBuilder()} initializes all durations to {@link
* java.time.Duration#ZERO}, multipliers to {@code 1.0}, and {@code maxAttempts} to {@code 0},
* merging a fresh builder resets unset fields to those defaults. Mutate {@link
* RetrySettings#toBuilder()} directly when changing a subset of fields.

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.

medium

The Javadoc states that merging a fresh builder resets unset fields to their defaults, including maxAttempts to 0. However, in the implementation of merge(RetrySettings.Builder), maxAttempts is only copied if it is non-zero (newSettings.getMaxAttempts() != 0). Since a fresh builder initializes maxAttempts to 0, merging it will not reset maxAttempts to 0 on the target builder. We should clarify this in the Javadoc.

     * Copies non-null duration fields, multipliers {@code >= 1.0}, non-zero {@code maxAttempts}, and
     * {@code jittered} from {@code newSettings} onto this builder.
     *
     * <p>Because {@link RetrySettings#newBuilder()} initializes all durations to {@link
     * java.time.Duration#ZERO}, multipliers to {@code 1.0}, and {@code jittered} to {@code true},
     * merging a fresh builder resets those fields to their defaults. However, since only non-zero
     * {@code maxAttempts} are merged, {@code maxAttempts} is not reset to {@code 0}. Mutate {@link
     * RetrySettings#toBuilder()} directly when changing a subset of fields.
References
  1. Update stale Javadoc comments to reflect new method behavior for improved clarity, rather than removing them.

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.

1 participant