feat(opencode): killswitch — block requests when quota drops below threshold#35
Open
iceteaSA wants to merge 1 commit into
Open
feat(opencode): killswitch — block requests when quota drops below threshold#35iceteaSA wants to merge 1 commit into
iceteaSA wants to merge 1 commit 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
d89dd9d to
f667649
Compare
b2399cf to
4fdf006
Compare
…reshold Self-review fixes folded in: - Token-aware fail-closed read: const mainQuota = quotaManager.getMain(auth.access) so a previous main account's cached quota can't satisfy the fail-closed check or feed the killswitch eval after a main-account switch. - Removed a stray inner 'let sessionRequestCount = 0' + unconditional increment that shadowed the process-scoped counter, which had left the active-route fallback every-N refresh reading a never-incremented counter.
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 unified
QuotaManagerin@cortexkit/anthropic-auth-coreso OpenCode blocks low‑quota requests, shares a single quota cache, and returns clear 429s with Retry‑After when all accounts are exhausted or the quota API is backed off.New Features
/claude-killswitchto view/toggle/set with persisted config; enable viakillswitchin the sidecar; optionalquota.refreshEveryNRequests.QuotaManager: one path for main + fallbacks with shared cache, inflight dedup, short serial gate, exponential backoff; treats 401 as auth (no backoff);/claude-quotaforces real refresh and persists; seeds from storage; every‑N and background refresh; skips request‑time refresh when backed off.Bug Fixes
getMain(auth.access)) and token‑bound fallback cache entries prevent cross‑account reuse.failClosedOnUnknownQuotais set and quota API is backed off with no cached quota, return 429 with aretry-afterfrom the backoff; count all replayable requests for the every‑N cadence and remove a shadowed counter.Written for commit 0054553. Summary will update on new commits.