diff --git a/internal/gateway/antigravity_rest_test.go b/internal/gateway/antigravity_rest_test.go index 2c5acaad1..9cd0b556a 100644 --- a/internal/gateway/antigravity_rest_test.go +++ b/internal/gateway/antigravity_rest_test.go @@ -135,7 +135,7 @@ func TestAntigravityTurnedAwayRestsNobody(t *testing.T) { t.Fatalf("the turn: %d %s", code, out) } r := lastRoute(s) - if len(r.Tries) != 2 || r.Tries[0].Status != 429 || r.Tries[0].Fail != failRefused || r.Tries[0].Rest != nil { + if len(r.Tries) != 2 || r.Tries[0].Status != 429 || r.Tries[0].Fail != failPrompt || r.Tries[0].Rest != nil { t.Fatalf("the turned-away try: %+v", r.Tries) } if !strings.Contains(r.Tries[0].Error, antigravityTurnedAwayHint) { @@ -295,7 +295,7 @@ func TestAntigravityTurnedAwaySaidInsideTheReply(t *testing.T) { if resting != tc.rest { t.Fatalf("rests %v, want %v: %+v", resting, tc.rest, r.Tries) } - if want := failRefused; !tc.rest && r.Tries[0].Fail != want { + if want := failPrompt; !tc.rest && r.Tries[0].Fail != want { t.Fatalf("the refusal said inside the reply: Fail=%q: %+v", r.Tries[0].Fail, r.Tries) } }) @@ -314,3 +314,160 @@ func rests() map[string]time.Time { } return out } + +// antigravityQuota is Antigravity's 429 when the plan's own allowance on the +// model is used up: it names the quota and when it resets, which the refusal +// of #666 never does. +const antigravityQuota = `{"error":{"code":429,"message":"You have exhausted your capacity on this model. Your quota will reset after 3h19m30s.","status":"RESOURCE_EXHAUSTED","details":[{"@type":"type.googleapis.com/google.rpc.ErrorInfo","reason":"QUOTA_EXHAUSTED","domain":"cloudcode-pa.googleapis.com"}]}}` + +// directTurn is a Claude Desktop chat on Antigravity's model itself, not a +// group: the one account is the last left to ask (#1425). +func directTurn(system string, stream bool) string { + return `{"model":"antigravity/m","max_tokens":100,"stream":` + fmt.Sprint(stream) + `,"system":` + quote(system) + `,"messages":[{"role":"user","content":"hi"}]}` +} + +// #1425: Claude Desktop's chat on Antigravity alone, with quota to spare. +// Nobody is left to ask, and the agent is told why at a status the +// Anthropic and OpenAI SDKs don't retry — Antigravity's own 429 had Claude +// Desktop ask again ten times over, each turned away the same. The Routing +// page tells it as the agent's prompt turned away, not a quota used up; the +// account doesn't rest and isn't asked again. +func TestAntigravityTurnedAwayLastIsNoQuota(t *testing.T) { + for _, stream := range []bool{false, true} { + t.Run(fmt.Sprintf("stream=%v", stream), func(t *testing.T) { + asked := 0 + s, askedUsage := antigravityTurnedAwayGroup(t, []string{"u@example.com"}, func(w http.ResponseWriter, r *http.Request) { + asked++ + w.WriteHeader(http.StatusTooManyRequests) + io.WriteString(w, turnedAway) + }) + code, out := turnOn(t, s, directTurn(claudeCodeSystem, stream)) + if code != http.StatusBadRequest { + t.Fatalf("the agent got %d, which its SDK retries: %s", code, out) + } + if !strings.Contains(out, "invalid_request_error") || !strings.Contains(out, "Resource has been exhausted") || !strings.Contains(out, antigravityTurnedAwayHint) { + t.Fatalf("the agent isn't told Antigravity's words and why: %s", out) + } + if asked != 1 { + t.Fatalf("Antigravity was asked %d times for a request it turns away every time", asked) + } + r := lastRoute(s) + if r.Status != http.StatusBadRequest || len(r.Tries) != 1 { + t.Fatalf("the route: %d %+v", r.Status, r.Tries) + } + if try := r.Tries[0]; try.Status != http.StatusTooManyRequests || try.Fail != failPrompt || try.Rest != nil { + t.Fatalf("the try is told as %q (rest %v), not the agent's prompt turned away: %+v", try.Fail, try.Rest, try) + } + if *askedUsage != 0 { + t.Fatalf("the account's usage was asked again %d times for a request it refused", *askedUsage) + } + if _, ok := restOf("antigravity@u@example.com"); ok { + t.Fatalf("antigravity@u@example.com rests for a request it turned away: %v", rests()) + } + rows, _, _ := usage.Ledger(usage.All, usage.Filter{Provider: "antigravity"}) + if len(rows) != 1 || rows[0].Status != http.StatusBadRequest || rows[0].ErrType != turnedAwayErrType { + t.Fatalf("the request list's row: %+v", rows) + } + }) + } +} + +// The same refusal said inside the reply (a 200 that opens with the error +// event), with nobody left: told the same, at a status not retried, and not +// asked again as a failure that may pass. +func TestAntigravityTurnedAwayInsideTheReplyLast(t *testing.T) { + asked := 0 + s, _ := antigravityTurnedAwayGroup(t, []string{"u@example.com"}, func(w http.ResponseWriter, r *http.Request) { + asked++ + w.Header().Set("Content-Type", "text/event-stream") + io.WriteString(w, sse(`data: {"error":{"message":"Resource has been exhausted (e.g. check quota)."}}`)) + }) + code, out := turnOn(t, s, directTurn(claudeCodeSystem, true)) + if code != http.StatusBadRequest || !strings.Contains(out, "Antigravity: Resource has been exhausted (e.g. check quota). — "+antigravityTurnedAwayHint) { + t.Fatalf("the agent got %d: %s", code, out) + } + if asked != 1 { + t.Fatalf("asked %d times", asked) + } + if r := lastRoute(s); len(r.Tries) != 1 || r.Tries[0].Fail != failPrompt || r.Tries[0].Rest != nil { + t.Fatalf("the try: %+v", r.Tries) + } +} + +// When the member after Antigravity's is out of its own allowance, the agent +// is told what Antigravity turned away and why, at a status it doesn't +// retry — not the other's quota, which waiting wouldn't fix either. +func TestAntigravityTurnedAwayThenAQuota(t *testing.T) { + s, _ := antigravityTurnedAwayGroup(t, []string{"u@example.com"}, func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusTooManyRequests) + io.WriteString(w, turnedAway) + }) + spent := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusTooManyRequests) + io.WriteString(w, `{"type":"error","error":{"type":"rate_limit_error","message":"weekly usage limit reached"}}`) + })) + t.Cleanup(spent.Close) + if err := provider.Save(provider.Provider{ID: "other", Name: "Other", Key: "k", Models: []string{"m"}, Anthropic: spent.URL}); err != nil { + t.Fatal(err) + } + code, out := turnOn(t, s, claudeTurn(claudeCodeSystem)) + if code != http.StatusBadRequest || !strings.Contains(out, antigravityTurnedAwayHint) { + t.Fatalf("the agent got %d: %s", code, out) + } + r := lastRoute(s) + if len(r.Tries) != 2 || r.Tries[0].Fail != failPrompt || r.Tries[1].Fail != failQuota { + t.Fatalf("the tries: %+v", r.Tries) + } +} + +// Antigravity's 429 for a plan really used up stays the quota it is on a +// Claude Code turn too: its words name the quota and when it resets, not +// the refusal's. It rests the account, goes on to the next member, and with +// nobody left the agent gets the 429 (Rest-of-#666 review: refusal, account +// or model, told apart by what was said, not by the system prompt alone). +func TestAntigravityQuotaOnAClaudeCodeTurnStaysQuota(t *testing.T) { + t.Run("in a group", func(t *testing.T) { + s, askedUsage := antigravityTurnedAwayGroup(t, []string{"u@example.com"}, func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusTooManyRequests) + io.WriteString(w, antigravityQuota) + }) + if code, out := turnOn(t, s, claudeTurn(claudeCodeSystem)); code != 200 || !strings.Contains(out, "from the other") { + t.Fatalf("the turn: %d %s", code, out) + } + r := lastRoute(s) + if len(r.Tries) != 2 || r.Tries[0].Fail != failQuota || r.Tries[0].Rest == nil { + t.Fatalf("the used-up try: %+v", r.Tries) + } + if strings.Contains(r.Tries[0].Error, antigravityTurnedAwayHint) { + t.Fatalf("a used-up plan is said not to be a quota: %s", r.Tries[0].Error) + } + if *askedUsage != 1 { + t.Fatalf("the account's usage was asked again %d times, once as for any used-up plan", *askedUsage) + } + }) + t.Run("the last left", func(t *testing.T) { + s, _ := antigravityTurnedAwayGroup(t, []string{"u@example.com"}, func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusTooManyRequests) + io.WriteString(w, antigravityQuota) + }) + code, out := turnOn(t, s, directTurn(claudeCodeSystem, false)) + if code != http.StatusTooManyRequests || strings.Contains(out, antigravityTurnedAwayHint) { + t.Fatalf("the agent got %d: %s", code, out) + } + if r := lastRoute(s); len(r.Tries) != 1 || r.Tries[0].Fail != failQuota { + t.Fatalf("the try: %+v", r.Tries) + } + }) +} + +// The Routing page says the note apart from Antigravity's words, in its own +// language, only when it knows the very words the gateway adds. +func TestAntigravityTurnedAwayHintIsTheRoutingPages(t *testing.T) { + b, err := os.ReadFile(filepath.Join("..", "gui", "assets", "routing.js")) + if err != nil { + t.Fatal(err) + } + if !strings.Contains(string(b), quote(antigravityTurnedAwayHint)) { + t.Fatal("routing.js doesn't know the note the gateway adds to Antigravity's refusal") + } +} diff --git a/internal/gateway/codeassist.go b/internal/gateway/codeassist.go index 2bceedae3..8a6cb34ee 100644 --- a/internal/gateway/codeassist.go +++ b/internal/gateway/codeassist.go @@ -4,6 +4,7 @@ import ( "cmp" "encoding/json" "fmt" + "net/http" "regexp" "strings" @@ -61,7 +62,31 @@ func antigravityRefuses(said string) bool { return strings.Contains(strings.ToLower(said), "resource has been exhausted") } -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" +// antigravityTurnedAway says whether what p answered a request with system +// as its system instruction is that refusal (#666): an Antigravity account, +// the system prompt it turns away, and its "Resource has been exhausted" +// words. A 429 that says something else — the plan's own allowance used up +// ("You have exhausted your capacity on this model. Your quota will reset +// after …") — is the quota it says, whatever the system prompt (#1425). +func antigravityTurnedAway(p provider.Provider, system, said string) bool { + return accountAgent(p) == "antigravity" && antigravityTurnsAway(system) && antigravityRefuses(said) +} + +// antigravityTurnedAwayHint is what magpie adds to Antigravity's words, after +// " — ", for the agent and the Routing page, which says it apart from them in +// its own language (routing.js AG_TURNED_AWAY). +const antigravityTurnedAwayHint = "Antigravity answers this 429 to the system prompt of Claude Code and the Claude Agent SDK (Claude Desktop's chats) whatever quota is left, so it is not a quota and waiting won't help; use another provider for these chats, or put one after Antigravity in a routing group" + +// turnedAwayStatus is what the agent is told when nobody is left to answer +// what Antigravity turned away: a request it shouldn't send again as it is. +// Antigravity's own 429 had the Anthropic and OpenAI SDKs — Claude Desktop, +// Claude Code — retry it ten times over, each one turned away the same +// (#1425); they retry 408, 409, 429 and 5xx, and not a 400. +const turnedAwayStatus = http.StatusBadRequest + +// turnedAwayErrType is the usage log's ErrType for that refusal, in place of +// the 429 Antigravity's body calls it. +const turnedAwayErrType = "prompt_turned_away" // 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 diff --git a/internal/gateway/continuation.go b/internal/gateway/continuation.go index b76fcb3f6..17caf1ce3 100644 --- a/internal/gateway/continuation.go +++ b/internal/gateway/continuation.go @@ -325,11 +325,12 @@ func (s *Server) streamTranslated(w http.ResponseWriter, r *http.Request, p prov if wrongEndpoint(res.StatusCode, b) { failed += wrongAPINote(p, model, res, b) } - if res.StatusCode == http.StatusTooManyRequests && accountAgent(p) == "antigravity" && antigravityTurnsAway(request.System) { + turnedAway := res.StatusCode == http.StatusTooManyRequests && antigravityTurnedAway(p, request.System, string(b)) + if turnedAway { failed += " — " + antigravityTurnedAwayHint } if !cont.resume { - if res.StatusCode == http.StatusTooManyRequests && accountAgent(p) == "antigravity" && antigravityTurnsAway(request.System) { + if turnedAway { markAntigravityTurnsAway(w) } if p.Preset == "openrouter" && openRouterSharedPool(b) { @@ -337,6 +338,9 @@ func (s *Server) streamTranslated(w http.ResponseWriter, r *http.Request, p prov } keepRetry(w.Header(), res.Header, b) u.ErrType = provider.ErrorType(b) + if turnedAway { + u.ErrType = turnedAwayErrType + } return writeError(w, from, res.StatusCode, failed), failed } } @@ -449,9 +453,12 @@ func (s *Server) streamTranslated(w http.ResponseWriter, r *http.Request, p prov failed = p.Name + ": " + errEndedShort.Error() } } - if failed != "" { + if failed != "" && markAntigravityRefused(w, p, request.System, failed) { // the same refusal as the 429's, said inside the reply - markAntigravityRefused(w, p, request.System, failed) + if !strings.HasSuffix(failed, antigravityTurnedAwayHint) { + failed += " — " + antigravityTurnedAwayHint + } + u.ErrType = turnedAwayErrType } if !errSent { enc.event(Event{Kind: KError, Text: failed, Code: failedCode}) diff --git a/internal/gateway/gateway.go b/internal/gateway/gateway.go index 42a456498..cb1b8132a 100644 --- a/internal/gateway/gateway.go +++ b/internal/gateway/gateway.go @@ -2027,6 +2027,14 @@ func (s *Server) serve(w http.ResponseWriter, r *http.Request, from provider.Pro } if hw.failure != 0 { // the stream failed before any of it was sent call.Status, call.Error = hw.failure, c.p.Name+": "+hw.failMsg + if hw.turnedAway { + // Antigravity's refusal said as the stream's error event: + // its words, and why, as its 429 is told (#1425) + call.Error = c.p.Name + ": " + provider.APIError([]byte(hw.failMsg), hw.failMsg) + } + } + if hw.turnedAway && !strings.HasSuffix(call.Error, antigravityTurnedAwayHint) { + call.Error += " — " + antigravityTurnedAwayHint } if hw.refused { // the vendor's safety filter, with nothing said (#248) @@ -2180,8 +2188,14 @@ func (s *Server) serve(w http.ResponseWriter, r *http.Request, from provider.Pro // wrong with it and no usage is asked again (#666). Its own // mates are asked last, not first: they carry the same system // prompt, so each is turned away just the same before the group - // reaches a member that answers - try.Fail = failRefused + // reaches a member that answers. It is told as the agent's prompt + // turned away, as WorkBuddy's is, not a quota (#1425); and if + // nobody after it answers but with a quota of its own, that is + // what the agent is told, at a status it doesn't retry + if other == nil { + other = &Try{Status: turnedAwayStatus, Error: call.Error} + } + try.Fail = failPrompt s.trace.update(tr, func(t *Route) { t.Tries[len(t.Tries)-1] = try if call.To != "" { @@ -2363,8 +2377,9 @@ func (s *Server) serve(w http.ResponseWriter, r *http.Request, from provider.Pro skipped = append(skipped, c.label()+": "+call.Error) continue } - if wait, ok := passing(hw.code(), hw.header, hw.errBody(), again); ok && !protected && hw.failed() { - // nobody else is left: the same one again, after a moment + if wait, ok := passing(hw.code(), hw.header, hw.errBody(), again); ok && !protected && !hw.turnedAway && hw.failed() { + // nobody else is left: the same one again, after a moment (not + // what Antigravity turned away: it turns it away again) try.Fail, try.Again = failureOf(c, hw.code(), hw.errBody()), wait.Milliseconds() s.trace.update(tr, func(t *Route) { t.Tries[len(t.Tries)-1] = try }) skipped = append(skipped, c.label()+": "+call.Error) @@ -2379,7 +2394,7 @@ func (s *Server) serve(w http.ResponseWriter, r *http.Request, from provider.Pro break } // (not for one account pinned: the others weren't asked) - if !autoReset && pin == "" && last && other == nil && hw.failed() && !hw.passing && failure(hw.code(), hw.errBody()) == failQuota { + if !autoReset && pin == "" && last && other == nil && hw.failed() && !hw.passing && !hw.turnedAway && failure(hw.code(), hw.errBody()) == failQuota { // everyone is out of their allowance: a Codex or Claude account // the user lets spend its resets by itself, its week used up, // spends one and is asked again @@ -2401,6 +2416,13 @@ func (s *Server) serve(w http.ResponseWriter, r *http.Request, from provider.Pro // request it shouldn't send again as it is, not handed an empty // reply it would ask again for, paying for each failTo(w, kept, from, refusedStatus, call.Error) + } else if hw.turnedAway && hw.failed() { + // nobody is left to answer what Antigravity turned away: the + // agent is told why, at a status it doesn't retry, not the 429 + // it would ask again for ten times over, each turned away the + // same (#1425). The account isn't at fault, and doesn't rest + call.Status = turnedAwayStatus + failTo(w, kept, from, call.Status, call.Error) } else if f := failure(call.Status, []byte(call.Error)); other != nil && !hw.passing && call.Status >= 400 && (f == failQuota || f == failCredit) { // the last one left is out of its allowance, but one before it // failed otherwise: the agent is told that one's error, not @@ -2468,6 +2490,10 @@ func (s *Server) serve(w http.ResponseWriter, r *http.Request, from provider.Pro } } else if hw.refused { try.Fail = failRefused + } else if hw.turnedAway { + // Antigravity turned the agent's system prompt away (#666), at + // whatever quota the account has: not a quota used up (#1425) + try.Fail = failPrompt } else if promptRefused(call.Status, []byte(call.Error)) { try.Fail = failPrompt } else { @@ -2750,11 +2776,13 @@ func markAntigravityTurnsAway(w http.ResponseWriter) { // its message, the Code Assist decoder keeping neither its code nor its // status. An error event of any other kind says something else and marks // nothing. -func markAntigravityRefused(w http.ResponseWriter, p provider.Provider, system, said string) { - if said == "" || !antigravityRefuses(said) || accountAgent(p) != "antigravity" || !antigravityTurnsAway(system) { - return +// It says whether it marked it. +func markAntigravityRefused(w http.ResponseWriter, p provider.Provider, system, said string) bool { + if said == "" || !antigravityTurnedAway(p, system, said) { + return false } markAntigravityTurnsAway(w) + return true } // forward sends a request to the provider. On Anthropic's messages, a @@ -4110,7 +4138,8 @@ func (s *Server) translate(w http.ResponseWriter, r *http.Request, p provider.Pr if wrongEndpoint(res.StatusCode, b) { msg += wrongAPINote(p, model, res, b) } - if res.StatusCode == http.StatusTooManyRequests && accountAgent(p) == "antigravity" && antigravityTurnsAway(request.System) { + turnedAway := res.StatusCode == http.StatusTooManyRequests && antigravityTurnedAway(p, request.System, string(b)) + if turnedAway { msg += " — " + antigravityTurnedAwayHint markAntigravityTurnsAway(w) } @@ -4119,6 +4148,9 @@ func (s *Server) translate(w http.ResponseWriter, r *http.Request, p provider.Pr } keepRetry(w.Header(), res.Header, b) u.ErrType = provider.ErrorType(b) + if turnedAway { + u.ErrType = turnedAwayErrType + } return writeError(w, from, res.StatusCode, msg), msg } dec := decoder(actual) @@ -4155,8 +4187,12 @@ func (s *Server) translate(w http.ResponseWriter, r *http.Request, p provider.Pr return writeError(w, from, 502, msg), msg } if col.err != "" && !saidAnything(col.res.Parts) { - markAntigravityRefused(w, p, request.System, col.err) - return writeError(w, from, 502, p.Name+": "+col.err), col.err + said := col.err + if markAntigravityRefused(w, p, request.System, said) { + said += " — " + antigravityTurnedAwayHint + u.ErrType = turnedAwayErrType + } + return writeError(w, from, 502, p.Name+": "+said), said } if empty && !saidAnything(col.res.Parts) && answersNothing(col.res.Stop) { msg := p.Name + ": " + emptyReply diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index 69aaec83c..5c832c133 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -2915,6 +2915,7 @@ const I18N = { "sent to {api} with Auto's session token": "发往 {api},带 Auto 的会话令牌", "Copilot refused it: {error}": "Copilot 拒绝了它:{error}", "WorkBuddy refuses chats from Codex and Claude Code (their system prompt); use it from Hermes, OpenCode or Pi, or add another provider to this group": "WorkBuddy 会因系统提示词拒绝 Codex 和 Claude Code 的对话;请在 Hermes、OpenCode 或 Pi 中使用,或在此分组中再加一个供应商", + "Antigravity answers this 429 to the system prompt of Claude Code and the Claude Agent SDK (Claude Desktop's chats) whatever quota is left, so it is not a quota and waiting won't help; use another provider for these chats, or put one after Antigravity in a routing group": "Antigravity 对 Claude Code 和 Claude Agent SDK(Claude Desktop 的对话)的系统提示词都会回这个 429,与剩余额度无关,所以这不是额度用尽,等待也不会好;请用其他供应商处理这些对话,或在路由分组中把另一个供应商排在 Antigravity 之后", "the provider's network firewall blocked requests from this IP; wait a while, or switch to another network or proxy": "供应商的网络防火墙拦截了此 IP 的请求;请稍后再试,或更换网络或代理", "ZCode's Start Plan still turned this request away, though magpie sends it as the ZCode app does; it can be a network block of this IP, or ZCode checking for something new. Use an account with a GLM Coding Plan, or add another provider to this group": "ZCode 体验套餐仍拒绝了此请求(已按 ZCode 客户端方式发送);可能是此 IP 被网络拦截,或 ZCode 新增了校验。请改用有 GLM Coding Plan 的账号,或在此分组中加入其他供应商", "Show the latest request that failed": "查看最近一个失败的请求", @@ -6764,6 +6765,7 @@ const I18N = { "sent to {api} with Auto's session token": "發往 {api},帶 Auto 的會話令牌", "Copilot refused it: {error}": "Copilot 拒絕了它:{error}", "WorkBuddy refuses chats from Codex and Claude Code (their system prompt); use it from Hermes, OpenCode or Pi, or add another provider to this group": "WorkBuddy 會因系統提示詞拒絕 Codex 和 Claude Code 的對話;請在 Hermes、OpenCode 或 Pi 中使用,或在此分組中再加一個供應商", + "Antigravity answers this 429 to the system prompt of Claude Code and the Claude Agent SDK (Claude Desktop's chats) whatever quota is left, so it is not a quota and waiting won't help; use another provider for these chats, or put one after Antigravity in a routing group": "Antigravity 對 Claude Code 和 Claude Agent SDK(Claude Desktop 的對話)的系統提示詞都會回這個 429,與剩餘額度無關,所以這不是額度用盡,等待也不會好;請用其他供應商處理這些對話,或在路由分組中把另一個供應商排在 Antigravity 之後", "the provider's network firewall blocked requests from this IP; wait a while, or switch to another network or proxy": "供應商的網路防火牆攔截了此 IP 的請求;請稍後再試,或更換網路或代理", "ZCode's Start Plan still turned this request away, though magpie sends it as the ZCode app does; it can be a network block of this IP, or ZCode checking for something new. Use an account with a GLM Coding Plan, or add another provider to this group": "ZCode 體驗套餐仍拒絕了此請求(已按 ZCode 用戶端方式傳送);可能是此 IP 被網路攔截,或 ZCode 新增了驗證。請改用有 GLM Coding Plan 的帳號,或在此分組中加入其他供應商", "Show the latest request that failed": "檢視最近一個失敗的請求", @@ -10590,6 +10592,7 @@ const I18N = { "sent to {api} with Auto's session token": "{api} に送信(Auto のセッショントークン付き)", "Copilot refused it: {error}": "Copilot に拒否されました:{error}", "WorkBuddy refuses chats from Codex and Claude Code (their system prompt); use it from Hermes, OpenCode or Pi, or add another provider to this group": "WorkBuddy は Codex と Claude Code からのチャットを(そのシステムプロンプトが原因で)拒否します。Hermes、OpenCode、Pi から使うか、このグループに別のプロバイダを追加してください", + "Antigravity answers this 429 to the system prompt of Claude Code and the Claude Agent SDK (Claude Desktop's chats) whatever quota is left, so it is not a quota and waiting won't help; use another provider for these chats, or put one after Antigravity in a routing group": "Antigravity は Claude Code と Claude Agent SDK(Claude Desktop のチャット)のシステムプロンプトに対し、残りクォータに関係なくこの 429 を返します。クォータ切れではなく、待っても解決しません。これらのチャットには別のプロバイダを使うか、ルーティンググループで Antigravity の後に別のプロバイダを置いてください", "the provider's network firewall blocked requests from this IP; wait a while, or switch to another network or proxy": "プロバイダのネットワークファイアウォールがこの IP からのリクエストをブロックしました。しばらく待つか、別のネットワークやプロキシに切り替えてください", "ZCode's Start Plan still turned this request away, though magpie sends it as the ZCode app does; it can be a network block of this IP, or ZCode checking for something new. Use an account with a GLM Coding Plan, or add another provider to this group": "magpie は ZCode アプリと同じ方法で送っていますが、ZCode の Start Plan がこのリクエストを拒否しました。この IP がネットワークでブロックされているか、ZCode が新たなチェックを加えた可能性があります。GLM Coding Plan のあるアカウントを使うか、このグループに別のプロバイダを追加してください", "Show the latest request that failed": "最後に失敗したリクエストを表示", @@ -14433,6 +14436,7 @@ const I18N = { "sent to {api} with Auto's session token": "an {api} gesendet, mit Autos Sitzungstoken", "Copilot refused it: {error}": "Copilot lehnte es ab: {error}", "WorkBuddy refuses chats from Codex and Claude Code (their system prompt); use it from Hermes, OpenCode or Pi, or add another provider to this group": "WorkBuddy lehnt Chats von Codex und Claude Code ab (wegen ihres System-Prompts); nutzen Sie es aus Hermes, OpenCode oder Pi oder fügen Sie dieser Gruppe einen weiteren Anbieter hinzu", + "Antigravity answers this 429 to the system prompt of Claude Code and the Claude Agent SDK (Claude Desktop's chats) whatever quota is left, so it is not a quota and waiting won't help; use another provider for these chats, or put one after Antigravity in a routing group": "Antigravity beantwortet den System-Prompt von Claude Code und dem Claude Agent SDK (Chats in Claude Desktop) mit diesem 429, egal wie viel Kontingent übrig ist – das Kontingent ist also nicht aufgebraucht, und Warten hilft nicht; nutzen Sie für diese Chats einen anderen Anbieter oder setzen Sie in einer Routing-Gruppe einen hinter Antigravity", "the provider's network firewall blocked requests from this IP; wait a while, or switch to another network or proxy": "die Netzwerk-Firewall des Anbieters hat Anfragen von dieser IP blockiert; warten Sie eine Weile oder wechseln Sie Netzwerk oder Proxy", "ZCode's Start Plan still turned this request away, though magpie sends it as the ZCode app does; it can be a network block of this IP, or ZCode checking for something new. Use an account with a GLM Coding Plan, or add another provider to this group": "Der Start Plan von ZCode hat diese Anfrage dennoch abgewiesen, obwohl magpie sie wie die ZCode-App sendet; möglich sind eine Netzwerksperre dieser IP oder eine neue Prüfung durch ZCode. Nutzen Sie ein Konto mit GLM Coding Plan oder fügen Sie dieser Gruppe einen weiteren Anbieter hinzu", "Show the latest request that failed": "Letzte fehlgeschlagene Anfrage anzeigen", diff --git a/internal/gui/assets/routing.js b/internal/gui/assets/routing.js index 71aa14346..4298e7305 100644 --- a/internal/gui/assets/routing.js +++ b/internal/gui/assets/routing.js @@ -740,7 +740,10 @@ // what it says of ZCode's Start Plan turning a request away (#425, // provider.ZCodeStartBlockedHint), in place of BLOCKED const ZCODE_BLOCKED = "ZCode's Start Plan still turned this request away, though magpie sends it as the ZCode app does; it can be a network block of this IP, or ZCode checking for something new. Use an account with a GLM Coding Plan, or add another provider to this group"; - const HINTS = [WB_REFUSED, BLOCKED, ZCODE_BLOCKED]; + // what it adds to Antigravity's 429 for Claude Code's and the Agent SDK's + // system prompt (antigravityTurnedAwayHint, #666, #1425) + const AG_TURNED_AWAY = "Antigravity answers this 429 to the system prompt of Claude Code and the Claude Agent SDK (Claude Desktop's chats) whatever quota is left, so it is not a quota and waiting won't help; use another provider for these chats, or put one after Antigravity in a routing group"; + const HINTS = [WB_REFUSED, BLOCKED, ZCODE_BLOCKED, AG_TURNED_AWAY]; function trySaid(r, i) { const tr = r.tries[i], w = tried(r, tr), agent = agentName(r.agent); diff --git a/internal/gui/tests/routing-ag-turned-away.test.cjs b/internal/gui/tests/routing-ag-turned-away.test.cjs new file mode 100644 index 000000000..f721f0302 --- /dev/null +++ b/internal/gui/tests/routing-ag-turned-away.test.cjs @@ -0,0 +1,110 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// Antigravity's 429 "Resource has been exhausted" for Claude Desktop's chat +// (Claude Code's and the Agent SDK's system prompt, #666), with quota to +// spare (#1425): the Routing page told it as "429 · quota used up" and the +// account's tally as quota used up, while magpie's own note said it isn't +// one. It is told as the agent's prompt turned away, in the request's row, +// its story and the account's tally, with the 400 the agent got; the +// vendor's words are said apart from magpie's note, which is in the page's +// language. +const assert = require("node:assert/strict"); +const fs = require("node:fs/promises"); +const path = require("node:path"); +const { test } = require("node:test"); +const { chromium, webkit } = require("playwright"); + +const assets = path.resolve(__dirname, "../assets"); +const now = new Date(); +const day = [now.getFullYear(), now.getMonth() + 1, now.getDate()].map((n) => String(n).padStart(2, "0")).join("-"); +const at = (i) => new Date(now.getTime() - (i + 1) * 60e3).toISOString(); +const hint = "Antigravity answers this 429 to the system prompt of Claude Code and the Claude Agent SDK (Claude Desktop's chats) whatever quota is left, so it is not a quota and waiting won't help; use another provider for these chats, or put one after Antigravity in a routing group"; +const vendor = "Antigravity: Resource has been exhausted (e.g. check quota)."; +const key = { id: "antigravity@u@example.com", provider: "antigravity", name: "Antigravity", kind: "account", who: "u@example.com", model: "gemini-3.8-flash" }; +// as the gateway now traces it: the try Antigravity's 429, told as the +// agent's prompt turned away, not resting; the request the 400 the agent got +const error = vendor + " — " + hint; +const routes = [0, 1].map((i) => ({ + id: 100 - i, seq: 100 - i, time: at(i), agent: "claude-desktop", model: "antigravity/gemini-3.8-flash", provider: "antigravity", + order: [key], tries: [{ id: key.id, model: key.model, start: at(i), done: true, status: 429, ms: 400, error, fail: "prompt", effort: "high" }], + done: true, status: 400, ms: 400, error, effort: "high", +})); + +function serve(lang) { + const state = { agents: [{ id: "claude-desktop", name: "Claude Desktop", path: "/test/config.json", fields: [] }], profiles: [], settings: { lang, theme: "light" } }; + return async (route) => { + const url = new URL(route.request().url()); + const json = (data) => route.fulfill({ json: data }); + if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` }); + if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" }); + if (url.pathname === "/api/state") return json(state); + if (url.pathname === "/api/plugins") return json({ plugins: [] }); + if (url.pathname === "/api/gateway/trace") { + if (url.searchParams.get("wait")) await new Promise((r) => setTimeout(r, 20e3)); + return json({ mine: true, now: now.toISOString(), seq: 1, totals: { requests: 0, rerouted: 0, errors: 0 }, routes: [] }); + } + if (url.pathname === "/api/gateway/history") { + const d = url.searchParams.get("day"); + return json({ cut: false, days: [{ day, requests: routes.length }], routes: d ? routes : [] }); + } + if (url.pathname === "/api/groups") return json({ groups: [] }); + if (url.pathname === "/api/providers") return json({ providers: [], gateway: { running: true, window: true } }); + if (url.pathname.startsWith("/api/")) return json({}); + const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname); + const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)]; + await route.fulfill({ body: await fs.readFile(file), contentType }); + }; +} + +const want = { + en: { said: "It said: " + vendor, hint, fail: "agent's prompt turned away", quota: "quota used up" }, + zh: { said: "原话:" + vendor, hint: "Antigravity 对 Claude Code 和 Claude Agent SDK(Claude Desktop 的对话)的系统提示词都会回这个 429,与剩余额度无关,所以这不是额度用尽,等待也不会好;请用其他供应商处理这些对话,或在路由分组中把另一个供应商排在 Antigravity 之后", fail: "Agent 的提示词被拒", quota: "额度用尽" }, + "zh-TW": { said: "原話:" + vendor, hint: "Antigravity 對 Claude Code 和 Claude Agent SDK(Claude Desktop 的對話)的系統提示詞都會回這個 429,與剩餘額度無關,所以這不是額度用盡,等待也不會好;請用其他供應商處理這些對話,或在路由分組中把另一個供應商排在 Antigravity 之後", fail: "Agent 的提示詞被拒", quota: "額度用盡" }, + ja: { said: "メッセージ:" + vendor, hint: "Antigravity は Claude Code と Claude Agent SDK(Claude Desktop のチャット)のシステムプロンプトに対し、残りクォータに関係なくこの 429 を返します。クォータ切れではなく、待っても解決しません。これらのチャットには別のプロバイダを使うか、ルーティンググループで Antigravity の後に別のプロバイダを置いてください", fail: "エージェントのプロンプトを拒否", quota: "クォータ切れ" }, + de: { said: "Meldung: " + vendor, hint: "Antigravity beantwortet den System-Prompt von Claude Code und dem Claude Agent SDK (Chats in Claude Desktop) mit diesem 429, egal wie viel Kontingent übrig ist – das Kontingent ist also nicht aufgebraucht, und Warten hilft nicht; nutzen Sie für diese Chats einen anderen Anbieter oder setzen Sie in einer Routing-Gruppe einen hinter Antigravity", fail: "Prompt des Agenten abgelehnt", quota: "Kontingent aufgebraucht" }, +}; + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + for (const lang of Object.keys(want)) { + test(`${engine} ${lang}: Antigravity turning Claude Desktop's prompt away isn't a quota`, async (t) => { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + const context = await browser.newContext({ viewport: { width: 1100, height: 760 }, reducedMotion: "reduce" }); + const page = await context.newPage(); + page.setDefaultTimeout(5000); + const errors = []; + page.on("pageerror", (e) => errors.push(e.message)); + await page.route("**/*", serve(lang)); + t.after(async () => { + if (process.env.ARTIFACT_DIR) { + await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true }); + await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-ag-turned-away.png`), fullPage: true }); + } + await browser.close(); + }); + await page.goto("http://magpie.test/?view=routing"); + await page.locator(".rt-days .rt-day").nth(1).click(); + await page.locator(".rt-req").nth(routes.length - 1).waitFor(); + const w = want[lang]; + + // the request's row: the 400 the agent got, the prompt turned away + const row = page.locator(".rt-req").nth(0); + const rowText = await row.textContent(); + assert(rowText.includes("400 · " + w.fail), rowText); + assert(!rowText.includes(w.quota), rowText); + + // the account's tally: turned away twice, no quota used up + const tally = await page.locator(".rt-acts").textContent(); + assert(tally.includes("2 " + w.fail), tally); + assert(!tally.includes(w.quota), tally); + + await row.click(); + await page.waitForTimeout(400); + const got = await page.locator(".rt-steps li").evaluateAll((ls) => ls.map((l) => [l.className, l.textContent])); + // the vendor's words as they were, without magpie's note in them + assert.deepEqual(got.filter(([c]) => c === "aside said").map(([, s]) => s), [w.said]); + // and the note on its own line, in the page's language + assert.deepEqual(got.filter(([, s]) => s === w.hint).map(([c]) => c), ["aside"]); + assert(!got.some(([, s]) => s !== w.hint && s.includes(w.quota)), JSON.stringify(got)); + assert.deepEqual(errors, []); + }); + } +}