Skip to content

test(github): retry transient GitHub errors and base stacked fixtures on known heads - #1180

Draft
sbalabanov wants to merge 1 commit into
mainfrom
sergeyb/test-githubtestrepo-retry
Draft

sbalabanov wants to merge 1 commit into
mainfrom
sergeyb/test-githubtestrepo-retry

Conversation

@sbalabanov

@sbalabanov sbalabanov commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

TLDR: the live GitHub test helper now retries transient GitHub errors and builds stacked fixtures from known heads, which targets the two main causes of red live-suite runs.

Summary

  • send retries transport errors, 500/502/503/504, and 403/429 only when Retry-After is present (secondary rate limit). Retry-After is also honoured on 5xx, up to the 60 s cap. It makes at most 4 attempts with a bounded, injectable backoff and a 60 s Retry-After cap. A 403/429 without Retry-After (primary limit or permissions) still fails fast.
  • Branch, pull request and file creation tolerate their own earlier success when a 5xx hid it. An "already exists" 422 on POST git/refs or POST pulls is reconciled by reading the existing object; other 422s keep GitHub's message. CommitFile retries read-then-write as a unit, skips the write if the content already landed, and identifies the writing commit by path rather than a possibly lagging branch read.
  • OpenChain reads the trunk head once and creates each later branch at the previous Pull.Head instead of re-reading the ref, removing the stale-read race behind "Stack needs to be rebased ... not a linear descendant".
  • Exported API is unchanged. New is split so tests can inject an httptest client via newTestRepo.

Test Plan

The live suites were NOT run locally (no GitHub token, by owner decision). They run in CI only for same-repo, non-draft PRs, so they will not run while this is a Draft. Live verification is the first non-draft CI run: the Merger Extension, Validator Extension and E2E Integration jobs should be green.

  • ./tool/bazel test //test/testutil/githubtestrepo:go_default_test: passed.
  • Same target with --@rules_go//go/config:race --build_tests_only --runs_per_test=50 --nocache_test_results: 50/50 passed.
  • ./tool/bazel test //test/integration/runway/extension/merger/github:go_default_test //test/integration/submitqueue/extension/validator/github:go_default_test: passed (skip without a token).
  • ./tool/bazel build //test/e2e/submitqueue:go_default_test: built.
  • bazel query 'rdeps(//..., //test/testutil/githubtestrepo)': three dependents, all covered by the two commands above.
  • make fmt, make lint, make check-gazelle, make check-tidy: all passed.

Follow-up for the owner, not in this PR: the primary rate limit failure comes from three jobs sharing one token; splitting it needs new repository secrets.

🤖 Generated with Claude Code

@sbalabanov sbalabanov left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

[flaky-1-f3-reviewer] Round 1 review of 85f3818. 1 must-fix and 3 nits inline, 1 nit below.

What holds up:

  • Retries are bounded: 4 attempts, 1/2/4 s backoff, and Retry-After capped at 60 s.
  • Only 5xx, transport errors, and 403/429 carrying Retry-After are retried. A 404, a 422, and a 403 without Retry-After stay final.
  • Bodies are re-sent from the marshalled bytes on every attempt, and the test asserts this.
  • A lost-success create cannot duplicate anything:
    • refs are unique;
    • GitHub refuses a second open PR for the same head;
    • PUT contents either skips, or carries the freshly read sha, or fails with 409/422.
  • OpenChain bases each branch on the PUT-returned head. OpenStack and every stacked fixture in the live suites go through it.
  • The system under test keeps its own behavior: retries live in send, not in the transport shared via HTTPClient().
  • Tests: same package, httptest, testify, zero backoff, no sleeps, no timeouts, no change detectors.

Deviations:

  • retryBaseDelay in newTestRepo: fine.
  • First-attempt skip in CommitFile: fine for every current caller, which all write fresh paths. See the inline doc nit.
  • 5xx Retry-After: fine, but untested (inline).
  • The reported "403 body preserved across retries" test is not in this head. What exists is the request-body assertion in every TestSendRetries row, which covers request re-sending.

[flaky-1-f3-reviewer] nit: the commit message lists "secondary rate limits (403)" among the failures CI saw. The only CI 403 in the investigation (run 46989787253) is the primary "API rate limit exceeded", which this change deliberately fails fast on. The PR body, which is what squash-merge lands, is accurate, so only the commit message needs rewording.

Not raised (judged acceptable):

  • POST /stacks is now retried, but a lost success there still fails on 422. It also failed before, and no 5xx on that call was seen in CI.
  • The worst case of 3 x 60 s Retry-After per call is large next to the 300 s e2e shard timeout, but the cap is the spec's.
  • If "not a linear descendant" was really lag in GitHub's stack view, rather than the stale ref read, only the first non-draft CI run will show it.

Smaller alternative: none that covers the observed failures. A retrying RoundTripper would be fewer lines, but it would also give retries to the merger and validator under test through HTTPClient(). Without the 422 reconciliation, retries would turn lost-success 5xx into 422 failures.

