Skip to content

fix(agy): use local quota snapshots and disable refresh for non-current accounts in Auth Center - #10073

Merged
farion1231 merged 1 commit into
farion1231:mainfrom
jimpablo:fix/agy-auth-center-non-current-quota
Nov 28, 2026
Merged

farion1231 merged 1 commit into
farion1231:mainfrom
jimpablo:fix/agy-auth-center-non-current-quota

Conversation

@jimpablo

@jimpablo jimpablo commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Human Note / 本人说明

在 v4.0.44 授权中心把 agy 从一个账号切到另一个账号时,看到旧账号切走后还留着之前查到的历史额度和可以点的 ↻ 刷新按钮,容易让人误以为还能实时查最新额度;如果关掉了「自动查询额度」,非当前号会显示「点刷新查询额度」,点过一次无快照的非当前号再切到那个号,整列额度连同右侧 ↻ 按钮还会直接消失,而且页头点「全部刷新」也会连非当前 agy 账号一起扫去读钥匙串,在外部终端切号回来「agy 在用」徽标也不会马上刷新。这个 PR 只聚焦修授权中心里非当前 agy 账号的只读快照展示、置灰禁用刷新按钮与悬停提示,以及切号/全部刷新/回焦同步这几处问题,保持当前号在关闭自动查询模式下的「点刷新查询额度 ↻」现状,不动供应商卡片、托盘、WorkBuddy 和数据库版本。

Summary / 概述

Fix Auth Center quota UX and state bugs for non-current Antigravity (agy) accounts introduced after v4.0.44 switched quota fetching to agy --print /usage:

1. Pure-local snapshot read path for non-current accounts (Backend + API)

  • Add agy_account_last_quota(accountId) in src-tauri/src/commands/agy_account.rs and register it in src-tauri/src/lib.rs, backed directly by AgyAccountManager::last_quota (zero keychain /usr/bin/security calls, zero agy subprocess launches, zero network requests).
  • Expose subscriptionApi.getAgyAccountLastQuota (src/lib/api/subscription.ts) and useAgyAccountLastQuota (src/lib/query/subscription.ts) with query key ["agy_oauth", "last_quota", accountId].

