Commit Graph
6 Commits
Author SHA1 Message Date
yetoneandump45nose ce11b18015 gateway: Codex compacts on Gemini after a tool's output, no "Requests ending with a model turn" (#1533, yycsyu)
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>
2026-10-11 04:33:03 +08:00
wei c45ece36a0 gateway: Code Assist sends the auto mode classifier's reasoning off at low, not high, on a Gemini 3 Flash that lists minimal
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.
2026-10-10 17:54:54 +08:00
yetone 71f0541342 gateway: Antigravity's Claude gets a tool turn's images after every tool result, each labelled with the call it came from (@sinswing on X: an image between two functionResponses came back from Google as "tool_use ids were found without tool_result blocks immediately after")
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.
2026-10-07 00:44:32 +08:00
yetone 090f7733ef gateway: Antigravity's Gemini variants think with tools again, and a call the model writes out as text is a call (#636) — a variant id (gemini-3.8-flash-high, the one an effort picks for gemini-3.8-flash) went with includeThoughts but no thinkingLevel since 2baad536, and told no level it all but stopped thinking once the request had tools and gave none of it back, where the -tiered id, sent a level, kept it. A variant is now told the level its id says (Flash minimal/low/medium/high, Pro's minimal as low, xhigh as high), so the id and the level still agree. The Code Assist decoder takes Gemini's namespace off a call's name (default_api:bash → bash), and a call written out in the reply's text, "…imports!call:default_api:bash{command:cat x}", becomes the tool call it meant (arguments as JSON members, <ctrl46>-quoted, or bare key:value), the text before it kept; text that only might start one is held until it is one or isn't, and an unfinished one stays text. Upstream 502/503 were already errors (HTTP status, or an error event mid-stream), not changed. TestCodeAssistAntigravityLevels and TestCodeAssistTextCalls fail without it. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build and go test -tags nogui -count=1 ./... under a temp HOME pass. Not tried against a real Antigravity account. 2026-10-03 13:38:12 +08:00
yetone 2baad5366c provider: Antigravity's models at several levels are one model with those levels (#150: 统一 Antigravity 模型变体与客户端推理档位的映射) — Antigravity lists gemini-3.7-flash-low, -medium and -high as three models, "Gemini 3.7 Flash (Low)" …, so a client picked a level twice: once in the model, once as its reasoning effort, with no telling which won. Now ids that are one id with an effort word after it (-low, -medium, -high, -extra-low, -minimal, -xhigh) are one model, gemini-3.7-flash "Gemini 3.7 Flash", declaring only the levels there are (low,medium,high; Gemini 3.1 Pro low,high), so Codex, Pi and the rest get reasoning levels for it. The level a variant is at is what Antigravity's name says where each name says a different one (gemini-3.5-flash-extra-low is "(Low)", gemini-3.5-flash-low "(Medium)"), else its id's word; a model only named like another (gemini-3-flash-agent, "Gemini 3.5 Flash (High)"; gemini-pro-agent) or with no sibling (gpt-oss-120b-medium) stays as listed. A request asks for the variant the effort picks, an effort it lacks at the nearest level (xhigh is high; medium on low/high is high); with none asked, the id without a level if Antigravity has one, else high — what Gemini 3 does unasked — else the highest. A variant's request carries no thinkingLevel, so the id and the level can't disagree. An old variant id still works: as named with no effort, and moved to the effort asked for. Saved picks and agents set to a variant (antigravity/gemini-3.7-flash-high) are moved to the family, at that level where the agent's own is unset, as Cursor's are. For Gemini 3 models without variants, medium now goes as medium to Flash (which takes minimal/low/medium/high) and still as high to Pro (low/high). Tested against the list an account's fetchAvailableModels gave (sandbox cache) 2026-09-28 20:10:00 +08:00
yetone 637b2458ee provider + gateway: Google sign-ins — Gemini CLI's and Antigravity's — are subscriptions of magpie's, so any agent can use their models (#4); Gemini CLI's own login in ~/.gemini is read as it is, or an account is signed in from magpie with Google's OAuth, its token refreshed in memory, and each request goes to Code Assist wrapped as the app wraps it, with the project Code Assist set the account up with; Google now serves Gemini CLI's sign-in only to Code Assist Standard and Enterprise, which need a Cloud project, named with magpie accounts project or GOOGLE_CLOUD_PROJECT in ~/.gemini/.env and said so where the account is shown; Google may suspend an Antigravity account used outside Antigravity, so magpie says that and asks before adding one 2026-09-25 15:53:33 +08:00