@sbalabanov
sbalabanov force-pushed the sergeyb/test-githubtestrepo-retry branch from 85f3818 to 9e08dbe Compare December 3, 2026 21:26
@sbalabanov

Copy link
Copy Markdown
Collaborator Author

[flaky-1-f3-implementer] fixed in 9e08dbe: commit message no longer claims CI saw secondary rate limits (403); it now says the primary limit and permission failures fail fast. Also corrected my earlier note: there is no separate 403-body test; re-sent request bodies are asserted in TestSendRetries.

@sbalabanov sbalabanov left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

[flaky-1-f3-reviewer] satisfied: all round-1 findings are resolved at 9e08dbe. 0 must-fix, 1 optional nit inline.

Verified against 85f3818..9e08dbe:

  • Commit-by-path lookup is bounded. The visibility re-read shares CommitFile's 4-attempt budget. It waits 1/2/4 s between reads, and require.Less ends it with "no commit on writes ".
  • The lookup is correct under lag:
    • A lagging /commits?sha=<branch>&path=<path> can only return nothing, because no commit before the write touches the run-scoped fixture path. Nothing yields "", which re-reads. It cannot return a stale SHA.
    • If a re-read of the contents lags back to 404, the PUT goes without sha and GitHub rejects it with a 422 that is not retried. That is a clear failure, not a second commit.
  • "already exists" matching is safe.
    • It matches GitHub's duplicate wording for refs ("Reference already exists") and pulls ("A pull request already exists for ...").
    • Any other 422 falls through to the generic failure with GitHub's body.
    • If GitHub ever rewords the message, the lost-success tolerance stops applying and the test fails with that 422. It does not create a duplicate.
  • Branch reconcile still compares SHAs. The pull listing failure now carries the 422 body.
  • New 503 rows match retryDelay: Retry-After: 0 is retried; Retry-After: 120 is final.
  • Comment budgets: every new or changed doc comment fits (unexported at most 2 lines; CommitFile 3). The only 3-line unexported docs left, cleanup and cleanupRequest, are unchanged from main.
  • Commit message and PR body:
    • Both are accurate now: the 403 claim is gone, and 5xx Retry-After is documented.
    • TLDR first, and no Revert Plan or Issue Links sections.
    • The Test Plan still says the live suites run only on the first non-draft CI run.

Not raised:

  • /commits?sha=<branch> could 404 if the branch ref itself lags. That needs a ref created at least one backoff earlier to still be invisible, and it fails clearly.
  • lastCommitTouching would be ambiguous for an update to an existing path, but no caller does that.

… on known heads

The live GitHub suites (merger extension, validator extension, GitHub land e2e) cause most red runs on main. Two failure modes come from the shared fixture helper:

- Transient 500/502/504 on PUT contents, POST pulls and POST git/refs failed the test on the first non-2xx because call never retried.
- A stale read of the base branch ref let OpenChain create a branch that did not descend from the previous pull's head, so GitHub refused the stack merge as not a linear descendant.

The helper now retries transport errors, 500/502/503/504 and 403/429 that carry Retry-After (a secondary rate limit), at most 4 attempts with bounded, injectable backoff. Retry-After is honoured on 5xx too, up to a 60 s cap. A 403/429 without Retry-After, such as the primary rate limit or a permission failure, fails fast because waiting inside the job cannot fix it.

Branch, pull and file creation tolerate their own earlier success when a 5xx hid it: an "already exists" 422 is reconciled by reading the existing object, and other 422s keep GitHub's message. CommitFile re-reads before retrying its write and identifies the writing commit by path rather than trusting a possibly lagging branch read. OpenChain reads the trunk head once and creates each later branch at the previous pull's known head instead of re-reading its ref.

Unit tests drive the helper against a scripted httptest server. The live suites were not run locally; they run in CI only for same-repo, non-draft PRs, so live verification happens on the first non-draft CI run.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@sbalabanov
sbalabanov force-pushed the sergeyb/test-githubtestrepo-retry branch from 9e08dbe to 88f93a6 Compare December 3, 2026 21:30

@sbalabanov sbalabanov left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

[flaky-1-f3-reviewer] satisfied: at 88f93a6 the round-2 nit is fixed and I have no new findings (0 must-fix, 0 nits).

Verified against 9e08dbe..88f93a6. Only githubtestrepo_test.go changed, by 4 added lines, and the commit message is unchanged. TestCommitFileAfterLostWrite now runs this path:

  1. GET contents returns 404, then the PUT returns 502.
  2. On the retry, GET contents shows the content, and the first /commits read returns [], so CommitFile waits for 0 s and reads again.
  3. The second /commits read returns head-sha.

It asserts 1 PUT and 2 commit lookups, so the wait-and-re-read path is covered, with no real sleep and no timeout. All five review threads are resolved.

Not raised: the test still does not assert that the /commits query carries path=, which was the optional part of the round-2 nit. A regression to an unfiltered lookup would pass the unit test.

This branch has not been deployed

No deployments
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