feat: add configurable tokens-per-minute rate limiting - #1131
Merged
avoidwork merged 6 commits intoSep 21, 2026
Merged
Conversation
Add OpenSpec change for configurable maxTokensMinute rate limiting: - RateLimitSchema gains maxTokensMinute (non-negative int, default 0) - New provider-token-budget capability for rolling 60s token window - Wire throttle into createChatModel dispatch - Attribute 429 errors to exceeded token budget
Add maxTokensMinute to RateLimitSchema (non-negative int, default 0). Create rolling 60-second token budget module (src/provider/tokenBudget.js) with consume, current, and waitForCapacity. Wire the throttle into createChatModel dispatch: estimate request cost (input + maxTokens), wait for capacity, then consume before invoking. Attribute 429 errors to an exceeded token budget when the rolling window exceeds the limit. Document maxTokensMinute example in config.yaml. Add unit tests for the token budget and throttle wiring.
Archive the OpenSpec change and sync provider-token-budget and provider-rate-limit-config specs into openspec/specs/.
Owner
Author
Implementation Audit Results — configurable-tokens-per-minute-rate-limitingAudit SummaryIteration: 1 Goal Fulfillment
Spec Compliance
Task CompletionAll 18 tasks marked Quality Check
Verification Results
Notes
|
avoidwork
deleted the
feat/configurable-tokens-per-minute-rate-limiting
branch
September 21, 2026 17:41
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.
Description
Adds a configurable
maxTokensMinutesetting to the provider rate-limit config that paces outgoing LLM requests against a rolling 60-second tokens-per-minute budget. Defaults to0(disabled) so the throttle is opt-in. When enabled, the harness estimates request token cost (input viacalculateConversationTokens+maxTokensoutput budget), waits for capacity in the rolling window, and consumes the estimated cost before dispatching.On a
429rate-limit response, the request is retried once after theretry-afterheader value (seconds or HTTP-date), defaulting to 60 seconds when no header is present. This retry only applies whenmaxTokensMinuteis enabled; when it is0, no retry occurs and the error surfaces immediately.429errors are attributed to an exceeded token budget when the rolling window exceedsmaxTokensMinute.Type of Change
Testing
Unit tests in
tests/unit/provider/tokenBudget.test.js(11 tests) cover: window eviction after 60s, disabled path (maxTokensMinute: 0), exactly-at-limit, single request larger than the whole budget, and rapid successive requests.tests/unit/provider.test.jscovers the throttle-wiring (enabled/disabled paths), 429 attribution, the single 429 retry, and thegetRetryDelayMshelper (retry-after parsing + 60s default). Verified withnpm run test(3860 passing),npm run lint(0 errors), andnpm run coverage(tokenBudget.js 100% statements).Coverage
Checklist
npm run lintpassesCloses #1130