Skip to content

fix: merge streamed model history turns#2566

Open
he-yufeng wants to merge 1 commit into
googleapis:mainfrom
he-yufeng:fix/merge-stream-model-history
Open

fix: merge streamed model history turns#2566
he-yufeng wants to merge 1 commit into
googleapis:mainfrom
he-yufeng:fix/merge-stream-model-history

Conversation

@he-yufeng

Copy link
Copy Markdown
Contributor

Fixes #2508.

Summary

When a streaming response yields multiple valid model Content chunks, the chat currently keeps those chunks as consecutive model turns in curated history. That history is reused for later requests, so the next request can include back-to-back model turns instead of a single model turn.

This change keeps comprehensive history unchanged, but normalizes curated history by merging adjacent model chunks into one model turn. That preserves the original parts while keeping request history in the expected user/model turn shape.

Tests

python -m pytest google\genai\tests\chats\test_get_history.py -q
python -m pytest google\genai\tests\chats\test_validate_response.py -q
python -m mypy google\genai\chats.py
python -m py_compile google\genai\chats.py google\genai\tests\chats\test_get_history.py
git diff --check

@Venkaiahbabuneelam Venkaiahbabuneelam self-assigned this Jun 8, 2026
@Venkaiahbabuneelam Venkaiahbabuneelam added the size:XL Code changes > 100 lines label Jun 8, 2026
@he-yufeng he-yufeng force-pushed the fix/merge-stream-model-history branch from cb4b2b7 to 77160fd Compare June 12, 2026 11:48
@he-yufeng

Copy link
Copy Markdown
Contributor Author

Rebased this branch onto current main and pushed the updated head 77160fd.

Validation:

  • python -m pytest google\genai\tests\chats\test_get_history.py -q -k "stream_merges_model_chunks_for_curated_history" -> passed, 1 passed
  • python -m py_compile google\genai\chats.py google\genai\tests\chats\test_get_history.py -> passed
  • git diff --check upstream/main..HEAD -> passed

@he-yufeng he-yufeng force-pushed the fix/merge-stream-model-history branch from 77160fd to f8cd04f Compare June 12, 2026 14:11
@he-yufeng he-yufeng force-pushed the fix/merge-stream-model-history branch from f8cd04f to bee08cd Compare June 12, 2026 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL Code changes > 100 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tool call history tracking invalidates implicit cache during chat stream session

2 participants