fix(gemini): keep user text out of tool-result turns via placeholder model turn (port of gemini-cli#28700, salvages #68863) - #79791
Merged
Conversation
Do not fold a human user text turn into a preceding functionResponse user content. Gemini 3 accepts that fold with HTTP 200 but then returns an empty model response. Contract: - ordinary same-role merges remain (parallel tool results, back-to-back plain user texts) for Gemini alternation - only mixed functionResponse/text user turns are split
… user text Port from google-gemini/gemini-cli#28700: when an interrupted/failed turn leaves history ending on an unanswered tool result and the user sends a new message, fusing the two into one Gemini user content makes the model read the trailing text as a continuation of the tool result — it 'finishes your sentence' instead of answering. Builds on #68863 (@rille111), which split the mixed functionResponse/text merge but emitted two consecutive user contents — a shape Gemini's alternation contract rejects with HTTP 400 on other request paths (#55125). This follow-up interposes gemini-cli's INTERRUPTED_RESPONSE_PLACEHOLDER model turn between the split contents so the request stays alternation-valid while the user's message remains a turn of its own.
…response-user-fuse
Contributor
૮ >ﻌ< ა ci reviewran on 8511f73
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Native-Gemini adapter no longer fuses a human user message into an adjacent tool-result turn — the model was reading the trailing text as a continuation of the tool result and "finishing your sentence" instead of answering. Port of google-gemini/gemini-cli#28700, salvaging and completing open PR #68863 by @rille111.
Root cause
_build_gemini_contentsmerges ALL adjacent same-role contents to satisfy Gemini's strict user/model alternation (#55125). When an interrupted/failed turn leaves history ending on an unanswered tool result, the user's next message becomes a second consecutiveusercontent and gets folded into the same content as thefunctionResponse. Gemini 3 accepts that shape with HTTP 200 but returns an empty candidate or continues the trailing text.Changes
agent/gemini_native_adapter.py: mixed functionResponse/text user contents are no longer merged (cherry-picked from fix(gemini): prevent user message merge into adjacent function response #68863, @rille111); a placeholder model turn ([The previous response was interrupted before it completed.], mirroring gemini-cli'sINTERRUPTED_RESPONSE_PLACEHOLDER) is interposed between the split contents so the request stays alternation-valid — fix(gemini): prevent user message merge into adjacent function response #68863 alone emitted two consecutive user contents, the exact shape Gemini rejects with HTTP 400 on other paths.tests/agent/test_gemini_native_adapter.py: regression test updated to assert the interposed placeholder and full alternation.Validation
Attribution
Cherry-picked from #68863 — authorship preserved for @rille111 (earliest submitter of the boundary split). This PR should REBASE-merge. After merge, #68863 can be closed with credit.
Source: google-gemini/gemini-cli#28700
Infographic