From cbfeab964ece18ed3b8e9610554f6c33237f17fb Mon Sep 17 00:00:00 2001 From: sweetcornna <96944678+sweetcornna@users.noreply.github.com> Date: Sat, 4 Jul 2026 17:09:16 +0800 Subject: [PATCH] fix(antigravity): default gateway forward base URL to the production endpoint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit resolveAntigravityForwardBaseURL() used ForwardBaseURLs() (which reorders the daily/sandbox endpoint to the front) and returned the first entry by default — daily-cloudcode-pa.sandbox.googleapis.com. Every Antigravity gateway request was therefore sent to Google's sandbox endpoint, which rejects production OAuth tokens: the account is benched with "OAuth 401: Invalid bearer token" (native paths surface it as 502) and never recovers. The dashboard "test connection" uses the production endpoint (antigravity.BaseURL), which is exactly why the test succeeds while the gateway 401s. Default to production (antigravity.BaseURLs[0] = cloudcode-pa.googleapis.com), matching the OAuth/test path; the daily/sandbox endpoint is now opt-in via GATEWAY_ANTIGRAVITY_FORWARD_BASE_URL=daily|sandbox. Fixes #3611, #2962. Supersedes the token-refresh self-heal approach (that premise — token staleness — was disproven: a 30s-old freshly-authorized token also 401s on the gateway while working on the test path). Verified on a live instance with a freshly-authorized Antigravity account: /antigravity/v1/messages and /v1/messages now return real completions (claude-sonnet-4-6, claude-opus-4-6); the same account/token 401/502'd before. --- .../service/antigravity_gateway_service.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/backend/internal/service/antigravity_gateway_service.go b/backend/internal/service/antigravity_gateway_service.go index aa4cab22d7..585170438e 100644 --- a/backend/internal/service/antigravity_gateway_service.go +++ b/backend/internal/service/antigravity_gateway_service.go @@ -153,14 +153,24 @@ type antigravityRetryLoopResult struct { } // resolveAntigravityForwardBaseURL 解析转发用 base URL。 -// 默认使用 daily(ForwardBaseURLs 的首个地址);当环境变量为 prod 时使用第二个地址。 +// +// 默认使用生产端点 cloudcode-pa.googleapis.com(antigravity.BaseURLs 的首个地址, +// 与账号 OAuth 登录/测试连接所用的 antigravity.BaseURL 一致)。 +// +// 历史上这里改用 ForwardBaseURLs()(把 daily/sandbox 排到首位)并默认取首个地址, +// 导致网关把带生产 OAuth token 的请求发到 daily-cloudcode-pa.sandbox.googleapis.com, +// 上游拒绝 → 账号被 401「Invalid bearer token」/502 打入临时不可调度且无法恢复 +// (见 #3611 / #2962)。后台「测试连接」用的是生产端点,所以「测试成功但网关 401」。 +// +// daily/sandbox 端点仅供内部联调,需显式设置 +// GATEWAY_ANTIGRAVITY_FORWARD_BASE_URL=daily(或 sandbox)才启用。 func resolveAntigravityForwardBaseURL() string { - baseURLs := antigravity.ForwardBaseURLs() + baseURLs := antigravity.BaseURLs if len(baseURLs) == 0 { return "" } mode := strings.ToLower(strings.TrimSpace(os.Getenv(antigravityForwardBaseURLEnv))) - if mode == "prod" && len(baseURLs) > 1 { + if (mode == "daily" || mode == "sandbox") && len(baseURLs) > 1 { return baseURLs[1] } return baseURLs[0]