Skip to content

fix: retry transient GitHub API failures and never fail on comment posting - #68

Merged
JarbasAl merged 1 commit into
devfrom
fix/pr-comment-retry-nonfatal
Jul 16, 2026
Merged

fix: retry transient GitHub API failures and never fail on comment posting#68
JarbasAl merged 1 commit into
devfrom
fix/pr-comment-retry-nonfatal

Conversation

@JarbasAl

Copy link
Copy Markdown
Member

A transient GitHub API 5xx raised out of github_api() and failed the whole job. On a PR where ruff, the health check, the license scan, pip-audit and the build all passed, five checks went red — the failing step in each was only "Post

to PR comment". During an API blip this reds out green PRs across every repo in the org and blocks merges.

Two changes, both in scripts/update_pr_comment.py:

  • github_api() retries transient failures (500/502/503/504, and 403/429 when GitHub signals throttling via Retry-After, x-ratelimit-reset, or a rate-limit message) with bounded exponential backoff plus jitter, capped at 30s over 5 attempts. Deterministic 4xx such as 404/422 raise on the first response.
  • Posting the summary is cosmetic, so main() catches URLError (which covers HTTPError), logs a warning and exits 0. This subsumes the existing fork read-only-token case, and every consuming workflow benefits without needing its own continue-on-error.

Regression tests cover the 503-then-200 retry, retry exhaustion, no-retry on 404/422 and on a plain non-throttled 403, Retry-After being honoured, bounded backoff, and comment-post failure exiting 0. Sleep is patched throughout.

🤖 Generated with Claude Code

…sting

github_api retries 5xx and throttled 403/429 responses with bounded
exponential backoff and jitter, honouring Retry-After and
x-ratelimit-reset when GitHub sends them. Deterministic 4xx responses
raise immediately.

Posting a section into the PR comment is a cosmetic summary of work that
already succeeded, so an unreachable API leaves a warning and exits 0
instead of failing the calling check.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@JarbasAl
JarbasAl marked this pull request as ready for review July 16, 2026 23:04
@JarbasAl
JarbasAl merged commit 8889229 into dev Jul 16, 2026
6 checks passed
@JarbasAl
JarbasAl deleted the fix/pr-comment-retry-nonfatal branch July 16, 2026 23:06
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