Repository navigation
feat(mobile): show all usage providers on mobile with a per-provider visibility filter - #8571
Closed
audichuang wants to merge 3 commits into
Closed
audichuang wants to merge 3 commits into
audichuang wants to merge 3 commits into
Conversation
桌面已支援 Claude/Codex/Gemini/OpenCode Go/Kimi/MiniMax/Grok 的用量顯示, 行動端卻只顯示 Claude+Codex。此變更讓行動端顯示全部 provider,並於 Settings → Account usage 提供每個 provider 的開關(預設只開 Claude+Codex, 其餘 opt-in,避免手機一次塞滿)。 - 純 client 變更:host 已在 accounts.list / accounts.subscribe 的 snapshot 送出完整 RateLimitState,零後端 / 協定改動。 - 拆 ManagedAccountProviderKey(可切換)vs UsageProviderKey(唯讀顯示); display-only provider 走不可點路徑,不會觸發帳號切換。 - 以 canonical descriptor 對應 wire id 與 snapshot 欄位(解 opencode-go / opencodeGo 不一致);新欄位為 optional 並以 ?? null 正規化舊 v1 快取。 - getProviderUsageWindows 依實際視窗渲染:Gemini 具名 buckets、OpenCode Go monthly、其餘 session/weekly,不再硬寫 5h/7d。 - 可見性偏好存於本地 AsyncStorage,沿用既有 focus-reload 慣例。 - home 卡片抽成 HomeAccountUsageCard 以符合 max-lines。
… load
The Account-usage settings screen started on the default set {claude,codex}
while the stored visibility set loaded asynchronously. A toggle fired before
that load resolved persisted the whole set against the stale default, silently
dropping any provider that lived only in the stored set (e.g. an opted-in
Grok).
- Gate the switches until the stored set loads, so no toggle can persist
against the default base.
- Move persistence to a serialized read-modify-write in preferences
(`setUsageProviderVisible`): each toggle re-reads the latest stored set and
changes only its own provider, so concurrent toggles can't clobber each
other and the write survives an unmount.
- Load once on mount via a settled read (the screen is the sole writer), so a
focus-reload can't overwrite the optimistic UI with a pre-write snapshot.
- Distinguish an I/O read failure (abort the write) from corrupt content
(missing / malformed JSON / non-array → re-base on the default and self-heal).
Tests cover: stored-only provider survives a pre-load toggle, concurrent
toggles serialize, I/O read failure aborts the write, malformed JSON self-heals.
…11y, guard NaN Review follow-ups on the multi-provider usage feature: - The Home usage card now keeps a display-only provider visible while it is fetching or in error (spinner / last bars) instead of dropping it, matching the accounts screen and making the previously-unreachable fetching branch reachable. - Each visibility Switch gets an accessibilityLabel so a screen reader names the provider being toggled. - UsageBar treats a non-finite percent (NaN/Infinity) as no data so it never renders `width: "NaN%"`.
6 of 8 tasks
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Mobile only showed Claude and Codex usage, even though the host already streams the full
RateLimitStatefor every provider in theaccounts.list/accounts.subscribesnapshot. This PR surfaces the rest — Gemini, OpenCode Go, Kimi, MiniMax, Grok — on mobile, plus a per-provider visibility filter under Settings → Account usage (defaults to Claude + Codex only; the others are opt-in so the phone isn't flooded).Pure client change — no backend or protocol change. Highlights:
ManagedAccountProviderKey(switchable: Claude/Codex) fromUsageProviderKey(display-only), so a display-only provider can never route into account-switching selectors.opencode-go/opencodeGomismatch); new snapshot fields are optional and normalized with?? null, so an old cached snapshot stays valid.getProviderUsageWindowsrenders each provider's real windows (Gemini named buckets, OpenCode Go monthly, others session/weekly) instead of two hardcoded 5h/7d bars.Bug fixed along the way: visibility toggle could drop an opted-in provider
Problem — On the settings screen, a toggle fired before the stored visibility set finished loading persisted the whole set against the default
{claude, codex}base, silently dropping any provider that lived only in the stored set (e.g. an opted-in Grok).Root cause — The screen started on the default set while the stored set loaded asynchronously; the pre-load toggle wrote that stale default plus the one change.
Fix
preferences.ts(setUsageProviderVisible): each toggle re-reads the latest stored set and changes only its own provider, so concurrent toggles can't clobber each other and the write survives an unmount.Follow-up review fixes: the Home usage card now keeps a display-only provider visible while fetching/on error (matching the accounts screen) instead of hiding it; each visibility
Switchgets anaccessibilityLabel;UsageBartreats a non-finite percent as no data so it never renderswidth: "NaN%".Screenshots
Mobile UI change (new Settings → Account usage filter screen; Home card and per-host accounts screen now list opted-in providers). Before/after captures to be added from a device/simulator — no desktop-renderable surface.
Testing
pnpm typecheck— clean on all changed files (tsc --noEmit -p mobile/tsconfig.json)pnpm lint— changed files pass oxlint + oxfmt via the husky pre-commit hook; full-repo lint not runpnpm test— ran the focused suites below (49 passed); full suite not runpnpm build— not run locally; relying on CIFocused tests (from
mobile/):New tests cover: a stored-only provider (Grok) survives a pre-load toggle; concurrent toggles serialize without loss; an I/O read failure aborts the write and leaves the stored set intact; malformed stored JSON self-heals. Each was confirmed to fail before its fix.
AI Review Report
Reviewed with Codex (GPT-5.6) across several independent adversarial passes:
getAccountsSnapshot()returnsrateLimits.getState()whole (Grok included) andaccounts.subscribebroadcasts it unmodified, so no host/protocol change is needed.accessibilityLabel, and aNaN%bar-width edge case.Security Audit
No new input parsing from untrusted sources, no command execution, no path handling, no secrets, and no new IPC/RPC surface. Visibility preferences are stored locally in
AsyncStorage; the usage data already arrives in the existing accounts snapshot. Stored preferences are defensively validated (unknown ids filtered, corrupt content normalized).Notes
AccountUsage.tsx/account-usage-state.ts, so expect a small rebase if one lands first. No functional overlap.Closes; the desktop provider-usage work that populated the hostRateLimitStateis already merged, so this is purely the mobile client catching up.