Skip to content

Add 429-aware retry/backoff to Grain API client - #3

Draft
dplakon wants to merge 1 commit into
mainfrom
fix/grain-client-429-retry
Draft

Add 429-aware retry/backoff to Grain API client#3
dplakon wants to merge 1 commit into
mainfrom
fix/grain-client-429-retry

Conversation

@dplakon

@dplakon dplakon commented Jul 17, 2026

Copy link
Copy Markdown

Summary

The daily Grain → Notion pipeline was failing intermittently because the Grain API client had no retry handling for transient rate limits. fetch_daily_meetings.py paginates through all recordings via list_all_recordings, and a single 429 Too Many Requests mid-pagination aborted the entire run.

Changes

  • Add _urlopen_with_retry to scripts/grain_client.py with exponential backoff that honors the Retry-After header and retries on 429 and 5xx responses (plus transient network errors).
  • Route both _get and get_transcript_text through the retry helper.
  • Retry behavior is tunable via GRAINIAC_MAX_RETRIES, GRAINIAC_RETRY_BASE_DELAY, and GRAINIAC_RETRY_MAX_DELAY env vars.

Context

Discovered while running the grainiac-orchestrator daily pipeline: the fetch repeatedly failed with HTTP Error 429 until this retry logic was added, after which today's 3 meetings fetched successfully.

Conversation: https://app.warp.dev/conversation/a5d08c69-0a16-4505-9a19-ff9c7f384e08
Run: https://oz.warp.dev/runs/019f71ae-483f-7a37-900c-b6dab7580270

This PR was generated with Oz.

The daily meeting fetch paginates through all recordings via list_all_recordings,
but _get had no retry handling, so a single transient 429 (Too Many Requests)
mid-pagination aborted the entire run. This made fetch_daily_meetings.py fail
intermittently under Grain rate limits.

Add _urlopen_with_retry with exponential backoff that honors the Retry-After
header and retries on 429 and 5xx responses (and transient network errors).
Route both _get and get_transcript_text through it. Retry counts and delays are
tunable via GRAINIAC_MAX_RETRIES / GRAINIAC_RETRY_BASE_DELAY / GRAINIAC_RETRY_MAX_DELAY.

Co-Authored-By: Oz <oz-agent@warp.dev>
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