Curated history keeps half a user turn when the model turn is invalid
维护者通常 1 天内回复
@Venkaiahbabuneelam 已经在做这个了。
开始于 2026年10月5日。
评估
调研方向
从 chats.py 中的 _extract_curated_history 开始,具体来说是从第 107-108 行的单个 curated_history.pop() 开始,它通过第 136 行的 chats.create(history=...) 到达。阅读 google/genai/tests/chats/test_get_history.py,尤其是 test_history_with_consecutive_valid_user_inputs(第 152 行)和 test_history_with_invalid_turns(第 401 行),它们界定了预期行为。用 issue 中展示的 multi-content 用户轮次加上空 model 轮次来复现。完成意味着无效的 model 轮次会丢弃整个前面的 user run,而不是一个 content,并且 get-history 套件通过。
由索引模型根据 Issue 内容生成。
描述
Title: _extract_curated_history drops only the last user content when a model turn is invalid
An invalid model turn makes _extract_curated_history call curated_history.pop() once (chats.py:107-108). A user turn of two or more Content objects went in one at a time, so one pop removes part of it. The rest stays in the curated history with no model answer behind it.
The way in is chats.create(history=...), the only caller of that function (chats.py:136): a caller persisting raw exchanges stores one content per function response, and a blocked model turn as an empty content.
At 618f0aa, through the public constructor:
$ /var/tmp/p9bL16/genai/.venv/bin/python probe_hist2.py
import: /var/tmp/p9bL16/genai/google/genai/__init__.py
curated: [('user', 1)]
comprehensive: [('user', 1), ('user', 1), ('model', 0)]
hist = [
C(role="user", parts=[P(text="what is the weather")]),
C(role="user", parts=[P.from_function_response(name="get_weather", response={"c": 21})]),
C(role="model", parts=[]), # invalid model turn
]
chat = client.chats.create(model="gemini-2.0-flash", history=hist)
The question survives and the tool result behind it disappears, so the next send_message sends a user turn the model already failed on, minus its evidence.
$ python -m pytest google/genai/tests/chats/test_get_history.py -q
17 passed, 1 warning in 0.06s
# not run: the replay suites, which need recorded sessions
Two of those tests bracket the gap. test_history_with_consecutive_valid_user_inputs (test_get_history.py:152) makes back-to-back user contents supported input, and test_history_with_invalid_turns (:401) sets the intent that the whole rejected user turn goes. One pop meets that intent only where the turn is a single content.
There is no CODEOWNERS here and every merge on GitHub is the Copybara import, so @jaycee-li, I am going by your last commit on this file. Should the pop walk back over the whole user run? I can write the diff out here if that helps the internal fix.
- 主要语言
- Python
- 星标
- 4k
- 派生
- 1k
- 平均合并
- 1 天 17 小时
- 30 天内合并 PR
- 54
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
googleapis/python-genai 的其他 Issue
-
[Bug]: Unsubscripted typing.List and typing.Dict crash convert_if_exist_pydantic_model in AFC可能已有人在做 @chauvuusvn 于 4 天前认领。 未关闭priority: p2 type: bug
难度 2/5 1-3 小时 新手友好度 82/100
googleapis/python-genai#3044 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Name collision in google.genai.interactions: triggers.Interaction shadows response model Interaction in static type checkers可能已有人在做 @Venkaiahbabuneelam 于 9 天前认领。 未关闭priority: p2 type: bug
难度 2/5 1-3 小时 新手友好度 78/100
googleapis/python-genai#3013 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Callable tools: optional scalar parameters (`int | None`) get `"type": "object"` in `parameters_json_schema`, so Gemini sends `{}`可能已有人在做 @Venkaiahbabuneelam 于 1 天前认领。 未关闭priority: p2 type: bug
googleapis/python-genai#3060 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Gemini API latency has recently increased significantly, especially with store=true可能已有人在做 @Venkaiahbabuneelam 于 1 天前认领。 未关闭priority: p3 status:awaiting user response type: question
googleapis/python-genai#3059 · 2 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
live.connect() (Vertex AI) resolves ADC and refreshes the OAuth token synchronously on the event loop on every connect可能已有人在做 @Venkaiahbabuneelam 于 1 天前认领。 未关闭priority: p2 type: bug
难度 3/5 1-2 天 新手友好度 74/100
googleapis/python-genai#3056 · 2 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
查看 googleapis/python-genai 的全部 Issue
相似的 Issue
-
area/install reliability
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 83/100
FluidNumerics/fluid-walk-blocker#191 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
TransformerLensOrg/TransformerLens#1868 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 85/100
climate-analytics-lab/jax-gcm#1057 ·
维护者通常 1 天内回复