2. Auth Center non-current vs current Antigravity quota UX (AccountQuota.tsx)

  • Extend AccountQuotaColumn with optional refreshDisabled and refreshHint props, forwarded to QuotaRefreshCell (disabled and hint), preserving the ↻ slot for column alignment while setting aria-disabled (with cursor-not-allowed, muted styling, no-op click) and custom HoverTip text.
  • Split AgyAccountQuota into NonCurrentAgyAccountQuota and CurrentAgyAccountQuota:
    • Non-current accounts: read useAgyAccountLastQuota directly regardless of officialQuotaManualOnly, showing the stored historical bars and true queriedAt relative time as-is; when no valid local snapshot exists, render "切到这个号后才能查额度" instead of misleading "点刷新查询额度"; right-side ↻ is muted/disabled with hover tooltip "切到这个号后才能查最新额度" (authCenter.agy.quotaRefreshDisabledHint), keeping authCenter.agy.quotaRefreshNotCurrent intact for AgyAccountQuotaFooter.tsx.
    • Current account (agy 在用): keeps existing "点刷新查询额度 ↻" behavior under officialQuotaManualOnly: true (does not overlap with [Feature] 授权中心所有官方服务统一持久化并展示上次刷新的额度、套餐与查询时间 #10057) and delegates not_found cache clearing to resetAgyNotFoundQuotas without extra cachedNotFound state in CurrentAgyAccountQuota.

3. Switch invalidation, Refresh All, and window-focus login sync

  • invalidateAgyLoginCaches (src/lib/query/subscription.ts) resets cached not_found entries from ["agy_oauth", "quota"] via queryClient.resetQueries (resetAgyNotFoundQuotas, preserving active observers such as mounted bound provider cards in auto mode instead of detaching them via removeQueries), awaits agyAuthStatusQuery invalidation first, and then invalidates non-current ["agy_oauth", "quota", *] with refetchType: "none" (actively refetching only the current account) so the displaced account never triggers a redundant agy_account_quota keychain read before React unmounts it, alongside invalidating ["agy_oauth", "last_quota"].
  • RefreshAllQuotaButton (src/components/settings/auth/RefreshAllQuotaButton.tsx) skips non-current agy_oauth quota queries when auth status is known (in addition to non-current rows no longer mounting useAgyAccountQuota), avoiding redundant serial keychain reads.
  • Add subscribeWindowFocus in src/lib/windowActivity.ts (reusing the deduplicated DOM focus + Tauri onFocusChanged active transitions since focusManager intentionally stays focused for visible unfocused windows) and syncAgyLoginOnWindowFocus in src/lib/query/subscription.ts, wired in useManagedAuth("agy_oauth") alongside refetchOnWindowFocus: "always" on agyAuthStatusQuery. Returning to the window after switching accounts in an external terminal immediately refreshes "agy 在用" and invalidates quota caches only when default_account_id actually changed. Completing agy_oauth login/reauth polling in useManagedAuth also invokes invalidateAgyQuotaCaches so newly signed-in or re-authenticated accounts reset any prior cached not_found state and refresh cleanly.

4. Internationalization & Tests

  • Add authCenter.agy.quotaRefreshDisabledHint across all 8 locale files (zh, zh-TW, en, de, ja, ko, ru, tr; leaving authCenter.agy.quotaRefreshNotCurrent untouched for AgyAccountQuotaFooter.tsx; non-Chinese/English translations were reviewed for consistency with quotaNotCurrent).
  • Add Rust unit test in src-tauri/src/services/agy_account/tests.rs verifying last_quota reads snapshots with 0 keychain reads even when locked.
  • Add frontend tests in tests/components/AgyAccountQuota.test.tsx (14 cases, including resetQueries keeping mounted auto-mode observers connected without refetching non-current not_found observers), tests/hooks/useManagedAuth.test.tsx (window-focus refresh, external switch invalidation, and agy_oauth login-polling cache invalidation), and tests/lib/windowActivity.test.ts (visible blur-to-focus deduplication), plus default MSW handler in tests/msw/handlers.ts.

Scope boundary

  • Does not touch AgyAccountQuotaFooter (provider cards), tray menu/panel, WorkBuddy, or database SCHEMA_VERSION.

Related Issue / 关联 Issue

Fixes #10072

Screenshots / 截图

Before / 修改前 After / 修改后
非当前 Antigravity 账号保留可点击 ↻;手动模式下显示「点刷新查询额度」,点过无快照非当前号再切过去后整列额度与 ↻ 消失 非当前 Antigravity 账号纯本地只读展示上次历史额度与真实查询时间(无快照显示「切到这个号后才能查额度」),右侧 ↻ 置灰禁用并悬停提示「切到这个号后才能查最新额度」;切号后当前号正常保留 ↻

Checklist / 检查清单

  • pnpm typecheck passes / 通过 TypeScript 类型检查
  • pnpm format:check passes / 通过代码格式检查(同时通过 pnpm knip、pnpm build:renderer、pnpm test:unit 348/348 files, 4605/4605 tests)
  • cargo clippy passes (if Rust code changed) / 通过 Clippy 检查(同时通过 cargo fmt --check、cargo test --lib services::agy_account 32/32 及 cargo test --test integration 231/231)
  • Updated i18n files if user-facing text changed / 如修改了用户可见文本,已更新全部八个语言文件

@github-actions github-actions Bot added frontend Frontend (React/TypeScript) backend Backend (Rust/Tauri) i18n Internationalization (zh/en/ja) labels Nov 28, 2026
@jimpablo
jimpablo force-pushed the fix/agy-auth-center-non-current-quota branch from 20a1496 to db24eaf Compare November 28, 2026 10:46

@farion1231 farion1231 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢!维护者决定授权中心的非当前 Antigravity 账号采用本 PR 的方案:直接显示本地快照,↻ 置灰并加悬停提示。db24eaff 补的回焦同步也解决了从外部终端切号回来后,真正在用的号还被置灰的问题。

main 已经合入了 12602dd(授权中心和绑号官方卡在点非当前号的 ↻ 后弹 toast),和本 PR 在 AccountQuota.tsx 和八个语言文件上有冲突,需要 rebase 到最新的 main。解冲突时请注意:

  • 授权中心以本 PR 为准:AgyAccountQuota 里 12602dd 加的 toast 和 refreshHint 那套去掉,保留置灰方案。QuotaRefreshCell 两边都加了悬停提示参数(main 叫 hint,本 PR 也有对应的 prop),合成一个就行。
  • authCenter.agy.quotaRefreshNotCurrent 不要改文案:main 上 AgyAccountQuotaFooter.tsx(供应商卡片)的 toast 还在用这个 key 的长句。置灰按钮的悬停提示请另起一个新 key,八个语言文件同步加上。
  • 供应商卡片那边保持 main 现状,本 PR 不用动。

另外一个小建议(不阻塞):removeAgyNotFoundQuotas 里的 removeQueries 会让仍在观察这个查询的组件和缓存断开,紧接着的 invalidateQueries 不会让它重新查询,要等组件下次重新渲染。授权中心的行会重新挂载,所以不受影响;绑号官方卡在自动模式下通过「打开终端」切到一个没有快照的号时,可能会一直空着。换成 resetQueries 就能避免,CurrentAgyAccountQuota 里 cachedNotFound 那层保护也可以一起去掉。

@jimpablo
jimpablo force-pushed the fix/agy-auth-center-non-current-quota branch from db24eaf to d0ee28c Compare November 28, 2026 14:24
@jimpablo

jimpablo commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor Author

@farion1231 已按意见 rebase 到最新 main(2212741f)并推送更新(7ca66cfa):

  • 授权中心与冲突处理:AccountQuota.tsx 去掉了 12602ddfc 在 AgyAccountQuota 中加的 toast 与相关逻辑,保留非当前账号置灰禁用 ↻ 方案;QuotaRefreshCell 已合并为一个 hint 参数;供应商卡片 AgyAccountQuotaFooter.tsx 保持 main 现状未动。
  • i18n:保留 authCenter.agy.quotaRefreshNotCurrent 原长句文案不变,为授权中心置灰按钮新增 authCenter.agy.quotaRefreshDisabledHint,并在全部 8 个语言文件同步添加。
  • resetQueries 与简化:将 resetAgyNotFoundQuotas(原 removeAgyNotFoundQuotas)中的 removeQueries 改为 resetQueries,避免仍在观察查询的绑定官方卡在自动模式下切到无快照账号时与缓存断开;同时去掉了 CurrentAgyAccountQuota 里的 cachedNotFound 保护层,并在 useManagedAuth 完成 agy_oauth 登录/重登轮询时补充调用 invalidateAgyQuotaCaches,同步补齐对应单元测试(含多活跃观察者场景下不误重查其他非当前 not_found、以及 agy_oauth 登录轮询完成后的缓存清理验证)。

全部前后端检查均已重新跑过并通过(pnpm format:check、pnpm typecheck、pnpm knip、pnpm build:renderer、pnpm test:unit 348/348 files / 4605/4605 tests、cargo fmt --check、cargo clippy --all-targets -- -D warnings、cargo test --lib services::agy_account 32/32 及 cargo test --test integration 231/231),请复审。

@jimpablo
jimpablo force-pushed the fix/agy-auth-center-non-current-quota branch from d0ee28c to 7ca66cf Compare November 28, 2026 14:36
@farion1231
farion1231 merged commit b825b1b into farion1231:main Nov 28, 2026
11 checks passed
@farion1231

Copy link
Copy Markdown
Owner

已合并,感谢您的贡献!rebase 处理得很干净,key 拆分和 resetQueries 也都按建议改好了,登录完成后刷新额度缓存这一处补得也很到位。授权中心里非当前的 Antigravity 账号现在直接显示切走前的快照,不再起 agy,也不读钥匙串。从外部终端切号回来后,「agy 在用」也会跟着同步。会随下一个版本发布。

farion1231 added a commit to funkpopo/cc-switch that referenced this pull request Nov 29, 2026
Resolve conflicts with the Antigravity quota rework that landed on main
(farion1231#10073 local quota snapshots, farion1231#10056 tray respects manual-only quota,
farion1231#10062 failure reuse and Windows CLI checks, 12602dd non-current refresh
hint). Main already lets non-current accounts show their saved snapshot
without starting agy and honours the "auto-query quota" switch, so the
quota side of this branch is resolved in main's favour: the forced
manual-only `manual` flag on agy_account_quota / get_subscription_quota,
the switching/login guard that only served it, and the manual-refresh
epoch on the frontend are dropped. Desktop sync, the running-state block,
the card switch button and the re-login fixes are kept as they were.

Also drops the unused runningNoticeTitle/runningNoticeBody strings and
main's has_agy_in_tasklist, which this branch's tasklist parser replaces.
@jimpablo
jimpablo deleted the fix/agy-auth-center-non-current-quota branch December 2, 2026 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend (Rust/Tauri) frontend Frontend (React/TypeScript) i18n Internationalization (zh/en/ja)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 授权中心非当前 Antigravity 账号额度交互异常:刷新按钮未禁用、手动模式切号后刷新入口消失

2 participants