Skip to content

Retry transient GitHub gateway errors - #872

Closed
CAOShurong wants to merge 2 commits into
ossf:mainfrom
CAOShurong:codex/57-retry-gateway-errors
Closed

CAOShurong wants to merge 2 commits into
ossf:mainfrom
CAOShurong:codex/57-retry-gateway-errors

Conversation

@CAOShurong

@CAOShurong CAOShurong commented Aug 13, 2026 •

Copy link
Copy Markdown

Summary

  • retry GitHub API responses with status 502 or 504 using exponential backoff
  • limit automatic retries to idempotent HTTP methods so issue/comment creation and other non-idempotent mutations are not duplicated
  • preserve the final gateway response when the retry budget is exhausted

The implementation reuses go-retryablehttp, which was already present in the module graph, and applies the retry transport to both app-level and installation-level GitHub clients.

Fixes #57.

Original validation (August, head 7f1fc906)

  • go test ./pkg/ghclients -count=1
  • real httptest + go-github paths: 502 -> 504 -> 200, non-gateway 500, non-idempotent POST, and persistent 504
  • go test for every package except pkg/scorecard
  • go build ./...
  • go vet ./...
  • go mod verify
  • golangci-lint run --timeout 5m --new-from-rev=HEAD

These are the original recorded checks, not a claim that the full matrix was rerun in October. The original Windows pkg/scorecard TestLocal failure after a temporary go-git/go-git clone reported unstaged changes was retained in the earlier validation record.

October 3 comment-only follow-up

The newRetryRoundTripper comment now explicitly says HTTP 502/504 responses, not all request timeouts. No executable code changed.

Current local checks:

  • go test -p 2 ./pkg/ghclients -count=2 -v: passed on the original head after one dependency-download retry, and passed twice on the comment-only tree. The existing tests exercise real HTTP success, persistent 504, non-gateway 500 and non-idempotent POST paths.
  • go test -p 2 ./pkg/ghclients ./pkg/config/... -count=1 -v: passed.
  • go test -p 2 ./pkg/ghclients ./pkg/config/... -count=2 -v: failed in pkg/config.TestGetIL on its second iteration. The same Get not called assertions reproduce with go test -p 2 ./pkg/config -count=2 -v in an untouched archive of 7f1fc906; the test retains installation-cache state between iterations. This is not a fully passing repeated related-package suite.
  • go vet -p 2 ./pkg/ghclients and go build -p 2 ./pkg/ghclients: passed.
  • gofmt -d pkg/ghclients/retry.go and git diff --check: clean.
  • golangci-lint run --concurrency 2 --timeout 3m --new-from-rev=HEAD ./pkg/ghclients/...: passed with the available v2.9.0 tool and Go 1.25.12. This is package-scoped local lint, not the repository's v2.4 CI matrix.

The first original-head test attempt failed before compilation because the golang.org/x/text@v0.39.0 zip download returned unexpected EOF; its single retry passed. Test/vet/build commands used Windows Go 1.26.7, CGO disabled. A full-repository rerun, race tests, new release/install validation and a live authenticated GitHub App deployment were not performed for this comment-only change. Public CI and maintainer review remain separate gates.

AI assistance

This PR was developed with OpenAI Codex assistance. Codex performed the October 3 source inspection and local checks above. No independent human review or live deployment is claimed.

Retry 502 and 504 responses for idempotent GitHub API requests while preserving final responses and avoiding duplicate non-idempotent mutations.

Assisted-by: OpenAI Codex <noreply@openai.com>
Signed-off-by: Shurong Cao <170531907+CAOShurong@users.noreply.github.com>
@CAOShurong
CAOShurong requested a review from a team as a code owner August 13, 2026 07:59
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Aug 13, 2026
@github-actions

Copy link
Copy Markdown

This pull request has been marked stale because it has been open for 10 days with no activity

@github-actions github-actions Bot added the Stale label Aug 24, 2026
@CAOShurong

Copy link
Copy Markdown
Author

Not stale — still ready for review. The branch is up to date and mergeable; no rebase needed. Happy to address any feedback on the retry implementation (pkg/ghclients/retry.go) if anything needs adjusting.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The retry behavior is narrowly scoped (idempotent + 502/504), covered by focused tests, and integrates cleanly with existing client construction (only a minor doc-comment alignment suggested).

Pull request overview

This PR adds a retrying HTTP transport for GitHub API calls to mitigate intermittent GitHub gateway failures (502/504), while avoiding unsafe retries for non-idempotent requests. It plugs the retry transport into the existing app/installation GitHub client construction in pkg/ghclients.

Changes:

  • Added a go-retryablehttp-backed RoundTripper that retries only HTTP 502/504 for idempotent methods.
  • Applied the retrying transport to the GitHub clients created by GHClients.Get.
  • Added httptest-based coverage for retry/no-retry behavior and “return last response” behavior; promoted go-retryablehttp to a direct dependency.
File summaries
File Description
pkg/ghclients/retry.go Introduces the retrying transport + idempotency gating logic for 502/504.
pkg/ghclients/retry_test.go Adds tests covering retry behavior, idempotency constraints, and returning the last gateway response.
pkg/ghclients/ghclients.go Wraps the existing per-installation/app transport with the retrying transport when building the GitHub client.
go.mod Promotes github.com/hashicorp/go-retryablehttp to a direct dependency.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pkg/ghclients/retry.go Outdated
Comment on lines +24 to +26
// newRetryRoundTripper retries the transient gateway errors that GitHub uses
// when an idempotent API request times out. The retryable client applies
// exponential backoff and stops when the request context is canceled.
@github-actions

Copy link
Copy Markdown

This pull request has been marked stale because it has been open for 10 days with no activity

Align the retry transport comment with the existing HTTP 502 and 504 behavior.

Assisted-by: OpenAI Codex <noreply@openai.com>
Signed-off-by: CAOShurong <170531907+CAOShurong@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files. Stale

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Add retry to transport

2 participants