From 3ebb1ba2cb420a5efd4b8d940a005ae8d464795d Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 11 Nov 2026 03:54:15 +0800 Subject: [PATCH] gateway: Antigravity's refused lines get two zero-width spaces a word, not one after the first letter (shzutbi1 on X) Claude Code's chats on Antigravity answered 429 "Resource has been exhausted" again. Reproduced on the owner's real Antigravity account with Claude Code 2.1.316's own system blocks (claude -p captured through a local server): both x-anthropic-billing-header and "built on Anthropic's Claude Agent SDK" are still turned away, and the first-letter break the cloak made ("x", U+200B, "-anthropic...", "b", U+200B, "uilt on ...") is turned away too, so the cloak did nothing. Bisected on the account: a break after the second character, two breaks, or a break in each word of the line go through (3 of 3 each); a break after the third character of "x-a" does not. Codex's and Hermes' lines now go through as written. antigravityCloak now puts a zero-width space after the first and the second character of every run of three or more letters or digits in each matched line. The full captured Claude Code prompt with that transform was answered 3 of 3 on the real account. The refusal is still told against the prompt as written (hint, 400, no rest), unchanged. Run: go test -run Antigravity ./internal/gateway on mote (ok), gofmt, go vet darwin, linux nogui, windows. New TestAntigravityCloakClaudeCode2316 pins the real prompt's output. antigravity_codex_test.go and the Codex check in antigravity_cloak_test.go read the sent prompt past the breaks. The old test expectation (first letter only) was changed, not broken by hand: the old code can't compile against the new helper. Not run: the full suite (started after the tag), a sandbox magpie binary (the transform was sent through the live gateway's real account), Hermes and Codex lines against the real account beyond "as written goes through". The community plugins carry the same cloak and are fixed in magpie-community/plugins (antigravity 0.1.1, antigravity-cloak 0.1.3). --- docs/subsystems/gateway-routing.md | 2 +- internal/gateway/antigravity_cloak_test.go | 48 ++++++++++++++++-- internal/gateway/antigravity_codex_test.go | 2 +- internal/gateway/codeassist.go | 59 +++++++++++++++++----- 4 files changed, 92 insertions(+), 19 deletions(-) diff --git a/docs/subsystems/gateway-routing.md b/docs/subsystems/gateway-routing.md index 61d6910bd..9d1f11de5 100644 --- a/docs/subsystems/gateway-routing.md +++ b/docs/subsystems/gateway-routing.md @@ -352,7 +352,7 @@ recorded as a prediction failure (`noPrediction`). - Claude Desktop's check that a gateway model answers (`{"max_tokens":1,"messages":[{"role":"user","content":"."}]}`, sent as it starts and by its settings' Test connection on the shortest id it is listed with haiku in it, else sonnet, else opus, else the first model listed; `desktopProbe` in [`desktop.go`](../../internal/gateway/desktop.go)) goes to the model the user chose in one of Desktop's own model menus that magpie still serves (`desktopChosen`: `__model_selector_state` in Claude-3p's `local-agent-mode-sessions///cowork_account_settings.json`, in the order Code, Cowork, Chat; cybercaius's DeepSeek in the Code tab, v0.1.2033), unless a session's turn was sent after that file was last written: then the model that turn was for (`desktopPicked`), while magpie serves it, the newer of the two being what the user is on now (before, the last session's model came first whenever any menu still held it, so the Code tab switched off DeepSeek with Cowork left on it kept the check on DeepSeek, cybercaius on Discord, v0.1.2212), else to Desktop's default model, the first one listed to it (`desktopDefault`; Desktop's own settings call the first listed model the default), never to the haiku it names, which is another provider's quota, nor, with no menu chosen, to the model the last session ran on (`desktopPicked`), which can be days old: v0.1.1821 sent it there, a relay's GPT model CyberCaius had left for his routing group, and the relay turned it away (Discord, v0.1.1838). It is asked for 16 tokens upstream (`desktopProbeTokens`): OpenAI's models refuse fewer, and a relay in front of one (AnyRouter's "bad response status code 400") passes on no floor for `tokenFloor` to ask again at. A relay that needs `prompt_cache_key` gets one (above). It is recorded with kind `connection_check` (`KindDesktopCheck`), which the Routing page tags "Connection check" with why its model is the id Desktop named and not the one chosen in the conversation: a list with no Claude-named id made the row read "requested deepseek-flash" while the menu's gpt-6.1-sol answered (cybercaius on Discord, v0.1.2212). `TestClaudeDesktopProbeToDefaultModel`, `TestClaudeDesktopProbeToChosenModel`. `TestClaudeDesktopProbeAsksNoClassifier` checks the kind. - Claude Desktop's `/v1/models` tags a model with `anthropic_family_tier` only when the user picked it for that tier (`DesktopTiers`, the Agents page's opus, sonnet, haiku and fable). Before, a Claude model magpie served was tagged with its own tier unpicked, so Desktop's Code tab told Claude Code to run its haiku calls (its small, fast model) on whichever provider served a `claude-haiku-…`: a chat on AgentRouter's gpt-6.1-sol sent them to Leee's `claude-haiku-5-5` (cybercaius on Discord). Untagged, Claude Code asks for its own id of the tier. A background call (no tools) or a subagent's turn asking for a Claude model by Claude's own id that is no catalog id (`claudeOwnID`) stays on the chat's provider (`desktopPicked`), even when another provider serves a model of that name: `servedBeside` gives that provider's model of that name, else its newest model of the tier, beside the chat's model first, else the call goes to the chat's model. The provider's Claude models stand in only when the chat itself is on one of them: a chat on Leee's DeepSeek had Claude Code's sonnet calls sent to Leee's `claude-sonnet-5-5`, which its key may not use (403, CyberCaius on Discord), so Claude Code's own calls in a chat on another vendor's model go to the chat's model, and a tier the user picked takes Claude Code's own id of it even where a provider lists a model by that name (`TestClaudeDesktopNonClaudeChatKeepsTierCalls`). A lead's turn and an id the user picked for a tier (a catalog id) go as asked. `TestClaudeDesktopBackgroundStaysOnChatProvider`. - While a model is picked for one of Claude Desktop's tiers, magpie's Desktop profile also lists Desktop's models in `inferenceModels` (`DesktopInferenceModels` in [`desktop_list.go`](../../internal/gateway/desktop_list.go)), so a pick that isn't a Claude model runs in the Code tab with the prompt of its tier's newest Claude model (`behavesAs`: `claude-opus-5-5`, `claude-sonnet-5-5`, `claude-haiku-5-5`, Desktop's catalog v3739; `claude-fable-5-2`, Claude Code 2.1.321's newest Fable, which Desktop's catalog v4371 doesn't list yet), not Claude Code's generic one (moer2831 on Discord). Desktop 4.29 and later hand Claude Code `behavesAs` only from that list (z3t in its app.asar, 4.4212: `modelPicker.options` with each entry's `behavesAs`); the gateway's `behaves_as` row field feeds Desktop's own effort profile only. A non-empty list replaces `/v1/models` in Desktop's menus (pzn: a discovered row gives only its name and description, by id), so the list is every row `/v1/models` gives Desktop, by its id and in its order, each with what Desktop would have read off the row: `supports1m` for a window of 1M and up, `prefer1m` (and the row's `display_name` as `labelOverride`, where Desktop names the row by display_name) for a model listed by its `[1m]` id, and a pick's `anthropicFamilyTier` with `isFamilyDefault`. Desktop keys the list by name and reads one tier off an entry (FPn in its app.asar, 4.23118: the entry tagged with a tier names its `ANTHROPIC_DEFAULT__MODEL`), so a model picked for two tiers is tagged with the first (`desktopTierOf`) and listed once more, after the rows, for each later tier (`desktopSharedTiers`), by its id's form under a number of its own (`desktopTierAlias`: magpie-.anthropic., mythos-magpie- or anthropic/magpie-), which `aliased` reads back to the model, so the gateway serves it as the pick (`desktopTierAsked`). Before, the later tier had no model: copilot/claude-sonnet-5.5 picked for sonnet and haiku gave Claude Code an empty `ANTHROPIC_DEFAULT_HAIKU_MODEL`, and its small tasks, WebFetch's page summaries among them, ran on the session's model. The rows stay first, so a new session still starts on the first row. A Claude model picked runs as itself where Claude Code knows it by the id it is listed by; a routing group led by one is listed by its mythos-magpie- and runs as the group's model, as one listed by anthropic/magpie- does (`desktopRunsAs`; `TestDesktopTierSharedPick`, `TestDesktopGroupPickRunsAsItsModel`). Nothing picked (or a pick of a model no longer listed): no list, and Desktop finds the models as before. Picks that can't be read are unknown, and what is written stays. Older builds take the entries' names and drop the rest (2.7032's entry is a zod object, which strips unknown keys). Desktop reads its profile only as it starts, so the tiers' menu says to restart it, and the Agents row's Restart shows (`AppBehind` reads the profile). `TestDesktopInferenceModels`. -- Antigravity answers a system instruction holding one of a few lines with a 429 "Resource has been exhausted" whatever quota is left, on every model (`agTurnedAway` in [`codeassist.go`](../../internal/gateway/codeassist.go)): Claude Code's billing line, the Claude Agent SDK's identity line, Codex's identity lines for its GPT-5 models (which a Codex thread begun on a GPT model keeps after a switch), and Hermes Agent's earlier default persona. An Antigravity account's system instruction goes with a zero-width space after each such line's first letter (`antigravityCloak`, in `codeAssistBody`), which Google lets through and the model reads the same; every other provider, Gemini CLI's sign-in on the same envelope included, is sent the prompt as written. `magpie provider set antigravity prompt=as-written` (`Provider.PromptAsWritten`) turns it off. The refusal is still told against the system prompt as the agent wrote it (`antigravityTurnedAway`): a 400 with the hint for that prompt, the account not rested, and a group skipping Antigravity for that prompt for 6 hours after a refusal (`antigravityForeseen`). +- Antigravity answers a system instruction holding one of a few lines with a 429 "Resource has been exhausted" whatever quota is left, on every model (`agTurnedAway` in [`codeassist.go`](../../internal/gateway/codeassist.go)): Claude Code's billing line, the Claude Agent SDK's identity line, Codex's identity lines for its GPT-5 models (which a Codex thread begun on a GPT model keeps after a switch), and Hermes Agent's earlier default persona. An Antigravity account's system instruction goes with zero-width spaces after the first and second character of every word of each such line (`antigravityCloak`, in `codeAssistBody`; one after the first letter only was turned away again on 11-11 for Claude Code's two lines, with Claude Code 2.1.316's prompt on a real account), which Google lets through and the model reads the same; every other provider, Gemini CLI's sign-in on the same envelope included, is sent the prompt as written. `magpie provider set antigravity prompt=as-written` (`Provider.PromptAsWritten`) turns it off. The refusal is still told against the system prompt as the agent wrote it (`antigravityTurnedAway`): a 400 with the hint for that prompt, the account not rested, and a group skipping Antigravity for that prompt for 6 hours after a refusal (`antigravityForeseen`). - Claude Code's advisor (`/advisor`, `--advisor`) is Anthropic's server tool `advisor_20260301`, its `model` named as Claude Code names its own: on magpie, by magpie's id (the tier an alias like `opus` is on), which no vendor knows, so the request was turned away whole (JackChou on Discord). Relayed on Messages (`passthrough`), the advisor's model goes as the upstream's own name for it when it is the same provider's Claude model, or a Claude id naming no provider (`advisorTools` in [`advisor.go`](../../internal/gateway/advisor.go)); one it can't run there (another provider's, a group, not Claude's) is left out, as is every advisor when the request's own model isn't a Claude model (a vendor's Messages API knows no such tool), and the turn is answered without one. A translation drops it with every other server tool. Claude Code (2.1.300) also puts the advisor in the conversation: a `{role: "system"}` message whose text ends in its instructions ("# Advisor Tool … call advisor BEFORE substantive work") and a `tool_addition` naming it. Where the advisor is left out, that `tool_addition` goes too (and a message it leaves empty), and the instructions become Claude Code's own "The advisor tool is no longer available; disregard the earlier advisor instructions." (`withoutAdvisor` on Messages, `advisorGoneIn` in `parseAnthropic` for a translation): left there, the model called `advisor()` as one of the agent's tools and Claude Code answered "No such tool available: advisor" (JackChou on Discord). The Claude subscription's run declares only magpie's tools, so it never has one. `TestAdvisorModelAsTheUpstreamNamesIt`, `TestAdvisorLeftOutOnTranslation`. - Kiro is told where to cache the prompt (plugins#110: a Kiro subscription read 0 from its cache). Its API takes Bedrock's `cachePoint: {"type":"default"}` on a `userInputMessage`, an `assistantResponseMessage` or as a tool entry. The built-in (`buildKiro` in [`kiro.go`](../../internal/gateway/kiro.go)) marks the first message when there is a system prompt, which it folds into that message, and the current message, as `buildAnthropic` marks Anthropic's. A moved Kiro's plugin (opencode-kiro-auth 0.1.10, the mover's `min`) turns each `cache_control` in the Anthropic body it is handed into one, at most 4, the last kept. - The cache marks `buildAnthropic` adds for a Responses client (Codex) to a Claude model last an hour (`addedMark`, `Request.hourMarks`; 7eleven on Discord): Codex's turns are often more than five minutes apart, and Codex's own vendor keeps a thread cached an hour (`chatGPTCold`). A 1h write costs 2x the input price where Anthropic's default 5m costs 1.25x and a read 0.1x or less, so one turn read after a 5 to 60 minute pause, which a 5m mark would have written again, pays for the dearer writes of dozens of turns in quick succession. Every mark it adds has the same ttl, since Anthropic refuses a 1h mark after a 5m one. The client's `prompt_cache_retention: "in_memory"` keeps them at 5m. A Chat client's marks, a model that isn't Claude's, and marks a client placed itself (an Anthropic client's, relayed as sent) are unchanged. An upstream that answers 400 naming `cache_control` and `ttl` (a relay that knows no ttl) is asked again at 5m and remembered in `unfit` (`hourMarksRefused`) until magpie restarts. A Claude subscription is served by Claude Code, which asks 1h unless the user picked 5m ([Claude subscription bridge](claude-subscription-bridge.md)). `TestResponsesToClaudeMarksLastAnHour`, `TestHourMarksRefused`. diff --git a/internal/gateway/antigravity_cloak_test.go b/internal/gateway/antigravity_cloak_test.go index 48a254682..30cbb999c 100644 --- a/internal/gateway/antigravity_cloak_test.go +++ b/internal/gateway/antigravity_cloak_test.go @@ -27,6 +27,44 @@ var googleTurnsAway = []string{ "hermes agent, an intelligent ai assistant created by nous research", } +// brokenTwice is line with "|" after the first and the second character of +// each run of three or more ASCII letters or digits. +func brokenTwice(line string) string { + var b strings.Builder + for i := 0; i < len(line); { + j := i + for j < len(line) && agAlnum(line[j]) { + j++ + } + switch { + case j == i: + b.WriteByte(line[i]) + i++ + case j-i >= 3: + b.WriteString(line[i:i+1] + "|" + line[i+1:i+2] + "|" + line[i+2:j]) + i = j + default: + b.WriteString(line[i:j]) + i = j + } + } + return b.String() +} + +// Claude Code 2.1.316's own system blocks (claude -p, captured 11-11): the +// first is turned away, once broken after only its first letter. +func TestAntigravityCloakClaudeCode2316(t *testing.T) { + system := "x-anthropic-billing-header: cc_version=2.1.316.2e4; cc_entrypoint=sdk-cli;\nYou are a Claude agent, built on Anthropic's Claude Agent SDK.\n" + got := antigravityCloak(system) + want := "x-a|n|thropic-b|i|lling-h|e|ader: cc_version=2.1.316.2e4; cc_entrypoint=sdk-cli;\nYou are a Claude agent, b|u|ilt on A|n|thropic's C|l|aude A|g|ent S|D|K.\n" + if got != strings.ReplaceAll(want, "|", zeroWidth) { + t.Fatalf("went as %q", got) + } + if antigravityCloak(got) != got { + t.Fatal("broken again") + } +} + func TestAntigravityCloakBreaksEveryLineItTurnsAway(t *testing.T) { for _, system := range []string{ claudeCodeSystem, @@ -51,11 +89,13 @@ func TestAntigravityCloakBreaksEveryLineItTurnsAway(t *testing.T) { if !strings.Contains(got, zeroWidth) { t.Errorf("nothing broken up: %q", got) } - // nothing else: each break sits after a line's first letter + // nothing else: every run of three or more letters or digits in a + // line has a break after its first and its second character, the + // way Google's check lets through (11-11, a real account) low := strings.ToLower(strings.ReplaceAll(got, zeroWidth, "|")) for _, line := range googleTurnsAway { - if strings.Contains(strings.ToLower(system), line) && !strings.Contains(low, line[:1]+"|"+line[1:]) { - t.Errorf("%q isn't broken after its first letter in %q", line, got) + if strings.Contains(strings.ToLower(system), line) && !strings.Contains(low, brokenTwice(line)) { + t.Errorf("%q isn't broken after its first two characters in %q", line, got) } } if antigravityCloak(got) != got { @@ -155,7 +195,7 @@ func TestAntigravityAnswersHermesAndCodexByDefault(t *testing.T) { if code, out := codexAGPost(s, codexAGTurn(true, search)); code != 200 || !strings.Contains(out, "from google") { t.Fatalf("Codex's switched thread (search=%v): %d %s", search, code, out) } - if !strings.Contains(sent, "Y"+zeroWidth+"ou are Codex, an agent based on GPT-5") || antigravityTurnsAway(sent) { + if !strings.Contains(strings.ReplaceAll(sent, zeroWidth, "|"), brokenTwice("You are Codex, an agent based on GPT-5")) || antigravityTurnsAway(sent) { t.Fatalf("Codex's prompt went as %q", sent) } } diff --git a/internal/gateway/antigravity_codex_test.go b/internal/gateway/antigravity_codex_test.go index 4b06d647e..684cf50e7 100644 --- a/internal/gateway/antigravity_codex_test.go +++ b/internal/gateway/antigravity_codex_test.go @@ -96,7 +96,7 @@ func TestAntigravityTurnsCodexsGPT5ThreadAwayOnce(t *testing.T) { rec := httptest.NewRecorder() s.Handler().ServeHTTP(rec, httptest.NewRequest("POST", "/v1/responses", strings.NewReader(codexAGTurn(switched, search)))) code, out := rec.Code, rec.Body.String() - if !strings.Contains(system, "systemInstruction") || !strings.Contains(system, "an agent based on GPT-5") || search != strings.Contains(system, `"web_search"`) { + if !strings.Contains(system, "systemInstruction") || !strings.Contains(strings.ReplaceAll(system, zeroWidth, ""), "an agent based on GPT-5") || search != strings.Contains(system, `"web_search"`) { t.Fatalf("the prompt didn't go as the system instruction, so this isn't the case: %s", system) } if code != http.StatusBadRequest { diff --git a/internal/gateway/codeassist.go b/internal/gateway/codeassist.go index 5c3f5a906..b4f7ed956 100644 --- a/internal/gateway/codeassist.go +++ b/internal/gateway/codeassist.go @@ -89,13 +89,14 @@ func antigravityTurnsAway(system string) bool { // goes through, and so does today's "You are Hermes Agent, built by // Nous Research." // -// Each is broken up before it goes by a zero-width space after its first -// letter (antigravityCloak), which Google lets through: each line so -// broken ("Y", U+200B, "ou are Codex, an agent based on GPT-5"; "b", -// U+200B, "uilt on Anthropic's Claude Agent SDK"; and so on) was answered -// on a real account where the line as written was turned away. A mention -// of the Claude Agent SDK elsewhere ("running within the Claude Agent -// SDK") goes through as written, and is sent so. +// Each is broken up before it goes by zero-width spaces (antigravityCloak), +// which Google lets through. A break after only a line's first letter was +// turned away again on 11-11 for Claude Code's two lines, so each word has +// two. Codex's and Hermes' lines went through as written on 11-11 too, and +// are still broken up: that costs nothing and a Codex thread that is +// refused again says why. A mention of the Claude Agent SDK elsewhere +// ("running within the Claude Agent SDK") goes through as written, and is +// sent so. var agTurnedAway = []string{ "x-anthropic-billing-header:", "built on anthropic's claude agent sdk", @@ -123,11 +124,18 @@ func antigravityTurnsHermesAway(system string) bool { const zeroWidth = "\u200b" // antigravityCloak is system with each line of agTurnedAway in it broken up -// by a zero-width space after its first letter, wherever and in whatever -// case it is, and every other word as the agent wrote it: what an -// Antigravity account's system instruction is sent as, unless the user has -// it sent as written (Provider.PromptAsWritten). A line already broken up -// (the antigravity-cloak plugin's) isn't one any more and is left alone. +// by zero-width spaces, wherever and in whatever case it is, and every other +// word as the agent wrote it: what an Antigravity account's system +// instruction is sent as, unless the user has it sent as written +// (Provider.PromptAsWritten). Inside a line, every run of three or more +// letters or digits gets one after its first and one after its second +// character. One after the first letter only (what this did until 11-11) +// stopped working: Google's check then turned "x\u200b-anthropic-billing- +// header:" and "b\u200built on Anthropic's Claude Agent SDK" away again +// (a real account, Claude Code 2.1.316's prompt, @shzutbi1 on X), while the +// same lines with two breaks in every word were answered. +// A line already broken up (the antigravity-cloak plugin's) isn't one any +// more and is left alone. func antigravityCloak(system string) string { if !antigravityTurnsAway(system) { return system @@ -146,7 +154,7 @@ func antigravityCloak(system string) string { if j < 0 { break } - at = append(at, i+j+1) + at = append(at, agBreaks(low, i+j, i+j+len(line))...) i += j + len(line) } } @@ -164,6 +172,31 @@ func antigravityCloak(system string) string { return b.String() } +// agBreaks are the offsets in s[from:to] a zero-width space goes at: after +// the first and after the second character of every run of three or more +// ASCII letters or digits. +func agBreaks(s string, from, to int) []int { + var at []int + for i := from; i < to; { + j := i + for j < to && agAlnum(s[j]) { + j++ + } + if j-i >= 3 { + at = append(at, i+1, i+2) + } + if j == i { + j++ + } + i = j + } + return at +} + +func agAlnum(c byte) bool { + return 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z' || '0' <= c && c <= '9' +} + // asciiLower lower-cases only ASCII letters, keeping every byte where it is. func asciiLower(s string) string { b := []byte(s)