Interactions retries ignore the documented `initial_delay` and `max_delay` defaults

未关闭 适合新手
#3,317 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@Sun-Wukhan 已经在做这个了。

开始于 2026年11月8日。

  • #3318 来自 @Sun-Wukhan —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
68/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
python

调研方向

阅读 types.py 中 HttpRetryOptions 默认值附近的内容,以及 _gaos/google_genai.py 中 _DEFAULT_INITIAL_INTERVAL_MS 附近的内容,然后将它们与 _api_client 中的重试默认值进行比较。Issue 报告称 client.interactions 和 client.models 的重试延迟和抖动不同;请判断 Interactions 是否应使用共享默认值,并使用提供的无网络复现方法验证重试计划。

由索引模型根据 Issue 内容生成。

描述

client.interactions backs off half as long as client.models when initial_delay and max_delay are left unset, so the same HttpRetryOptions give two different retry schedules in one client.

Repro at afb10e8 (3.0.0), with no network and no real key:

import time, httpx2
from google import genai
from google.genai import types

stamps = []
def handler(request):
    stamps.append(time.monotonic())
    return httpx2.Response(503, json={"error": {"code": 503, "message": "unavailable", "status": "UNAVAILABLE"}})

def gaps():
    return [round(b - a, 1) for a, b in zip(stamps, stamps[1:])]

retry = types.HttpRetryOptions(attempts=4, jitter=0)  # jitter=0 keeps the gaps exact; delays left unset
client = genai.Client(
    api_key="test",
    http_options=types.HttpOptions(
        retry_options=retry, httpx_client=httpx2.Client(transport=httpx2.MockTransport(handler))
    ),
)
for name, call in [
    ("models.generate_content", lambda: client.models.generate_content(model="gemini-3.8-flash", contents="hi")),
    ("interactions.create", lambda: client.interactions.create(model="gemini-3.8-flash", input="hi")),
]:
    stamps.clear()
    try:
        call()
    except Exception as e:
        print(f"{name}: {len(stamps)} requests, gaps {gaps()} s, {type(e).__name__}")
$ python repro.py
models.generate_content: 4 requests, gaps [1.0, 2.0, 4.0] s, ServerError
interactions.create: 4 requests, gaps [0.5, 1.0, 2.0] s, InternalServerError

HttpRetryOptions documents initial_delay as "If not specified, default to 1.0 second" and max_delay as "default to 60.0 seconds" (types.py:2671-2678). The comment above _DEFAULT_INITIAL_INTERVAL_MS in _gaos/google_genai.py calls 0.5 s and 8 s the default, so one of the two contracts is wrong. An unset jitter differs too: Interactions takes up to 25% off each delay, while client.models adds up to 1 s. #3263 already moved the unset attempts onto _api_client._RETRY_ATTEMPTS. I checked the sync client only.

I'd take all three from _api_client (_RETRY_INITIAL_DELAY, _RETRY_MAX_DELAY, _RETRY_JITTER) in the same way. Or are 0.5 s and 8 s meant to stay specific to Interactions?

主要语言
Python
星标
4.1k
派生
1.1k
平均合并
1 天 20 小时
30 天内合并 PR
99

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

googleapis/python-genai 的其他 Issue

查看 googleapis/python-genai 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。