feat(#160): Add token-bucket rate limiting to AgamemnonClient#268
Open
mvillmow wants to merge 2 commits into
Open
feat(#160): Add token-bucket rate limiting to AgamemnonClient#268mvillmow wants to merge 2 commits into
mvillmow wants to merge 2 commits into
Conversation
mvillmow
commented
Jun 20, 2026
mvillmow
left a comment
Contributor
Author
There was a problem hiding this comment.
Correct, complete, disabled-by-default; env binding fixed+tested. Two minor findings: off-scope backoff cap, stale test-math comment. GO.
Implement a configurable token-bucket rate limiter applied to all outbound Agamemnon HTTP calls, resolving the burst API call issue in _provision_agents. The limiter is integrated at a single chokepoint (AgamemnonClient._request_with_retry) for comprehensive coverage across all endpoints. - Add TokenBucket rate limiter (src/telemachy/rate_limiter.py) with async acquire() that waits for tokens at a configurable rate and burst size - Integrate into AgamemnonClient.__init__ with rate_limit_rps and rate_limit_burst - Add AGAMEMNON_RATE_LIMIT_RPS and AGAMEMNON_RATE_LIMIT_BURST env vars (default off, burst >= 1 validated via Pydantic Field) - Cap retry backoff at 2.0s per nats-publish-retry-backoff team-knowledge guidance - Comprehensive test coverage: 7 rate_limiter tests, 4 config tests, 3 client tests, 1 executor integration test - All 64 existing tests still pass; zero regressions Closes #160 Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com> Signed-off-by: mvillmow <4211002+mvillmow@users.noreply.github.com>
GHSA-4xgf-cpjx-pc3j) Signed-off-by: Micah Villmow <4211002+mvillmow@users.noreply.github.com>
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.
Summary
Add a configurable token-bucket rate limiter to all outbound Agamemnon HTTP calls, resolving issue #160 (burst API calls in
_provision_agents). The limiter is integrated at a single chokepoint (AgamemnonClient._request_with_retry) for comprehensive coverage across all endpoints and request patterns.Implementation Details
src/telemachy/rate_limiter.py— AsyncTokenBucketclass withacquire(n)that refills at a configurable rate and caps at a burst sizeAgamemnonClientnow acceptsrate_limit_rpsandrate_limit_burstkwargs; callsacquire()before each HTTP request attemptAGAMEMNON_RATE_LIMIT_RPS(default0, disabled) andAGAMEMNON_RATE_LIMIT_BURST(default16, must be>= 1)min(2**attempt, 2.0)per team-knowledgenats-publish-retry-backoffguidance to prevent unbounded delaysTesting
TokenBucketcovering burst consumption, refill, and disabled stateVerification
Closes #160
Co-Authored-By: Claude Haiku 4.5 noreply@anthropic.com