feat(opencode): show quota usage toast after quota refresh#36
Merged
Conversation
There was a problem hiding this comment.
3 issues found across 6 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/opencode/src/index.ts">
<violation number="1" location="packages/opencode/src/index.ts:428">
P2: Fallback quota command output drops fresh per-account refresh errors by always passing an empty error map.</violation>
</file>
<file name="packages/core/src/quota-manager.ts">
<violation number="1" location="packages/core/src/quota-manager.ts:88">
P2: Persisted main quota cache uses interval-only staleness instead of policy-aware `getQuotaNextRefreshAt`, causing premature refreshes.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
4ad7d49 to
b20b6c0
Compare
95a1614 to
58f05a8
Compare
f4bee10 to
617634b
Compare
Contributor
Author
Displays quota usage bar notifications via client.tui.showToast after quota data is refreshed. Shows main and fallback account usage with visual bars, percentage, and reset time. Toast variant reflects severity (info < 70%, warning >= 70%, error >= 90%).
Align the quota refresh toast with the sidebar's visual language: - Replace the emoji status dots with status words (active/idle) - Use the shared bar width and a padded percentage via a quotaLine helper - Rename the seven-day label from 1w to 7d to match the sidebar - Keep severity-driven variant color (info/warning/error)
e21de9f to
4b7a88c
Compare
There was a problem hiding this comment.
iceteaSA has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.
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.
Displays quota-usage bar notifications via
client.tui.showToastafter quota data is refreshed.█░).formatResetInhandles sub-1-minute (<1m), "now", and invalid-date inputs.RangeErroron >100% utilization..then()of each periodic background refresh; never blocks the request.Single file change:
packages/opencode/src/index.ts.Summary by cubic
Shows a quota usage toast after quota refresh, matching the TUI sidebar. Keeps the sidebar correct during async refreshes by preserving the active account and re-rendering when background fallback storage changes via
@cortexkit/anthropic-auth-core.New Features
client.tui.showToastafter cold-startrefreshMainand background refresh; shows main + enabled fallbacks with shared-width█░bars, padded %, 5h/7d, “resets <1m/now”, and active/idle status; clamps >100%; severity by max usage; reads token-aware data from the sharedQuotaManagercache and marks the first account that passes policy.Bug Fixes
onFallbackStorageChangedinFallbackAccountManager.Written for commit 4b7a88c. Summary will update on new commits.
Greptile Summary
This PR adds a quota-usage toast notification after main quota refreshes (both cold-start and periodic background) and fixes the bug where async background refreshes would clobber the active fallback account back to
mainin the sidebar. It also wiresonFallbackStorageChangedinFallbackAccountManagerso the sidebar updates automatically when background fallback quota refreshes persist storage changes.showQuotaToast/showQuotaToastFromCachewithquotaBar,quotaLine, andformatResetInhelpers; toast variant (info/warning/error) reflects the highestusedPercentacross all shown accounts.lastSidebarRoutingstate andrefreshSidebarQuota()to preserve the actual active-account label across quota-only sidebar refreshes, specifically targeting the async background-refresh clobber race.onFallbackStorageChangedcallback toFallbackAccountManager(fired fromrefreshQuotaForDueAccountswhen storage changes) and wires it torefreshSidebarQuota().Confidence Score: 4/5
Safe to merge; the core logic is correct and well-tested, with one minor interaction between the new lastSidebarRouting mechanism and the pre-existing /claude-quota command handler.
The async-clobber fix is solid and covered by integration tests. The one notable rough edge is that the pre-existing /claude-quota command handler still calls writeSidebarState with a hardcoded activeId:'main', which now also resets lastSidebarRouting — so a background refresh landing after a quota command continues showing 'main' as active even when a fallback is serving, until the next real request corrects it. It doesn't affect routing correctness, only display accuracy.
packages/opencode/src/index.ts around the CLAUDE_QUOTAS_COMMAND_NAME handler (lines 847–863)
Important Files Changed
Reviews (5): Last reviewed commit: "Merge branch 'fix/sidebar-fallback-quota..." | Re-trigger Greptile