Skip to content

fix(gemini): keep user text out of tool-result turns via placeholder model turn (port of gemini-cli#28700, salvages #68863) - #79791

Merged
teknium1 merged 4 commits into
mainfrom
gemini-cli-port/tool-response-user-fuse
Aug 6, 2026
Merged

teknium1 merged 4 commits into
mainfrom
gemini-cli-port/tool-response-user-fuse

Conversation

@teknium1

@teknium1 teknium1 commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

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_contents merges 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 consecutive user content and gets folded into the same content as the functionResponse. Gemini 3 accepts that shape with HTTP 200 but returns an empty candidate or continues the trailing text.

Changes

Validation

Probe Result
tests/agent/test_gemini_native_adapter.py (9) pass
Sibling gemini test files (45 total) pass
E2E: mixed boundary → placeholder interposed, strict alternation holds pass
E2E: parallel tool results still grouped into one user content pass
E2E: back-to-back plain user texts still merge, no placeholder pass
E2E: reverse boundary (text then functionResponse) alternation-valid pass

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

gemini-turn-fusion-fix

rille111 and others added 4 commits August 5, 2026 17:07
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.
@github-actions

github-actions Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

૮ >ﻌ< ა ci review

ran on 8511f73

⚠️ Warnings

OSV vulnerability scan · View job

37 known vulnerabilities found in pinned dependencies.

How to fix:

Review the findings in the Security tab. Update the affected dependencies if a patched version is available.


debug info

CI timings

CI timings · View report · View job

Wall time 3m26s vs 6m35s (-47.8%). 7 job(s) slower, 13 faster, 3 unchanged.

  • Python tests / Run tests slice 9/12: -26.0s
  • Python tests / Run tests slice 11/12: +13.0s
  • Python tests / Run tests slice 8/12: -11.0s
  • Python tests / Run tests slice 6/12: +10.0s
  • Python tests / Run tests slice 12/12: +9.0s

@teknium1
teknium1 merged commit 01a1037 into main Aug 6, 2026
43 checks passed
@teknium1
teknium1 deleted the gemini-cli-port/tool-response-user-fuse branch August 6, 2026 00:21
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/gemini Google Gemini (AI Studio, Cloud Code) labels Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists provider/gemini Google Gemini (AI Studio, Cloud Code) type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants