diff --git a/internal/gateway/antigravity_turned_away_test.go b/internal/gateway/antigravity_turned_away_test.go new file mode 100644 index 000000000..b9d2a16a5 --- /dev/null +++ b/internal/gateway/antigravity_turned_away_test.go @@ -0,0 +1,32 @@ +package gateway + +import "testing" + +// Antigravity answers a 429 "Resource has been exhausted (e.g. check +// quota)" to Claude Code's and the Agent SDK's system prompt whatever the +// quota left (#666: Claude Desktop's chats always 429, its titles and +// Codex on the same account fine); magpie says so rather than leave a user +// chasing a quota. Both lines are as Claude Code 2.1.288 sends them. +func TestAntigravityTurnsAwayClaudeCodesSystemPrompt(t *testing.T) { + for _, system := range []string{ + "x-anthropic-billing-header: cc_version=2.1.288.e3f; cc_entrypoint=sdk-cli;\nYou are Claude Code, Anthropic's official CLI for Claude.", + "You are a Claude agent, built on Anthropic's Claude Agent SDK.\n\nYou are an interactive agent …", + "Some instructions first.\nYou are a Claude agent, built on Anthropic's Claude Agent SDK.", + } { + if !antigravityTurnsAway(system) { + t.Errorf("%q isn't taken for what Antigravity turns away", system) + } + } + // what it lets through: other agents', Claude Code's own name alone, + // and no system prompt at all (Claude Desktop's title requests) + for _, system := range []string{ + "", + "You are a helpful assistant.", + "You are Claude Code, Anthropic's official CLI for Claude.", + "You are Codex, based on GPT-5.", + } { + if antigravityTurnsAway(system) { + t.Errorf("%q is taken for what Antigravity turns away; it answers it", system) + } + } +} diff --git a/internal/gateway/codeassist.go b/internal/gateway/codeassist.go index 5fc43ef57..1270504db 100644 --- a/internal/gateway/codeassist.go +++ b/internal/gateway/codeassist.go @@ -38,6 +38,20 @@ func accountAgent(p provider.Provider) string { return p.Account.Agent } +// antigravityTurnsAway: a system prompt Antigravity answers with a 429 +// "Resource has been exhausted (e.g. check quota)" whatever the quota left, +// the one Claude Code and its Agent SDK (Claude Desktop's chats) send: its +// billing line or the SDK's identity line anywhere in the system +// instruction turns the request away, on every model, while the same words +// in a message go through (#666). magpie doesn't hide them from Google; it +// says why, so no one chases a quota that isn't spent. +func antigravityTurnsAway(system string) bool { + return strings.Contains(system, "x-anthropic-billing-header:") || + strings.Contains(system, "built on Anthropic's Claude Agent SDK") +} + +const antigravityTurnedAwayHint = "not a quota: Antigravity turns away Claude Code's and the Claude Agent SDK's system prompt (Claude Code, Claude Desktop's chats) with this 429; use another provider for them" + // codeAssistID is the id a request on the account's app goes out under: on // Antigravity the variant the effort picks for a model that is a family of // levels, and elsewhere the model magpie knows. It is keyed by the account diff --git a/internal/gateway/gateway.go b/internal/gateway/gateway.go index 9db66c42e..e0ae65ead 100644 --- a/internal/gateway/gateway.go +++ b/internal/gateway/gateway.go @@ -2865,6 +2865,9 @@ func (s *Server) translate(w http.ResponseWriter, r *http.Request, p provider.Pr if res.StatusCode >= 400 { b, _ := io.ReadAll(io.LimitReader(res.Body, 1<<20)) msg := p.Explain(p.Name+": "+provider.APIError(b, res.Status), res.StatusCode, b) + if res.StatusCode == http.StatusTooManyRequests && accountAgent(p) == "antigravity" && antigravityTurnsAway(request.System) { + msg += " — " + antigravityTurnedAwayHint + } if p.Preset == "openrouter" && openRouterSharedPool(b) { markOpenRouterSharedPool(w) }