Skip to content

fix(antigravity): 修复个人账号配额查询对齐官方IDE并剥离残留GCP标记 / align quota queries with official IDE for personal accounts and strip orphaned GCP tags - #2326

Merged
jlcodes99 merged 2 commits into
jlcodes99:mainfrom
zoutao212:fix/antigravity-gcp-tos-account-switch
Sep 19, 2026

Conversation

@zoutao212

Copy link
Copy Markdown
Contributor

PR 标题 (Title)

fix(antigravity): align quota queries with official IDE for personal accounts and strip orphaned GCP tags / 修复个人账号配额查询对齐官方IDE并剥离残留GCP标记


PR 正文 (Description)

🇨🇳 中文说明

背景与问题定位

在主线合入 #2286 解决 Antigravity 切换账号及多数据目录注入后,经过实际多账号场景复核,发现了两个影响个人付费订阅账号(standard-tier / Google One AI Premium)的配额与元数据缺陷:

  1. 配额死锁 100%(与官方 IDE 行为不一致):
    • 逆向分析 Antigravity 官方 IDE 内核发现,官方对个人订阅账号查询 retrieveUserQuotaSummary 时,请求 body 为 {}(空 Payload,不带任何 project 参数)。Google 服务端收到后会自动绑定该 OAuth 用户的个人订阅真实配额。
    • 先前逻辑误以为只要是个人付费账号(standard-tier)就属于 GCP ToS 体系,并给没有绑定真实项目的账号自动塞入了一个虚拟占位项目 "aicode-consumers"。
    • 当向 Google 发送 { "project": "aicode-consumers" } 时,Google 服务端会去查询该空项目的企业配额池,导致即使用户在 IDE 中已消耗了额度,Cockpit Tools 却始终显示为 100%(remainingFraction: 1)。
  2. 端点错误路由与 GCP 标签自循环死锁:
    • fetch_project_metadata_with_context 拿传入的上下文 ctx.is_gcp_tos 作为初始默认值。由于 Google 原生个人订阅响应中并不返回企业级 usesGcpTos 字段,导致账号一旦曾被标记过 is_gcp_tos=true,代码就永远无法覆盖重置它。
    • 受到该假标记影响,resolve_cloud_code_base_url 将请求错误路由到了企业生产端点(cloudcode-pa.googleapis.com)而非官方个人结算端点(daily-cloudcode-pa.googleapis.com),进一步加剧了配额失真,且卡片持续误显示【GCP ToS 账号】徽标。
本次修复内容
  1. 解耦 standard-tier 与 GCP 判定:
    • 严格尊重 Google API 返回的真实 usesGcpTos 字段,绝不把个人 Pro 订阅(standard-tier)强行判定为 GCP 体系。
  2. 对齐官方 IDE 查询 Payload:
    • 彻底移除 "aicode-consumers" 虚拟项目占位符;无真实 GCP 项目的账号统一发送 {},与官方 IDE 行为完全同源。
  3. 纠正请求端点路由:
    • 优化 resolve_cloud_code_base_url,只有在账号既标记为 GCP ToS 又拥有真实 GCP Project ID 时才发往生产端点;普通个人账号一律走默认的 daily-cloudcode-pa。
  4. 历史脏数据主动清洗与兼容:
    • 在 load_account 与配额刷新流程中,若账号无真实 Project ID,自动清洗剥离历史上误存的 is_gcp_tos 标记,实现平滑自愈。

🇬🇧 English Description

Problem & Root Cause

Following the merge of PR #2286 (which resolved account switching and multi-user-data injection for Antigravity), extensive real-world testing across multiple personal paid accounts (standard-tier / Google One AI Premium) revealed two key regressions:

  1. Quotas Stuck at 100% (Divergence from Official IDE):
    • Reverse engineering of the official Antigravity IDE core demonstrated that personal subscriber quotas (retrieveUserQuotaSummary) are queried with an empty payload {} without specifying a project attribute. Google's backend automatically maps this to the user's personal subscription usage.
    • The prior implementation mistakenly assumed all standard-tier accounts belonged to the GCP ToS system, injecting a placeholder project "aicode-consumers" when no GCP project was bound.
    • Sending { "project": "aicode-consumers" } causes Google to query an unconsumed enterprise project pool, persistently reporting 100% remaining quota even when substantial quota has been used in the IDE.
  2. Erroneous Endpoint Routing and Sticky GCP ToS Tags:
    • fetch_project_metadata_with_context initialized resolved_is_gcp_tos with ctx.is_gcp_tos. Because Google does not include the enterprise-only usesGcpTos field in personal account responses, an account once flagged as is_gcp_tos=true would permanently inherit the tag in a feedback loop.
    • This tag forced resolve_cloud_code_base_url to direct traffic to the enterprise production endpoint (cloudcode-pa.googleapis.com) instead of the official personal settlement endpoint (daily-cloudcode-pa.googleapis.com), causing the card to show a false GCP ToS Account badge and inaccurate quotas.
Key Changes in This PR
  1. Disentangle standard-tier from GCP ToS:
    • Strictly respect upstream usesGcpTos returned by Google API; never infer GCP ToS solely from personal paid tiers.
  2. Align Quota Request Payload with Official IDE:
    • Completely remove the "aicode-consumers" placeholder. Query personal accounts with empty payload {} so Google accurately returns individual consumption.
  3. Correct Endpoint Routing:
    • Update resolve_cloud_code_base_url to only route to cloudcode-pa.googleapis.com if an account is both marked as GCP ToS and possesses a valid project_id. All other personal accounts use daily-cloudcode-pa.googleapis.com.
  4. Backward-Compatible Data Sanitization:
    • In load_account and cache validation, automatically sanitize and reset stale is_gcp_tos tags when no valid project_id exists, ensuring seamless self-healing for existing installations.

…d build guide

Ensure scripts/tauri.cjs injects cargoBinPath into PATH and detects
vcvars64.bat across Professional/Enterprise/Community/BuildTools editions,
preventing raw cargo builds that omit embedded frontend assets.
@DuolaD

DuolaD commented Sep 9, 2026

Copy link
Copy Markdown

🤔其实我好奇这个GCP TOS标记是什么意思,搜了一圈也找不到解释。

@zoutao212

Copy link
Copy Markdown
Contributor Author

GCP 似乎是 google 云服务的独立配额系统,但是 实际上 一开始是那个账户的区域是中国大陆,不被 Antigravity IDE 认可登录,所以静默登录失败,账户没有切换,后来 硬是修复了这个大陆区域的账户登录状态,可以登陆,拉取到的API 竟然是企业级的端点路由,后来修复了这个账户区域问题,这个账户的判断代码也需要修改正确。

@folgercn

Copy link
Copy Markdown

实测当前最新版本(v1.3.57)中,个人 Pro 账号确实依然深受该问题困扰(被误识别为 GCP ToS 账号,且 Gemini 5h 配额常驻 100% 无法真实刷新,导致依赖阈值的自动切号功能完全无法生效)。

相关实测数据与现象已在 Issue #2500 中补充记录。此 PR 的根因定位非常精准,恳请作者 @jlcodes99 抽空审阅并尽快合并,感谢!🙏

@DuolaD

DuolaD commented Sep 19, 2026

Copy link
Copy Markdown

今天也遇到了这个情况,希望尽快合并🙏

@jlcodes99
jlcodes99 merged commit dbe56a1 into jlcodes99:main Sep 19, 2026
11 checks passed
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.

4 participants