Skip to content

Variance/jitter cannot be disabled for automatic retry/random exponential backoff #2026

Closed

Description

@RealErikHuebner

Bug description

When configuring automatic retry with random exponential backoff for genai.Client objects, disabling the variance/jitter of retry wait times is impossible using genai.types.HttpRetryOptions objects; setting the variance/jitter to 0.0 automatically defaults to 1.0 instead upon initialization of genai.Client objects.

The issue occurs in google/genai/_api_client.py in retry_args():

jitter=options.jitter or _RETRY_JITTER,

The falsy check returns False when 0.0 is passed. Since jitter is typed and validated as Float | None, this line should instead be:

jitter=options.jitter if options.jitter is not None else _RETRY_JITTER,

or:

jitter=_RETRY_JITTER if options.jitter is None else options.jitter,

Expected behaviour

Initializing a genai.Client object with the http_options.retry_options parameter set to:

genai.types.HttpRetryOptions(jitter = 0.0)

should return a genai.Client object that has no variance/jitter added to retry wait times.

Actual behaviour

Initializing a genai.Client object with the http_options.retry_options parameter set to:

genai.types.HttpRetryOptions(jitter = 0.0)

returns a genai.Client object that is initialized to add a random value between 0 seconds and 1 second to retry wait times.

Steps to reproduce

  1. Run the following code:
from google import genai

client = genai.Client(
    vertexai=True,
    project="foo",
    location="foo",
    http_options=genai.types.HttpOptions(
        api_version="v1",
        retry_options=genai.types.HttpRetryOptions(
            jitter=0.0,
        ),
    ),
)

print(client._api_client._retry.wait.jitter)

The above block will print:

1

Environment details

  • Programming language: Python
  • OS: Any

Activity

  1. added
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    priority: p2Moderately-important priority. Fix may not be included in next release.
    on Feb 4, 2026
  2. self-assigned this
    on Feb 5, 2026
  3. Venkaiahbabuneelam commented on Feb 9, 2026

    @Venkaiahbabuneelam

    Hi @RealErikHuebner,
    Thanks for reaching out us

    When you pass jitter = 0.0 condition treats as a false and assigning default value is 1.

    For now workaround you can try with below code:

    from google import genai

    client = genai.Client(
    vertexai=True,
    project="foo",
    location="foo",
    http_options=genai.types.HttpOptions(
    api_version="v1",
    retry_options=genai.types.HttpRetryOptions(
    jitter=0.0,
    ),
    ),
    )

    print(client._api_client._retry.wait.jitter)

    if hasattr(client._api_client._retry, 'wait'):
    client._api_client._retry.wait.jitter = 0.0

    print(f"Jitter is now: {client._api_client._retry.wait.jitter}")

    Thanks

  4. RealErikHuebner commented on Feb 14, 2026

    @RealErikHuebner
    Author

    Hi @Venkaiahbabuneelam

    Thank you for the response and the provided workaround; I've confirmed that it does indeed work.

    Are there any plans to include the changes I proposed above in a coming release? Since jitter is typed and validated as Float | None, this change should be safe, unless jitter = 0.0 being reset to default is intended behaviour?

  5. RealErikHuebner commented on Feb 14, 2026

    @RealErikHuebner
    Author

    Also would you be able to tell me what the corresponding workaround would be for genai.client.AsyncClient objects? i.e. when retrieving and using some_client.aio objects where some_client is of type genai.Client and has already been initialized?

  6. Venkaiahbabuneelam commented on Feb 17, 2026

    @Venkaiahbabuneelam

    Hi @RealErikHuebner,
    Thank you for your feedback. We appreciate you taking the time to share your thoughts with us, and we'll be filing a feature request.

  7. added 3 commits that reference this issue on Oct 20, 2026
    d41b8fc
    9c64ec7
    419dd89
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions