Repository navigation
Retry transient GitHub gateway errors - #872
CAOShurong wants to merge 2 commits into
Conversation
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>
|
This pull request has been marked stale because it has been open for 10 days with no activity |
|
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. |
There was a problem hiding this comment.
🟢 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-backedRoundTripperthat 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; promotedgo-retryablehttpto 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.
| // 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. |
|
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>
Summary
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=1httptest+go-githubpaths: 502 -> 504 -> 200, non-gateway 500, non-idempotent POST, and persistent 504go testfor every package exceptpkg/scorecardgo build ./...go vet ./...go mod verifygolangci-lint run --timeout 5m --new-from-rev=HEADThese are the original recorded checks, not a claim that the full matrix was rerun in October. The original Windows
pkg/scorecardTestLocalfailure after a temporarygo-git/go-gitclone reported unstaged changes was retained in the earlier validation record.October 3 comment-only follow-up
The
newRetryRoundTrippercomment 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 inpkg/config.TestGetILon its second iteration. The sameGet not calledassertions reproduce withgo test -p 2 ./pkg/config -count=2 -vin an untouched archive of7f1fc906; the test retains installation-cache state between iterations. This is not a fully passing repeated related-package suite.go vet -p 2 ./pkg/ghclientsandgo build -p 2 ./pkg/ghclients: passed.gofmt -d pkg/ghclients/retry.goandgit 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.0zip 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.