Skip to content

fix(bot): wait out a near GraphQL rate limit and retry once - #204

Merged
jamesconwaydev merged 1 commit into
devstreamhq:mainfrom
foothillsdigital:fix/graphql-rate-limit-retry
Nov 6, 2026
Merged

jamesconwaydev merged 1 commit into
devstreamhq:mainfrom
foothillsdigital:fix/graphql-rate-limit-retry

Conversation

@foothillsdigital

Copy link
Copy Markdown
Collaborator

What and why

Closes #47. This is the part left open after #199: retrying a GraphQL RATE_LIMITED error instead of raising straight away.

graphql() now handles it the way _request handles a REST rate limit. If x-ratelimit-reset is within MAX_SLEEP, it sleeps until then and sends the document once more. If the reset is further off, or the retry is limited too, it raises RateLimited as before, so spends_attempt and the callers see no change. With no reset header it still assumes a minute.

Mutations get the retry too. GraphQL works out a document's point cost before running it, so a rate-limited document never ran and sending it again can't duplicate anything.

Tests: a query and a mutation each get limited once with a reset 30s out, then succeed after one sleep. The existing test_graphql_rate_limited now also checks the far-off reset raises without sleeping, and the 60s fallback sleeps once and then raises. Both fail on main.

Checks

  • The PR title follows Conventional Commits
  • python3 -m unittest discover -s scripts -t . passes
  • npm --prefix site test passes (if you touched site/)
  • npx prettier --check . passes
  • This doesn't edit data/entries.json by hand (submissions go through the form)

A RATE_LIMITED GraphQL error raised straight away, even when the
limit reset in a few seconds. It now gets the same treatment as a
REST rate limit: if the reset is within MAX_SLEEP, sleep until then
and send the document again once; otherwise raise RateLimited as
before. GitHub rejects a rate-limited document before running it, so
mutations are retried too.

@jamesconwaydev jamesconwaydev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call making it match the REST path: one wait for a near reset, then raise. I'm happy with mutations getting the retry too, since a RATE_LIMITED document is refused before it runs. Thanks for picking up the last bit of #47.

@jamesconwaydev
jamesconwaydev merged commit c39250d into devstreamhq:main Nov 6, 2026
9 checks passed
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.

Harden the GitHub client's edge cases

2 participants