feat(opencode): killswitch — block requests when quota drops below threshold#35
Open
iceteaSA wants to merge 2 commits into
Open
feat(opencode): killswitch — block requests when quota drops below threshold#35iceteaSA wants to merge 2 commits into
iceteaSA wants to merge 2 commits into
Conversation
This was referenced May 21, 2026
There was a problem hiding this comment.
2 issues found across 10 files
Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.
Fix all with cubic | Re-trigger cubic
65f5a21 to
a4ba530
Compare
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)
…reshold Per-account request blocking when remaining quota drops below configurable thresholds. Returns synthetic 429 when all accounts (main + fallbacks) are below their thresholds. Includes /claude-killswitch slash command for runtime management. Features: - Per-account threshold overrides (5h and 7d windows) - Eager quota refresh on first request for killswitch evaluation - Skip-main routing when main is killed (try surviving fallbacks) - Filter killed accounts from reactive fallback path - Retry-After header with earliest quota reset time
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.
Per-account request blocking when remaining quota drops below configurable thresholds. Returns synthetic 429 when all accounts (main + fallbacks) are below their thresholds.
Features:
/claude-killswitchslash command for runtime management (on/off/set thresholds)Files:
packages/core/src/killswitch.ts— new (164 lines)packages/core/src/accounts.ts— killswitch types and policy functionspackages/opencode/src/index.ts— killswitch check in fetch handler, command registrationpackages/opencode/src/tests/killswitch.test.ts— new (501 lines)README.md+packages/opencode/README.md— killswitch documentationSummary by cubic
Adds a per-account killswitch and a shared
QuotaManagerto OpenCode to block requests before hitting Anthropic limits and unify quota caching/backoff across main and fallback accounts. Integrated into routing and/claude-quota, with/claude-killswitchfor quick runtime control.New Features
5h/1waliases), skip-main routing and filtered fallbacks, synthetic 429 withretry-after(earliest reset + 60s) when all accounts are killed, eager quota refresh, and/claude-killswitchto view/toggle/set thresholds with persisted config.QuotaManagerin@cortexkit/anthropic-auth-core: unified main/fallback quota cache with inflight dedup, serial API gate (1s min gap), exponential backoff (60s–15m) for 429/5xx, cross-process file-lock, seeds from disk, persists main quota/backoff via callbacks; supports request-count refresh withquota.refreshEveryNRequests./claude-quotanow read fromQuotaManager;FallbackAccountManagerseeds/uses the shared cache and staleness; fail-closed 429 (with backoff-basedretry-after) when the quota API is backed off and no cached quota exists (honorsfailClosedOnUnknownQuota).Migration
killswitchblock to the sidecar config (defaults off).quota.refreshEveryNRequeststo force periodic quota refresh.Written for commit f667649. Summary will update on new commits. Review in cubic