Repository navigation
Conversation
📝 WalkthroughWalkthroughAdds Z.AI Coding Plan usage tracking through OpenCode’s Merge Risk: 🔵 Low · up to Some Z.AI users can lose the usage indicator or setup guidance after indeterminate quota responses or when connected to an older host. Resolve these visibility-state issues before relying on the feature rollout. 🚥 Pre-merge checks | ✅ 2 | ❌ 3❌ Failed checks (3 warnings)
✅ Passed checks (2 passed)
Full details: Description checkExplanation The description is detailed and covers the change, rationale, linked issue, testing, review notes, compatibility, and checklist. The ELI5 section is missing, and the Visual Proof section describes validation but does not show attached before-and-after evidence. Full details: Linked Issues checkExplanation The PR implements the core Z.AI status-bar provider, quota windows, endpoint access, visibility controls, and default-on migration for Resolution Either implement the Full details: Out of Scope Changes checkExplanation Most changes support Z.AI quota monitoring. The pet-selection hydration extraction and normalization in ui-slice-hydration-actions.ts and ui-slice-hydration-values.ts are unrelated to the linked issue and add separate scope. Full details: Docstring CoverageExplanation Docstring coverage is 29.82% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 57 functions across 50 files. (19 skipped: 7 unsupported, 12 over the file limit.)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: 8c2e7816-c0bc-44d8-8ee7-e515f44275bc
📒 Files selected for processing (69)
docs/site/content/docs/agents/usage-tracking.mdxmobile/src/components/accounts-snapshot.tssrc/main/opencode/opencode-auth-store.test.tssrc/main/opencode/opencode-auth-store.tssrc/main/rate-limits/gemini-oauth-sources.tssrc/main/rate-limits/rate-limit-service-test-harness.tssrc/main/rate-limits/service-account-target-selection.test.tssrc/main/rate-limits/service-antigravity-usage.test.tssrc/main/rate-limits/service-inactive-account-previews.test.tssrc/main/rate-limits/service-live-claude-usage.test.tssrc/main/rate-limits/service-minimax-usage.test.tssrc/main/rate-limits/service-refresh-orchestration.test.tssrc/main/rate-limits/service-window-activation.test.tssrc/main/rate-limits/service-zai-usage.test.tssrc/main/rate-limits/service/service-configuration.tssrc/main/rate-limits/service/service-full-cycle-application.tssrc/main/rate-limits/service/service-full-cycle-preparation.tssrc/main/rate-limits/service/service-polling.tssrc/main/rate-limits/service/service-result-policy.tssrc/main/rate-limits/service/service-state.tssrc/main/rate-limits/service/service-types.tssrc/main/rate-limits/zai-auth-configured.test.tssrc/main/rate-limits/zai-auth-configured.tssrc/main/rate-limits/zai-credentials.test.tssrc/main/rate-limits/zai-credentials.tssrc/main/rate-limits/zai-fetcher.test.tssrc/main/rate-limits/zai-fetcher.tssrc/main/runtime/rpc/methods/client-ui-schemas.tssrc/main/runtime/rpc/methods/client-ui.test.tssrc/renderer/src/components/settings/appearance-status-bar-minimax-toggle-search.tssrc/renderer/src/components/settings/appearance-status-bar-search.test.tssrc/renderer/src/components/settings/appearance-status-bar-search.tssrc/renderer/src/components/settings/appearance-status-bar-zai-toggle-search.tssrc/renderer/src/components/status-bar/StatusBarProviderSegment.tsxsrc/renderer/src/components/status-bar/StatusBarVisibilityMenu.tsxsrc/renderer/src/components/status-bar/UsageRosterPanel.test.tsxsrc/renderer/src/components/status-bar/icons.test.tsxsrc/renderer/src/components/status-bar/icons.tsxsrc/renderer/src/components/status-bar/provider-segment-letter-badge.test.tsxsrc/renderer/src/components/status-bar/status-bar-agent-gating.test.tssrc/renderer/src/components/status-bar/status-bar-provider-visibility.test.tssrc/renderer/src/components/status-bar/status-bar-provider-visibility.tssrc/renderer/src/components/status-bar/tooltip.tsxsrc/renderer/src/components/status-bar/usage-error-copy.test.tssrc/renderer/src/components/status-bar/usage-error-copy.tssrc/renderer/src/components/status-bar/usage-provider-settings-target.test.tssrc/renderer/src/components/status-bar/usage-provider-settings-target.tssrc/renderer/src/components/status-bar/usage-roster-order.test.tssrc/renderer/src/components/status-bar/usage-roster-order.tssrc/renderer/src/components/status-bar/use-status-bar-controller.tssrc/renderer/src/i18n/en-runtime-required.jsonsrc/renderer/src/i18n/locales/en.jsonsrc/renderer/src/i18n/locales/es.jsonsrc/renderer/src/i18n/locales/ja.jsonsrc/renderer/src/i18n/locales/ko.jsonsrc/renderer/src/i18n/locales/zh.jsonsrc/renderer/src/runtime/runtime-provider-accounts-client.test.tssrc/renderer/src/store/slices/rate-limits.test.tssrc/renderer/src/store/slices/rate-limits.tssrc/renderer/src/store/slices/ui-hydration-workspace-preferences.test.tssrc/renderer/src/store/slices/ui/status-bar-default-hydration.tssrc/renderer/src/store/slices/ui/ui-slice-hydration-actions.tssrc/renderer/src/store/slices/ui/ui-slice-hydration-values.tssrc/renderer/src/web/preload-api/web-rate-limits-api.tssrc/shared/persisted-ui-state-types.tssrc/shared/rate-limit-types.tssrc/shared/status-bar-defaults.tssrc/shared/ui-chrome-types.tstests/e2e/status-bar-caffeinate.spec.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
| if (limits.usageMetadata?.failureKind === 'missing-credentials') { | ||
| return false | ||
| } | ||
| return limits.status !== 'unavailable' |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Keep Z.AI discoverable when credential state is unknown.
Line 17 hides every unavailable result. An unavailable result without failureKind: 'missing-credentials' does not prove that the Coding Plan key is absent. This hides the provider for unfamiliar or indeterminate quota outcomes. Return true after the explicit missing-credentials check. Update src/main/rate-limits/zai-auth-configured.test.ts Line 42 to expect true.
Proposed fix
- return limits.status !== 'unavailable'
+ return true📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| return limits.status !== 'unavailable' | |
| return true |
| isProviderSnapshotPending(providers.minimax) || | ||
| isProviderSnapshotPending(providers.grok) | ||
| isProviderSnapshotPending(providers.grok) || | ||
| isProviderSnapshotPending(providers.zai) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Gate the Z.AI pending check on Z.AI configuration.
An older host can omit the Z.AI snapshot while zaiAuthConfigured is false. Line 177 then treats the absent snapshot as pending. isUsageEmptyState returns false indefinitely and suppresses the setup CTA after all supported provider snapshots settle.
Match the Antigravity path. Require hasUsageProviderSettingsForProvider('zai', settings) before testing whether providers.zai is pending.
Proposed fix
+ const zaiSnapshotPending =
+ hasUsageProviderSettingsForProvider('zai', settings) &&
+ isProviderSnapshotPending(providers.zai)
if (
isProviderSnapshotPending(providers.claude) ||
isProviderSnapshotPending(providers.codex) ||
isProviderSnapshotPending(providers.gemini) ||
isProviderSnapshotPending(providers.opencodeGo) ||
isProviderSnapshotPending(providers.kimi) ||
antigravitySnapshotPending ||
isProviderSnapshotPending(providers.minimax) ||
isProviderSnapshotPending(providers.grok) ||
- isProviderSnapshotPending(providers.zai)
+ zaiSnapshotPending
) {| }) | ||
| await flushMicrotasks() | ||
|
|
||
| subscriptionCallbacks?.onResponse({ |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Require the compatibility test to establish the subscription and receive one snapshot.
If watchProviderAccounts does not call runtimeEnvironmentSubscribe, or if the callback receives no ready response, subscriptionCallbacks remains unset and the optional assertions at lines 301–302 still pass. Assert that the callback exists and that snapshots has one item before checking the omitted Z.AI fields.
There was a problem hiding this comment.
ℹ️ No critical issues — two minor suggestions inline.
Reviewed changes
- OpenCode auth-store extraction — pulled
auth.jsoncandidate discovery/parsing into a sharedopencode-auth-store.tswith sanitized (path-free) read errors, and routed the existing GeminireadAuthJsonthrough it while preserving its throw-on-error contract. - Z.AI fetcher + credential reader — new
zai-fetcher.ts/zai-credentials.ts/zai-auth-configured.ts: reads only thezai-coding-planrecord, strict two-host origin allowlist, raw-keyAuthorization, exact 5h/7d window parsing that fails "unknown" instead of 0%, and typedfailureKindclassification (401/403 → stale-token, 429 → rate-limited with Retry-After, 5xx → server, etc.). - Service wiring —
zaiadded to thePromise.allSettledcycle, polling roster, stale/backoff policy, failure-streak tracking, andzaiAuthConfiguredderived from the settled result (no duplicate auth probe). - Renderer + shared types —
zai/zaiAuthConfiguredas optionalRateLimitStatefields for old-host compatibility, roster ordering (Claude, Codex, Z.AI, …), visibility, letter badge, icon, error copy, i18n across all five catalogs, and a one-shot default-on migration inserting Z.AI after Codex. - Tests — mixed-version, credential-safety, parser, stale/backoff, service-isolation, persistence, renderer, and an Electron E2E across verbose/compact/icon-only modes plus visibility toggle.
The parsing is fail-closed, keys never reach the renderer or error strings, and the old-host wire compatibility is handled carefully. The two notes below are the only things that gave me pause.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
| } | ||
|
|
||
| /** Durable `zaiAuthConfigured` signal: a nonempty Coding Plan key is on disk. */ | ||
| export async function isZaiAuthConfigured(): Promise<boolean> { |
There was a problem hiding this comment.
isZaiAuthConfigured is exported and unit-tested but has no production caller — the service derives the durable flag from the settled fetch result via deriveZaiAuthConfigured instead. Its semantics also diverge from that live path: it returns false for an unreadable auth.json, whereas deriveZaiAuthConfigured returns true for the status: 'error' result such a failure produces. Two near-identically-named "is configured" functions with opposite edge-case behavior is a maintenance trap. Recommend removing isZaiAuthConfigured (and its test) or wiring it in explicitly if a store-level check is intended somewhere.
| if (limits.usageMetadata?.failureKind === 'missing-credentials') { | ||
| return false | ||
| } | ||
| return limits.status !== 'unavailable' |
There was a problem hiding this comment.
status !== 'unavailable' treats every error result as configured, including an auth-store read/parse failure (makeError(credentials.error, 'unknown')). That means a user who has never set up Z.AI but has a corrupt or unreadable ~/.opencode/auth.json gets a phantom Z.AI row in error state, and the recovery path shows the raw store error ("Failed to read OpenCode auth.json (EACCES)") since only stale-token/missing-credentials get the friendly copy. The keep-visible-on-transient-network-failure goal is right, but consider keying it on failureKind: unknown (store read failure) should read as unconfigured, while network/server/parse keep the row. Worth confirming this edge is intentional before merge.
|
Tested locally on macOS arm64 (Orca 1.4.194, ZCode v2 credentials). Verified that querying the Filtering out Solid implementation and verified working on real hardware. Thanks for the work! |
|
Thanks for the careful work here. Z.AI/GLM Coding Plan usage now ships on main via ZCode (#24674), so we're closing this as superseded. Feel free to open a new PR if reading OpenCode's zai key is still needed. |

What Changed
zai-coding-planAPI-key record from OpenCodeauth.jsonand sends one read-only quota request to the configured global or China origin.Why
GLM Coding Plan users currently need to leave Orca to check quota. This reuses the existing usage roster while preserving OpenCode credential ownership and treating missing or unfamiliar quota data as unknown rather than falsely showing 0%.
Linked Issue
Fixes #18506
Visual Proof
Validated by the deterministic Electron status-bar E2E at normal, compact, and icon-only widths, and with a signed local macOS build manually tested by the requester. The E2E asserts the visible Z.AI row, 5-hour and weekly windows, compact meter, icon badge, keyboard focus, and visibility toggle.
Testing
I manually tested these changes locally on macOS
Automated tests added/updated
pnpm tc— passed on current upstreammain222 focused tests — passed on current upstream
mainpnpm run check:code-quality:changed— feature branch passed with 0 findings before rebasing; after rebasing, the repo-wide baseline comparison reports one unrelated pre-existing finding inmobile/src/session/use-mobile-session-terminal-create-actions.test.tsElectron status-bar E2E — 2/2 passed
pnpm build:mac— signed arm64 and x64 DMG/ZIP artifacts producedReview
RateLimitStateadditions are optional for old-host compatibility.Parallel implementation
PR #18507 addresses the same issue. This PR is an independently developed, hardened alternative with explicit OpenCode credential ownership, a strict global/CN origin allowlist, no in-app key-entry/account surface, stale/backoff integration, additive old-host compatibility, one-shot migration behavior, and broader regression coverage. Maintainers may prefer or combine either approach.
Agent skill upstream boundary
Notes
Checklist