Stalled uploads to /v1/tts, /v1/stt and /v1/custom-voices reach GrokVoice
directly. Its read errors fell through to a 400 carrying err.Error(): with
the read timeout now preserved, that reported a timeout as a malformed
request and returned the raw socket error. Keep the validation message for
a missing body and send every read error through the shared classifier.
Upstream added WithBodyReadTimeout (gateway.request_body_read_timeout_seconds)
and client-gone handling for body reads. Drop this branch's own server-level
idle-timeout wrapper and server.request_body_idle_timeout setting in favor of
it, and keep the classification and diagnostics on top:
- readRequestBodyChunksWithBudget reports the read error before ctx.Err():
on HTTP/1 a read deadline also cancels the request context, which turned
every timeout into context.Canceled. Read errors carry bytes read and
elapsed time in RequestBodyReadError.
- handleRequestBodyReadError and RejectRequestBodyReadError skip the
client-gone (empty 499) path for read timeouts, so they are reported as
408 instead of a client cancellation (HTTP/1) or a generic 400 (HTTP/2).
- Every gateway body read site and both body-reading middlewares log
payload-free diagnostics, including the client-gone path.
OpenAI scheduling now reads the privacy gate from the auth snapshot; cover
the GetByKeyForAuth projection so a dropped column fails here instead of
admitting accounts without privacy set.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
FilterThinkingBlocks runs on every Anthropic forward. Its substring fast path
matches any request with top-level thinking config or signed thinking
history, which is nearly all Claude Code traffic, so it decoded the whole body
into a map even when nothing would be filtered.
Mirror the filter decision on borrowed gjson views, applying encoding/json's
last-wins rule for duplicate keys, and return the body untouched when no block
would be dropped. Bodies that need filtering still take the original decode
and marshal path, so output bytes are unchanged; a differential test and fuzz
target compare both paths.
On a 450 KB signed history: 1.29 ms, 904 KB, 10,629 allocs -> 0.67 ms, 0 B.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every /v1/responses request ran the automation and delegation bootstrap
normalizers, each a json.Decoder token scan plus a full map decode, and
NormalizeCompactionTriggerInputOrder decoded the whole body on each HTTP
request and WebSocket turn, although almost none of them can change it.
- Bootstrap normalizers return early unless the raw body contains
function_call_output and one of their tool names, or any \u escape that
could spell them.
- The compaction normalizer returns early when the body has neither
compaction_trigger nor a \u escape and is a valid JSON object, so invalid
or non-object bodies still report the original decode error.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
computeGeminiTextDelta returned seen+incoming for each incremental chunk, so
a long thinking, text or tool-argument block copied its whole prefix per
chunk and grew quadratically.
Keep the emitted text in a strings.Builder per block. Only storage changes:
the cumulative, duplicate/rewind and delta decisions and the returned deltas
are identical, verified against the previous implementation.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Gemini native, Claude-compat, Chat Completions-compat and stream collector
paths read upstream SSE with bufio.Reader.ReadString, so a custom base_url
upstream that never sends a newline could grow one line without limit.
- Read these streams through boundedSSELineReader, which keeps line endings
and EOF semantics and enforces the configured line and event limits. An
overflow is a stream read error; no truncated prefix is forwarded.
- Thread cfg into collectGeminiSSE/collectGeminiSSEObserved.
- Antigravity ForwardUpstream reads non-stream responses with
ReadUpstreamResponseBody instead of an unlimited io.ReadAll.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each OpenAI account selection read the group row twice: once to resolve
require_privacy_set into the request, and again in selectByLoadBalance,
which ignored that result.
- Project require_privacy_set into the auth snapshot (v27) and resolve it
from the ctx group when it is the scheduled group; composite members and
other mismatches still read the repository.
- selectByLoadBalance filters on the already-resolved req.RequirePrivacySet,
so a failed group read is handled once, fail-closed, as in Select.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The auth snapshot stored "no override" and "lookup failed" both as nil, so
checkRPM fell back to SELECT rpm_override on nearly every gateway request.
Record the group whose override lookup succeeded (snapshot v26). checkRPM
trusts a nil override only for that group; lookup failures and other groups,
such as composite members, still query the database. Admin override writes
already invalidate the auth cache by group.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The decoder allocated total_length bytes straight from the upstream prelude
(up to ~4 GiB) and sliced headers by an unchecked headers_length, which could
panic in the decode goroutine outside gin's recovery and crash the process.
Reject frames whose headers exceed 128 KiB or the frame, or whose payload
exceeds 16 MiB (the AWS EventStream protocol limits), before allocating.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Async tasks inherited the ingress reservation through context.WithoutCancel,
but RequestBodyLimit releases and closes it when Submit returns. The task's
request body was a plain reader, so the gateway's read reserved against the
closed reservation and every task failed with a 503 budget error.
- Add httputil.DetachRequestBodyMemory: a reservation on the same budget that
the handler's release does not close. It takes over the retained body's
existing charge from the request and reserves only the remainder, so the
body is never counted twice; the caller releases it when the work ends.
- Submit reserves the retained body before creating the task, returning 503
with Retry-After on exhaustion instead of accepting a task that cannot run;
the task releases it when execution finishes.
- Back the task request with PrereadBody so the body is not buffered again.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- ApplyPatches reserves the input size before editing on every strategy
(batched Doc, single edit, sequential sjson), settles to the exact output
length, and refunds on failure, so batching no longer adds a rejection
that the unoptimized paths bypass.
- Forward holds patched outputs in a WithRequestBodyMemoryScope: a newer
output releases the superseded one and the last is returned when the
attempt ends, instead of accumulating across failovers until the handler
returns.
- A Doc edit error retries with sequential sjson; when raw edits cannot
express the patch set, Forward replays it onto the decoded map rather than
re-running ApplyPatches and failing the request.
- Snapshot reuse in CloneForBody/ReplaceBody also checks a maphash content
fingerprint, so in-place edits of shared storage reparse.
- Reuse openAIWSPayloadStringView for borrowed views and split batch path
eligibility into isOpenAIBatchPatchPath with an O(P^2) ancestor check.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Capture weekly usage headers independently of 5h status and before 429 window handlers return. Reuse passive snapshots for Anthropic setup-token usage queries, with regression coverage for weekly/Fable windows and existing cooldowns.
Every other platform's account test sends the admin's prompt (default "hi") and returns the
model's reply. The Antigravity text and Claude tests sent "." with a 1-token output cap and
ignored the prompt, so the UI showed "sent: hi" with an empty response, and thinking models
(gemini-4-argon, gemini-3.8-flash) spent the one token thinking. They now send the prompt (or
"hi") with 256 output tokens.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pro accounts report a third quota group, gemini-argon-wtu ("For paid Pro plans, Argon
quota is separate", weekly only). It was labelled like the Claude/GPT group, so the cell
showed C·weekly twice. It now shows as A·weekly.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An INTERNAL 500 that survives every retry put the whole antigravity account
in the progressive penalty (30 min, 2 h, then disabled), whatever model failed.
The image endpoint (gemini-3.1-flash-image) returns this 500 far more often
than text models, so one failing image request took the account's text models
(gemini-4-argon, gemini-3.8-flash) offline for 30 minutes, and repeats could
disable the account.
- An INTERNAL 500 on an image model now cools only that model (model-level
rate limit, default 2 min, GATEWAY_ANTIGRAVITY_INTERNAL500_IMAGE_COOLDOWN_SECONDS)
and does not count toward the account penalty.
- The account penalty tiers can be set per deployment:
GATEWAY_ANTIGRAVITY_INTERNAL500_TIER1_SECONDS, ..._TIER2_SECONDS and
GATEWAY_ANTIGRAVITY_INTERNAL500_DISABLE_ACCOUNT (false repeats tier 2 instead
of disabling). Unset, every value is the previous default.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fetchAvailableModels reports one remainingFraction per model, whichever window is
tighter at the moment, so the 5-hour and the weekly limit could not be told apart:
a used-up weekly limit showed as "5h 99%" with a reset days away. The quota fetcher
now also calls v1internal:retrieveUserQuotaSummary, which reports every window of
every group (Gemini models; Claude and GPT models), and returns it as
antigravity_quota_groups. The account usage cell shows G·5h / G·weekly and
C·5h / C·weekly from it, and keeps the per-model bars when the summary is missing.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Problem: on a WS v2 passthrough connection only the first turn gets a
first_token_ms. The per-turn value was stamped in two places: together
with the connection-level first token (which only happens once per
connection), or when the token event itself carries response.id. Token
events (*.delta, response.output_text.done,
response.function_call_arguments.done) never carry response.id, so from
the second turn on every usage log and every scheduler TTFT sample of a
long-lived Codex connection is nil.
Fix: resolve the turn first (by response.id, otherwise the active turn)
and stamp that turn's first token from its own start time. The
connection-level first token is unchanged.
Test: TestRelay_OnTurnComplete_FirstTokenMsRecordedForEveryTurn replays
two real-shaped turns on one connection (deltas without response.id) and
expects each turn's first token to be measured from its own start. It
fails on the second turn without the fix.