Retry Grain API rate limits with exponential backoff - #17
Draft
dplakon wants to merge 1 commit into
Draft
Conversation
The daily fetch was failing with `HTTP Error 429: Too Many Requests` partway through pagination: `list_all_recordings` walked pages back to back with no delay and `_get` raised on the first error response, so a single rate-limited page aborted the whole run. - Add `_request`, a shared GET helper that retries 429s and transient 5xx/network errors with exponential backoff, honoring `Retry-After` when the API sends it. - Route `_get` and `get_transcript_text` through the new helper so transcript fetches get the same treatment. - Pause briefly between paginated list requests and between per-recording hydration requests, tunable via `GRAINIAC_PAGE_DELAY`. Co-Authored-By: Warp <agent@warp.dev>
Author
|
This PR was generated with Warp. Comment |
|
Your Warp account is not a member of any team with access to this repository. |
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.


Problem
Today's daily run of
scripts/fetch_daily_meetings.pyfailed twice with:Two issues combined to make this fatal:
list_all_recordingswalks up to 100 pages back-to-back with no delay, so a busy account reliably trips Grain's rate limit._getraised on the first non-2xx response, so one rate-limited page aborted the entire run — even though the earlier pages had succeeded.hydrate_with_participantshas the same problem: it makes one request per recording of the target day with no pacing.Changes
_request, a shared GET helper that retries429and transient500/502/503/504/network errors with exponential backoff (6 attempts, starting at 2s), honoring theRetry-Afterheader when Grain provides one._getandget_transcript_textboth route through the new helper, so transcript fetches in the per-meeting processor get the same protection.GRAINIAC_PAGE_DELAYenv var (default1.0seconds).Verification
Before this change the fetch failed on the second page of pagination on two consecutive attempts, ~45s apart. After the change, the same command completed end to end:
The 10 meetings were then handed off to per-meeting child agents as usual.