Skip to content

fix(antigravity): align shared quotas with generation and keep header waits alive - #8226

Open
baryon wants to merge 2 commits into
Wei-Shaw:mainfrom
baryon:contrib/antigravity-quota-header-fix
Open

baryon wants to merge 2 commits into
Wei-Shaw:mainfrom
baryon:contrib/antigravity-quota-header-fix

Conversation

@baryon

@baryon baryon commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Antigravity Gemini usage can stay at 0% (or a stale weekly value) while generation consumes a different endpoint's quota. Separately, large streaming requests can hit a reverse proxy's 60-second idle timeout before upstream response headers arrive, before the existing stream-reader keepalive starts.

This PR completes the earlier quota-display work in #8157 and adds the missing response-header keepalive stage. It is built directly on upstream main at 8f2cbb53d; it does not merge the fork's main branch.

Quota behavior

  • Read both fetchAvailableModels and retrieveUserQuotaSummary from resolveAntigravityForwardBaseURL(account), following the endpoint-alignment approach in @Achordchan's fix(antigravity): fetch quotas from the forwarding endpoint #8214. A successful response from another endpoint must not conceal the selected endpoint's quota or errors; fixed-endpoint probes do not redirect or fall back across endpoints.
  • Render separate Gemini and Claude/GPT shared pools for the 5-hour and weekly windows. Continue to use used percentage, skip disabled buckets, and retain model-level fallback when quota summary retrieval is unavailable.
  • Include Gemini 4 Argon / current Gemini variants and Claude 5.5 in the legacy display fallback and rate-limit labels.

The endpoint mismatch was observed with one paid account using the same token/project: prod returned Gemini weekly used 7.004% / 5h 0%, while daily returned 37.684% / 5h 2.902%. Claude values agreed across endpoints. No credentials or account-specific configuration are included.

Streaming behavior

  • For Responses and Chat Completions streaming requests, flush SSE comment keepalives while each upstream HTTP request waits for response headers. Default interval is 15 seconds, or the shorter configured stream keepalive interval.
  • Keep all Gin response writes on the calling goroutine. Cancel abandoned requests, close late responses, and preserve the successful response body's context until it is closed.
  • Once a keepalive commits HTTP 200, report later HTTP/transport/account-switch failures as SSE errors. Do not return an account failover signal that the protocol handler would turn into a silent EOF.
  • Preserve the non-streaming response contract.

This extends #7643 / #7637, which handle silence after upstream headers have been received. The motivating production trace showed repeated approximately 34 MB requests failing at 60 seconds with Nginx upstream timed out ... while reading response header; a small request on the same account succeeded in 5.7 seconds.

Relationship to existing work

Validation

On this clean upstream-based branch:

  • Regression tests first reproduced paid/daily/sandbox quota endpoint failures and response-header silence. A separate failing regression reproduced silent failover after a committed keepalive, then passed with the fix.
  • go test -tags=unit ./internal/pkg/antigravity -count=1
  • Targeted service tests covering quota fetching, normalization, existing compatibility streams, response-header waits, cancellation/late-response cleanup, and committed HTTP/account-switch errors.
  • go test -race -tags=unit for the new quota endpoint cases and header keepalive/error/cancellation cases.
  • Relevant protocol-handler failover/committed-response tests.
  • go vet ./internal/pkg/antigravity ./internal/service ./internal/handler and go build ./cmd/server.
  • Frontend locale completeness, vue-tsc -b, vite build, and ESLint on changed production frontend files.
  • Manual Chromium review using the actual Vue components with controlled quota data: four buckets, exhausted weekly pools without misleading 5h bars, Gemini 4 / Claude 5.5 legacy fallback, error state, and light/dark rendering in normal and 320px-wide containers. No overflow observed. The temporary preview is not committed.
  • Independent code review completed; git diff --check passed.

The quota/header fixes were deployed in the fork and passed service health checks; the original large production conversation has not been replayed after deployment. The pre-existing two-minute first-content limit is unchanged (checked by the stream reader after headers arrive). This PR does not add keepalives during retry backoff or change that timeout policy.

…K-110)

Use the selected generation endpoint for both quota APIs; keep streaming clients alive before response headers and report committed failures through SSE instead of silent failover EOF.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Antigravity配额探测固定请求cloudcode-pa生产域名,与实际流量转发域名不一致导致Gemini额度恒显0%且无法感知限流

1 participant