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 shared QuotaManager in @cortexkit/anthropic-auth-core to unify main/fallback quota caching, serialize and back off usage API calls, persist quota/backoff state, and reduce 429s across the OpenCode plugin and routing.

  • New Features

    • Show quota toast via client.tui.showToast with bars, % and reset time; highlights the active account; variants info/warning/error; clamps >100%.
    • Add QuotaManager: unified main/fallback cache with inflight dedup, 1s serial API gate + cross‑process file lock, exponential backoff (60s–15m) for 429/5xx/network errors, seeding from disk, and request‑count trigger (refreshEveryNRequests).
    • Persist main quota and backoff via plugin callbacks so cache survives restarts and seeds the shared cache at boot.
    • Fail‑closed path: when failClosedOnUnknownQuota is set, no cached main quota, and the quota API is backed off, return 429 with Retry-After.
  • Refactors

    • Integrate QuotaManager with FallbackAccountManager and OpenCode routing/loader: shared staleness checks, background refresh, and overlay cached fallback quotas for display.
    • Extend AccountStorage.quota with refreshEveryNRequests, mainQuota, mainQuotaCheckedAt, and mainLastQuotaApiError; add backoff helpers and messages; add QuotaManager test suite and update plugin tests.

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

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 Outdated
Comment thread packages/core/src/quota-manager.ts
@iceteaSA iceteaSA force-pushed the feat/quota-toast branch 3 times, most recently from a69aab5 to 4601bd8 Compare May 22, 2026 16:52
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)
@iceteaSA iceteaSA force-pushed the feat/quota-toast branch from 4601bd8 to 4ad7d49 Compare May 22, 2026 16:58
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 4ad7d49 to b20b6c0 Compare May 22, 2026 17:08
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