Skip to content

fix(gemini): fail invalid function calls, end unfinished continuations - #4808

Open
jaeminbird wants to merge 1 commit into
docker:mainfrom
jaeminbird:fix/gemini-malformed-continuation
Open

jaeminbird wants to merge 1 commit into
docker:mainfrom
jaeminbird:fix/gemini-malformed-continuation

Conversation

@jaeminbird

Copy link
Copy Markdown
Contributor

Follow-up to #4786, covering the two P2.1 cases from #4600 that @aheritier flagged in review.

  • MALFORMED_FUNCTION_CALL / UNEXPECTED_TOOL_CALL: Gemini ends the turn without the call. On main this fell through to the inferred reason, so the turn ended as an empty null, or as stop when text came first. It looked like a finished answer. The adapter now fails the stream with ErrInvalidFunctionCall. modelerrors treats it as non-retryable, so a fallback model takes over if one is configured.
  • Leaked CONTINUATION: SDK v1.77 continues automatically, but when it can't resume (no token, or a repeated token with no progress), the partial answer ended as stop. A pending continuation now ends the turn as length. Any later finish reason clears it, so a resumed stream still ends as stop.
Tests
  • Adapter: 5 new cases fail on main (3 failure, 2 continuation); a resumed-then-stopped control passes.
  • Real client → LocalRuntime fixture (geminiintegration): 3 new cases fail on main; with the fix, length for both continuation cases, an error event for the malformed call, 0 tool runs. Passed 20/20.
  • go test ./pkg/model/provider/... ./pkg/runtime/... ./pkg/acp/... ./pkg/cli/... on Windows: only TestBackgroundWorktree* and TestFilesystemPolicyExpandsHomeDirectory fail, same on main. golangci-lint clean. Not run on Linux this time.
  • The Gemini API converter in the SDK drops finishMessage, so the error carries only the reason there.

Completes the remaining docker#4600 P2.1 terminal cases raised in the docker#4786
review.

MALFORMED_FUNCTION_CALL and UNEXPECTED_TOOL_CALL now fail the stream
with ErrInvalidFunctionCall instead of falling through to the inferred
stop or tool_calls, so the turn can no longer end as an empty or
apparently complete answer.

A CONTINUATION stop, or a continuation token, that the SDK doesn't
resume now ends the turn as length instead of stop. Any later finish
reason clears it, so a resumed stream still ends as stop.
@jaeminbird
jaeminbird requested a review from a team as a code owner November 5, 2026 00:23
Copilot AI balanced review requested due to automatic review settings November 5, 2026 00:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@aheritier aheritier added area/providers/gemini Google Gemini provider support area/runtime Runtime engine, agent loop execution, tool dispatch, loop detection kind/fix PR fixes a bug (maps to fix:). Use on PRs only. labels Nov 5, 2026

This branch has not been deployed

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

Labels

area/providers/gemini Google Gemini provider support area/runtime Runtime engine, agent loop execution, tool dispatch, loop detection kind/fix PR fixes a bug (maps to fix:). Use on PRs only.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants