Skip to content

feat(opencode): show quota usage toast after quota refresh#36

Open
iceteaSA wants to merge 2 commits into
cortexkit:mainfrom
iceteaSA:feat/quota-toast
Open

feat(opencode): show quota usage toast after quota refresh#36
iceteaSA wants to merge 2 commits into
cortexkit:mainfrom
iceteaSA:feat/quota-toast

Conversation

@iceteaSA
Copy link
Copy Markdown
Contributor

@iceteaSA iceteaSA commented May 21, 2026

Dependency: Requires #34 (QuotaManager) to be merged first. Branch is based on feat/quota-manager.

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 per account
  • Toast variant reflects severity: info (<70%), warning (≥70%), error (≥90%)
  • Clamped bar rendering prevents RangeError on >100% utilization

Single file change: packages/opencode/src/index.ts (+127 lines)


Summary by cubic

Adds a quota usage toast and a unified QuotaManager in @cortexkit/anthropic-auth-core to cache, deduplicate, and rate‑limit quota API calls for main and fallback accounts, reducing rate-limit errors and improving routing reliability.

  • New Features

    • Show quota toast via client.tui.showToast with bars, percent, reset time, and active account indicator; variant reflects usage (info/warning/error) and clamps >100%.
    • Introduced QuotaManager with shared cache for main/fallback, inflight dedup, a serial API gate (1s gap) plus cross‑process file lock, exponential backoff (60s–15m) for 429/5xx, request‑count refresh trigger, and persistence of main quota/backoff via callbacks.
  • Refactors

    • Integrated QuotaManager with FallbackAccountManager and request routing: seeds from disk, shared staleness checks, background refresh, and overlay of cached fallback quotas for display.
    • Added fail‑closed path: when failClosedOnUnknownQuota is set, no cached quota, and the quota API is backed off, return 429 with Retry‑After and a backoff message.
    • Tests updated and added for the new quota flow, including a QuotaManager suite.

Written for commit 18123ae. Summary will update on new commits. Review in cubic

Unified quota cache and API gateway for main + fallback quota state.
All consumers share one QuotaManager instance for consistent caching.

Features:
- Inflight deduplication prevents concurrent API calls
- Exponential backoff (60s-15min) for 429/5xx errors
- Persists main quota and backoff state to disk via callbacks
- Cross-process file lock guard for quota API dedup
- Seeds from persisted storage on construction
- Integrates with FallbackAccountManager for shared staleness
- Captures storage path at init to prevent test config corruption
- Request-count-based refresh trigger (refreshEveryNRequests)
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

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

Comment thread packages/opencode/src/index.ts
Comment thread packages/core/src/quota-manager.ts
Comment thread packages/core/src/quota-manager.ts
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%).
@iceteaSA iceteaSA force-pushed the feat/quota-toast branch from 4e7ccc0 to 18123ae Compare May 21, 2026 20:05
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.

1 participant