An agent's compaction or a cut-down context can leave a history whose
first turn is the assistant's (text, or a tool call). Gemini turns that
away: "Please ensure that function call turn comes immediately after a
user turn or after a function response turn." buildCodeAssistSent, which
Gemini CLI and Antigravity accounts, Factory's generateContent route
(buildGemini) and Zed's Google models all build their contents with, now
puts the user turn "[Continuing from previous AI thoughts...]" before such
a history, as Gemini CLI's own hardenHistory (packages/core/src/utils/
historyHardening.ts, enforceRoleConstraints) does. Histories that open
with the user, and parallel calls split over two assistant messages, go
as before. Chat, Responses and Anthropic upstreams are unchanged.
Verified: TestGeminiHistoryOpeningWithModel fails without the change
(roles model,user, want user,model,user, for codeassist/gemini,
codeassist/antigravity and gemini, with model text and with a model
functionCall first). TestGeminiHistoryOpeningWithUserUnchanged and
TestNonGeminiHistoryOpeningWithModelUntouched pass before and after.
go test -tags nogui ./internal/gateway/... ./internal/zed/... under a temp
HOME with pinned caches; go vet -tags nogui for darwin, linux, windows.
Not tried against a real Gemini or Antigravity account.