Repository navigation
Labels
area/coreIssues related to User Interface, OS Support, Core Functionalityeffort/small1 day or less: trivial logic, UI adjustments, docskind/bugpriority/p2Important but can be addressed in a future release.status/bot-triagedstatus/need-information
Description
What happened?
When Gemini CLI attempts to inspect image files (e.g. .png) using the built-in ReadFile tool during an agentic session, the CLI encounters an unhandled API error and enters a broken state with repeated HTTP 400 errors:
✓ ReadFile inspect_history_user.png → Read image file: inspect_history_user.png
✕ [API Error: [{
"error": {
"code": 400,
"message": "Requests ending with a model turn are not supported.",
"errors": [
{
"message": "Requests ending with a model turn are not supported.",
"domain": "global",
"reason": "badRequest"
}
],
"status": "INVALID_ARGUMENT"
}
}
]]
ℹ This request failed. Press F12 for diagnostics, or run /settings and change "Error Verbosity" to full for full details.
✓ ReadFile inspect_history_kim.png → Read image file: inspect_history_kim.png
✕ [API Error: [{
"error": {
"code": 400,
"message": "Requests ending with a model turn are not supported.",
"errors": [
{
"message": "Requests ending with a model turn are not supported.",
"domain": "global",
"reason": "badRequest"
}
],
"status": "INVALID_ARGUMENT"
}
}
]]
Steps to Reproduce
- Start Gemini CLI (
gemini) in a repository containing image assets (e.g.,.png). - Ask the model to inspect or verify a screenshot or UI element that triggers the internal
ReadFiletool on an image file. - Observe that after
ReadFile <image>.pngexecutes, the subsequent API call fails immediately with400 INVALID_ARGUMENT: Requests ending with a model turn are not supported. - Subsequent retries in the same session fail with the identical error.
Root Cause Analysis
The Google Gemini API enforces strict alternating conversation turns (user ↔ model). When sending contents, the request must never end with a model turn.
When ReadFile is executed on an image binary:
- The model initiates a
functionCallturn (role: "model"). - The image processing or response payload generation fails, times out, or fails to properly append a trailing
functionResponse/role: "user"turn back into the conversation buffer. - The CLI's retry/recovery handler re-dispatches the conversation payload with the incomplete
modelturn at the tail of the array. - The Gemini backend rejects the malformed payload with
400 Bad Request: Requests ending with a model turn are not supported.
What did you expect to happen?
- Image files read via
ReadFileshould either be handled properly as multimodal input or gracefully fail with a standard tool error without breaking the turn structure. - The turn manager must ensure that any outgoing request payload to the Gemini API is correctly terminated (i.e. ending with a
functionResponseoruserturn), preventing400 INVALID_ARGUMENTcrashes. - When a tool fails, the session should recover gracefully instead of getting stuck in an infinite error loop.
Client Information
- OS: Windows 11 (MINGW64 / Git Bash) & Ubuntu 24.04 LTS
- Gemini CLI Version: v0.61.0
- Model:
gemini-3.8-flash - Auth: Google OAuth (
oauth-personal/ Workspace)
Reacted by Dimitar Pavlov
Metadata
Metadata
Assignees
Labels
area/coreIssues related to User Interface, OS Support, Core Functionalityeffort/small1 day or less: trivial logic, UI adjustments, docskind/bugpriority/p2Important but can be addressed in a future release.status/bot-triagedstatus/need-information
Type
Projects
- StatusShow more project fieldsClosed
Activity
gemini-cli commentedon Sep 30, 2026
Effort Analysis:
In
packages/core/src/agents/local-executor.ts, theLocalAgentExecutoraggregates tool call results into asyncResultsmap usingsyncResults.set(call.request.callId, call.response.responseParts[0]). When a tool likeReadFilereturns an image,convertToFunctionResponseinsidepackages/core/src/scheduler/tool-executor.tsreturns multiple parts (thefunctionResponsepart and theinlineDatapart as siblings). By exclusively capturingresponseParts[0], the local-executor permanently drops the siblinginlineDatapart. Because the resulting user turn lacks theinlineDataand the multimodal properties attached to thefunctionResponseget stripped byscrubPartinpackages/core/src/utils/historyHardening.ts(called bygeminiChat.ts), the user turn is effectively emptied and skipped. The history sent to the API then ends in the previous model turn, violating the strict alternating user/model API rule. Resolving this requires a trivial, highly localized change topackages/core/src/agents/local-executor.tsto accumulate the fullresponsePartsarray instead of just the first index, placing this firmly in theeffort/smallcategory.Hughhhhcoder commentedon Oct 1, 2026
The triage points to a localized loss of sibling response parts in
LocalAgentExecutor, with a focused regression available around an image-returningReadFilecall. This looks like a good candidate for community contribution: preserve the fullresponsePartsarray for each call and verify that both thefunctionResponseandinlineDatareach the next user turn. If a maintainer agrees, please add thehelp wantedlabel; I’d be happy to/assignand implement it.gemini-cli commentedon Oct 1, 2026
👋 @Hughhhhcoder, thanks for your interest in this issue! We're reserving self-assignment for issues that have been marked with the
help wantedlabel. Feel free to check out our list of issues that need attention.gemini-cli commentedon Oct 12, 2026
Could you please provide the CLI version you are using (such as from the output of the
/aboutcommand) so we can reproduce and investigate this issue?phansl commentedon Oct 19, 2026
CLI Version 0.64.0
Git Commit 4a0749a
Model Auto
Sandbox no sandbox
OS win32
seokjeongeum commentedon Nov 7, 2026
Retest on 2026-11-07: stable v0.67.0 (
dc6602ce) versus pinned main62bab5b2, Linux Node 24.21.0/npm 11.19.0. Both were built in disposable checkouts with exact-lock offlinenpm ci --ignore-scripts, isolated homes and updates disabled; tracked source stayed clean.The 16 ordinary PNG scenarios pass on both versions: two model identifiers × context management on/off × fresh/resumed JSONL × one/two completed
read_filecalls. The probe uses the productionReadFileTool,GeminiChat, recorder/resume conversion and Code Assist request converter, with a controlled content generator. No Google provider request was sent.Six additional request-boundary cases (three shapes across those two model identifiers) show a meaningful difference:
thoughtSignature, with no usable text/tool/image payload.This supports the normalization portion of merged #30153, which is present on main and absent from v0.67.0. See the pinned request-rendering code. Fixture SHA-256:
bfa9bfa4f828514d7d7a67f274f59a0c4fc10dc5e3249c9d9514e8f31cd03240.Additional controlled subagent retest (November 8 KST): the actual compiled
LocalAgentExecutor.runpreserves one and two PNG/text sibling parts on main, but drops them after both single and parallel tool results on stable. Model and scheduler boundaries were stubbed; both loops reachedGOAL. This verifies the sibling-part aggregation change in #30153. Fixture SHA-256:a026f90dab354e6a4cbe3f122fcabdbdfb1d9e5db1a1e4e062276b3edd226ca6.Limitation: this did not reproduce the original provider 400 or demonstrate its account-specific cause. A live retest with a build containing #30153 is still needed before claiming the production report resolved. Leaving this issue open.
seokjeongeum commentedon Nov 11, 2026
I retested upstream main
e5d88fb2, which contains #30153, and PR #30228 ate879341aon Linux with Node v24.21.0.Five controlled assertions from #30228 failed when run against main’s implementation and passed on the PR. They cover the interrupted model turn when the model returns empty or signature-only content after a tool call, role alternation, and the next-speaker check.
With the live Gemini Developer API and
gemini-3.8-flash, one of three main sessions successfully read both PNGs withread_file, returned both image markers, and answered a plain-text follow-up in the same session. A second session timed out waiting for a response after the first image read. The third returned the first marker and hit HTTP 429 on the second image prompt. On the PR, the first image read succeeded before HTTP 429 on the post-tool request. One retry hit HTTP 429 before the tool ran.The observed post-tool requests ended in a user turn with an image. The reported terminal-model HTTP 400 did not occur in these live attempts. Verification with the original Workspace OAuth account remains pending.