fix(policy-bot): Retry GitHub 502 responses when loading policy#7
Open
wrannaman wants to merge 3 commits into
Open
fix(policy-bot): Retry GitHub 502 responses when loading policy#7wrannaman wants to merge 3 commits into
wrannaman wants to merge 3 commits into
Conversation
api.github.com intermittently returns 502 on
GET /repos/{owner}/{repo}/contents/.policy.yml. isServerError only
treated 500, 503 and 504 as retryable, so a single 502 skipped the
backoff loop entirely, surfaced as a LoadError, and posted a red
"Error loading policy from <org>/<repo>@main" status. The underlying
httpcache entry is also evicted on any non-200, so the next request
could not fall back to the last known good policy.
Observed on the wonderlydotcom installation: six load errors in 100
minutes across backend-net and internal-tool-camp, every one a 502,
each self-healing on the next webhook. A merge_group receives a single
checks_requested delivery, so a 502 there leaves the status red and
boots the PR from the queue.
429 is deliberately not added: go-github converts 429 and rate-limited
403 into *RateLimitError / *AbuseRateLimitError, which never satisfy
errors.As(err, &ghErr), so such a case would be unreachable.
Also corrects a stale expectation in TestParseConfigPostsStatusForSeenPolicy,
which still asserted the "policy-bot: main" status context after this
branch dropped the branch suffix. It was failing before this change.
golangci-lint (unused) fails Verify on this branch: policy/approval/approve_test.go:34:6. The helper has zero references repo-wide and was orphaned by 2872525.
The Dist job's comment says these steps should only run when publishing, but the guard was lost when Docker Hub was swapped for GCR. secrets.GCR_JSON_KEY is not exposed to pull_request events, so docker/login-action fails with 'Password required' on every PR. Dist has failed on all PRs since 2026-04-02, including PRs opened from usemotion-patches itself. Upstream guards the equivalent steps with 'github.event_name == push || github.event_name == release'. Excluding only pull_request preserves the current push and release behaviour.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
isServerErrortreats only500,503and504as retryable.api.github.comintermittently returns502onGET /repos/{owner}/{repo}/contents/.policy.yml, so a single 502 skips the existing 3x backoff loop, becomes aLoadError, and posts a redError loading policy from <org>/<repo>@mainstatus.httpcachealso evicts the cached entry on any non-200, so the next request cannot fall back to the last known good policy.This adds
http.StatusBadGatewayto the retryable set.Evidence
From the running deployment (
policy-bot-7cb7f8659-ml7tp, mgmt cluster), six load errors in 100 minutes, every one a 502, each self-healing on the next webhook:check_runissue_commentcheck_runcheck_runworkflow_runcheck_runA
merge_groupreceives a singlechecks_requesteddelivery. A 502 there leaves the status red permanently and boots the PR from the merge queue.Why not also 429
Deliberately omitted.
go-githubconverts429and rate-limited403into*RateLimitError/*AbuseRateLimitError(github.go:1536-1548), neither of which satisfieserrors.As(err, &ghErr)for*github.ErrorResponse. AddingStatusTooManyRequeststo that switch would be unreachable code.Tests
TestIsServerError— table over 500/502/503/504 (retryable) and 403/404/422/non-GitHub errors (not).TestConfigFetcherRetriesBadGateway— loader returns 502 once, then succeeds; asserts two calls and noLoadError. Fails onusemotion-patcheswithout this change, with the exact production error (502 []).Also fixes a stale expectation in
TestParseConfigPostsStatusForSeenPolicy, which still asserted thepolicy-bot: mainstatus context after this branch dropped the branch suffix. It was already failing onusemotion-patchesbefore this change;go test ./server/handler/...andgo vet ./server/...are now clean.