Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Curated history keeps half a user turn when the model turn is invalid

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

维护者通常 1 天内回复

@Venkaiahbabuneelam 已经在做这个了。

开始于 2026年10月5日。

评估

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

调研方向

从 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 内容生成。

描述

priority: p2 status:awaiting user response type: bug

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 模板
  • 阅读贡献指南

从这里开始

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

googleapis/python-genai 的其他 Issue

查看 googleapis/python-genai 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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