Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta Adatta ai principianti
#3,051 1 commento 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
62/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
api

Direzione di ricerca

Inizia da _extract_curated_history in chats.py, in particolare dal singolo curated_history.pop() alle righe 107-108, raggiunto tramite chats.create(history=...) alla riga 136. Leggi google/genai/tests/chats/test_get_history.py, specialmente test_history_with_consecutive_valid_user_inputs (riga 152) e test_history_with_invalid_turns (riga 401), che delimitano il comportamento previsto. Riproduci con il turno utente multi-content più il turno di modello vuoto mostrati nell'issue. Fatto significa che un turno modello non valido elimina l'intero user run precedente, non un singolo content, e la suite get-history passa.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
4k
Fork
1k
Merge medio
1g 17h
PR unite (30g)
52

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di googleapis/python-genai

Tutte le issue di googleapis/python-genai

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.