Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở Phù hợp với người mới
#3,051 1 bình luận 0 reaction 1 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@Venkaiahbabuneelam đang làm issue này rồi.

Từ ngày 5/10/2026.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
62/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
api

Hướng nghiên cứu

Bắt đầu tại _extract_curated_history trong chats.py, cụ thể là lệnh curated_history.pop() duy nhất ở dòng 107-108, được truy cập thông qua chats.create(history=...) ở dòng 136. Đọc google/genai/tests/chats/test_get_history.py, đặc biệt là test_history_with_consecutive_valid_user_inputs (dòng 152) và test_history_with_invalid_turns (dòng 401), những test này bao quanh hành vi dự kiến. Tái hiện với lượt người dùng multi-content cộng với lượt model trống được hiển thị trong issue. Hoàn thành nghĩa là một lượt model không hợp lệ loại bỏ toàn bộ user run phía trước, không phải một content, và get-history suite vượt qua.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Python
Star
4k
Fork
1k
Merge trung bình
1 ngày 17 giờ
Pull request đã merge (30 ngày)
54

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của googleapis/python-genai

Tất cả issue của googleapis/python-genai

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.