Skip to content

miniswen: share rate-limit backoff across concurrent trials - #22

Open
gfortaine wants to merge 1 commit into
rails:mainfrom
gfortaine:feat/shared-rate-limit-backoff
Open

gfortaine wants to merge 1 commit into
rails:mainfrom
gfortaine:feat/shared-rate-limit-backoff

Conversation

@gfortaine

Copy link
Copy Markdown

With -c N, each trial retries a rate-limited provider on its own schedule. When one trial gets a 429/529 with retry-after, the other N−1 keep sending into the same exhausted limit, each burning retries from the ~10-minute budget, and a heavy run can turn one limit into a storm.

Miniswen::SharedBackoff is a Faraday middleware installed next to the adapter on every ruby_llm connection, in the same way as the existing transport tweaks. It keeps one resume time per host, shared by the trials' threads:

  • a 429/529 with retry-after (seconds or HTTP date) pauses that host for the given time;
  • an Anthropic response whose anthropic-ratelimit-*-remaining is 0 pauses until the matching *-reset, so the next call waits instead of drawing a 429;
  • pauses are capped at retry_max_interval, and other hosts are unaffected.

Waiting happens before the request, inside the existing retry loop. Retry counts and intervals are unchanged; only the timing of calls to an already rate-limited host changes. As with retries today, the wait counts toward the trial's wall-clock limit.

We use the same idea, across processes, for a 4- to 6-trial-concurrent run against the direct Anthropic, OpenAI and Gemini APIs.

Tests: test/miniswen/shared_backoff_test.rb (3 runs). bundle exec rake test passes (348 runs, 0 failures) and bundle exec rubocop is clean.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant