Repository navigation
feat: rotate a pool of Command Code keys on credential failures - #9
Merged
Merged
Conversation
JoshRob297
force-pushed
the
feat/key-rotation
branch
from
October 31, 2026 18:27
874c0d5 to
547ba09
Compare
A plan can hold several API keys. With two or more (COMMANDCODE_API_KEYS, COMMANDCODE_KEYS_FILE or ~/.config/commandcode/keys.txt) the plugin now picks the first key that is not cooling down, records 24h cooldowns for 402/401/403, honours Retry-After up to 6h for 429, and never blames the key for 5xx. State is labels-only and logged without secrets; single-key mode keeps the previous behaviour and never overrides a host header.
JoshRob297
force-pushed
the
feat/key-rotation
branch
from
October 31, 2026 18:28
547ba09 to
39d7271
Compare
JoshRob297
marked this pull request as ready for review
October 31, 2026 18:29
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.
Stacked on #8 (ZDR). Rebase to main once #8 merges.
Context
A Command Code plan can hold several API keys (one per account). Today a key that hits
402 insufficient creditsor a rate-limit window keeps failing every request until the user edits the key file, which is what happened with the $0.07 account.Change
src/auth/pool.ts: pool loading (COMMANDCODE_API_KEYS,COMMANDCODE_KEYS_FILE,~/.config/commandcode/keys.txtwithlabel=keylines), selection, cooldown mapping, state persistence.Authorizationheader.Authorizationheader on the strict Command Code host, because the host-injected key may be the one that just returned 402.commandcode-keys-state.json, 0600) and each cooldown is appended tocommandcode-rotation.logwithout secrets.Verify
bun test: 120 pass, 3 skip, 0 fail (newtests/pool.test.tscovers parsing, selection, cooldown mapping, Retry-After, rotation through the real plugin hooks, lookalike host, single-key regression).bunx tsc --noEmit: clean.