Repository navigation
fix(ai): continue Google Interactions responses split across requests - #65006
Conversation
There was a problem hiding this comment.
I found no problems that should block this merge. The continuation logic matches Google's documented requires_continuation / continuation_token flow and the official Python SDK's handling. With store on it sends previous_interaction_id set to the interaction that issued the token and leaves out input; with store off it resends the input. Resuming a dropped stream is limited to checkpoints with no visible output after them, which avoids repeating text or tool calls.
I couldn't test against a live Google model. Instead I ran the new tests on the base branch, where 5 of the 7 continuation cases fail (one hangs until its timeout). With this PR all 13 tests in google-interactions.test.ts pass, and tsc --noEmit passes for packages/ai.
Public API: additive only. GoogleInteractions.transport and the Prepared type are new exports from @opencode/ai/protocols. For responses split across requests, the Google usage providerMetadata now holds per-request sums plus a requests count. Single-request responses are unchanged, so this is backwards compatible.
There was a problem hiding this comment.
The new commit is sound; I have nothing new to raise. Follow-up requests now require a new token, and a completed request that returns its own start token stops as an incomplete stream, so it can't loop. A dropped stream gets up to three reconnects without a new token, using the interaction that issued the token, and each new token resets that count. After the third reconnect, the last disconnect is reported as a retryable incomplete-stream error. HTTP errors on follow-up requests go to the existing retry handling. This matches Google's SDK behaviour.
I checked it with scripted streams only (no live Google model): all 16 tests in google-interactions.test.ts pass, and tsc --noEmit passes for packages/ai.
Public API: unchanged since the last review. It adds the GoogleInteractions.transport and Prepared exports to @opencode/ai/protocols, which is backwards compatible.
Issue for this PR
None.
Type of change
What does this PR do?
I made Google Interactions continue the same response when Google asks for another request.
Text, reasoning, signed tool calls, and usage carry across requests. I matched Google's GenAI SDKs: there is no total hop cap, a hop that finishes with its starting token stops, and a dropped stream gets up to three reconnects without a new token. New tokens reset that count. Output after the checkpoint or an HTTP rejection goes through the existing retry path.
How did you verify your code works?
I ran the Google Interactions tests (29 passed), AI typecheck, changed-file lint, and the root check. Live Flash returned
incompleteat a low cap. Neon finished below its hop limit, so neither returned a token. The continuation tests use scripted SSE in Google's documented format.Screenshots / recordings
Not applicable.
Checklist
Added by the opencode bot (AI-generated).
Public API: adds GoogleInteractions.transport and Prepared exports to @opencode/ai/protocols (backwards compatible)