What the user saw: Codex on Google Vertex AI (gemini-3.8-flash) failed
every compaction that came right after a tool's output with
"Google Vertex AI: Requests ending with a model turn are not supported."
Why: codexInput turns compaction_trigger into a user message holding the
compaction prompt; mergeTurns and then buildCodeAssistSent merged it with
the function_call_output's user turn, so Gemini got one user content
holding a functionResponse and text. Vertex answers that with the
"ending with a model turn" 400 although the last role is user; #1533
showed the same history with the two as separate user contents gets 200.
What changed:
- buildCodeAssistSent (every Gemini-shaped request: Vertex AI, Factory's
Gemini, Gemini CLI's and Antigravity's Code Assist, Google sign-in)
puts what the user said after tools' responses in a user turn of its
own, and never merges text into a responses turn or the other way.
Tools' images stay with their response; parallel calls' responses stay
in one turn. A Claude model on Antigravity keeps its single tool_result
turn as before.
- It also never ends contents with the model's turn: a user turn goes
after it ("Continue.", or compactLastText when an agent compacts with
the ask in its system prompt). prefillRefusal knows Gemini's wording.
- docs/subsystems/gateway-routing.md says both.
Tests: gemini_model_last_test.go uses #1533's exact Responses request
(read_sample / call_diagnostic_1 / compaction_trigger) on /v1/responses
and Codex's path against a fake Vertex that refuses as the real one did;
with the split disabled it fails with the reporter's exact message, and
TestGeminiToolResponseTurnHoldsNoText fails for all four builders.
ump45nose's fork patch on #1533 (93a2afca) found the same cause and
split the turn on Vertex AI only; this does it for every Gemini builder,
and takes its Anthropic case (a tool_result beside text in one message)
into the end-to-end test, which fails on the old code too.
TestBuildCodeAssistForGemini, TestCodeAssistToolImagesAfterEveryResponse
and TestGeminiHistoryOpeningWithModel held the old one-turn merge (from
637b2458, a choice, not a fix for a report) and now expect the question
in a turn of its own.
Run: go test ./internal/gateway ./internal/provider, the full
go test -tags nogui ./... (queue lock), gofmt -l, go vet -tags nogui for
darwin, linux and windows.
Not tried against real Vertex AI: no Vertex credentials on this machine.
Co-authored-by: ump45nose <52391318+ump45nose@users.noreply.github.com>
fitAutoModeClassifier asks a model to think at its least level (#250). On
a Gemini 3 Flash whose models.dev levels include minimal (gemini-3.5-flash,
3.1-flash-lite, 3-flash-preview), that level is minimal. thinkingConfig
sends minimal only to an Antigravity variant whose id says minimal, and
everything else fell through to high. So the classifier, asked to think
least, went at the most, with 2112 tokens to think and answer in.
Sending minimal instead isn't safe. Gemini CLI's 3.5 Flash goes out as
3.8 Flash where that is rolled out (geminiFlags.wire), and 3.8 Flash has
no minimal: AI Studio answers it with a 400.
Reasoning off (minimal or none) with no variant level now goes at low,
which every Gemini 3 text model lists. An image model may have no low
(3.1 Flash Image has minimal and high), so it still goes at high, as
before. Every other case is unchanged: a variant's own level, low, medium,
high, no effort, and Gemini 2.5's budgets. The comment saying Flash takes
minimal, low, medium and high is corrected. Factory's Gemini route
(buildGemini) builds its request with the same code, and gets the same
change.
TestCodeAssistReasoningOffAtLow sends Claude Code's classifier request
(autoModeAsk) to Gemini CLI's gemini-3.5-flash and to Antigravity's
gemini-3.1-flash-lite, with models.dev's levels. Both go at low. It also
asks an image model at low, which fits to minimal; that goes at high.
* With the parent's codeassist.go it fails with: the classifier on
gemini's gemini-3.5-flash: "minimal" at "high", want minimal at low.
Antigravity's 3.1-flash-lite fails the same way.
* Without the image check it fails with: gemini-3.1-flash-image asked
low: at "low", want high.
Verified with the commit before. Not tried live.
Checked with the owner's real Antigravity account: two Reads that each
return a PNG fail on claude-sonnet-4-6 and claude-opus-4-6-thinking
before, and both answer with each file's own colour after. Gemini on
Antigravity keeps each image beside its response.