Skip to content

Omit empty model message when replaying stopped Gemini streams - #445

Open
Pybsama wants to merge 1 commit into
huggingface:mainfrom
Pybsama:fix-gemini-stopped-stream-replay
Open

Pybsama wants to merge 1 commit into
huggingface:mainfrom
Pybsama:fix-gemini-stopped-stream-replay

Conversation

@Pybsama

@Pybsama Pybsama commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Pass stoppedResponseContentMetadata to state.stoppedSnapshot(provider: "Gemini", ...) in GeminiLanguageModel.streamResponse when state.responseText.isEmpty, matching GeminiLanguageModel.respond.
  • Without that metadata, Transcript.resolveStringTurn cannot identify the synthetic empty response of a stopped tool round that had no preceding text (including rounds that only carried a signed thought plus a function call), so the next request replays an extra empty "model" message (parts: [{"text": ""}]) between the tool output and the next user prompt.
  • Leaving providerMetadata as nil when state.responseText is non-empty preserves existing behavior for stopped streams with preamble text (including history transforms that clear the response).

Testing

  • Added regression tests in GeminiAssistantHistoryTests:
    • aStoppedToolRoundWithoutTextOmitsEmptyModelMessage(streaming:) (reproduced failure for streaming: true pre-fix)
    • aStoppedToolRoundWithSignedThoughtOmitsEmptyModelMessage(streaming:)
  • Ran swift format lint --strict --recursive . (PASS)
  • Ran swift test --disable-index-store --filter "GeminiAssistantHistoryTests|StoppedToolCallReplayTests" (PASS)
  • Ran swift test --skip-build --disable-index-store --skip OllamaLanguageModelTests (1,112 tests in 114 suites PASS)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant