Skip to content

ci: persist Bazel's repository cache across runs and retry the first fetch, so proxy.golang.org flakes stop failing jobs (#1001) - #1016

Merged
bpalermo merged 4 commits into
mainfrom
ci/1001-repository-cache
Sep 27, 2026
Merged

bpalermo merged 4 commits into
mainfrom
ci/1001-repository-cache

Conversation

@bpalermo

@bpalermo bpalermo commented Sep 27, 2026 •

Copy link
Copy Markdown
Owner

The two flakes

On 2026-09-27 two unrelated PRs went red the same way and passed on a plain re-run:

The #995 log is the useful one. The repository cache was already restored, as an exact hit, 1.9 GB:

Cache hit for: setup-bazel-1-linux-x64-repository-ab8c1ebefd842d140dc813e94c19b7e037d67c39ffd7ea463f6c416c79ed1803
Successfully restored cache from setup-bazel-1-linux-x64-repository-ab8c1ebefd842d140dc813e94c19b7e037d67c39ffd7ea463f6c416c79ed1803
…
Error in fail: gazelle++go_deps+org_golang_google_genproto_googleapis_api: fetch_repo: google.golang.org/genproto/googleapis/[email protected]: Get "https://proxy.golang.org/…": net/http: TLS handshake timeout

and that module has been in go.mod since #749 (2026-09-12). So "persist the repository cache" was half-done; what was wrong is what got persisted:

  1. Key. setup-bazel's repository-cache: true hashes MODULE.bazel only. A go.sum bump keeps the key, so the entry is an exact hit and is never re-saved with the new modules.
  2. Who saves. setup-bazel saves in its post step, only when the restore was not an exact hit, so the first job to finish writes the entry. deps-audit/format/shell (a handful of repositories each) finish before test, and every later job then restores their entry as an exact hit and never re-saves.
  3. Namespace. proxy.yml/proxy-release.yml run setup-bazel from the repo root, so they hashed the root MODULE.bazel and wrote Envoy's repositories under the root key (the 1.4 GB linux-arm64 entry is theirs).

Go modules are cacheable this way: go_repository in module mode is reproducible = True, so Bazel 9's repo contents cache (<repository_cache>/contents) holds the fetched repo. Measured locally: a cold bazel build --nobuild //... into an empty --repository_cache, then clean --expunge, then the same with --repo_env=GOPROXY=https://127.0.0.1:9 → Build completed successfully, zero fetch_repo lines. A warm cache needs no network for a known module. (This is the issue's "GOPROXY=off after the cache is warm" gate.)

The fix

(1) The cache (still bazel-contrib/[email protected]; I read its config.js/index.js/post.js at the tag: it restores key then falls back to the setup-bazel-<cache-version>-<os>-<arch>-repository- prefix, which is the restore-keys behaviour we want, and its repository-cache input takes a file list and cache-version namespaces the key):

  • Root jobs: cache-version: root-1, repository-cache: '["MODULE.bazel", "MODULE.bazel.lock", "go.mod", "go.sum"]'.
  • Proxy jobs: cache-version: proxy-1, repository-cache: '["proxy/MODULE.bazel", "proxy/MODULE.bazel.lock"]'. (proxy.yml's shell job runs in the root workspace, so it is a root job.)
  • One saver per workflow: diff in ci.yaml and main.yaml (main.yaml's writes the main entry every PR falls back to), and the per-arch build matrix in proxy.yml/proxy-release.yml. Each saver warms all of //..., so what it saves covers every other job's fetches. Every other job has cache-save: false. Knock-on: fewer ~2 GB entries against the 10 GB repo budget (it was at 9.87 GB when I looked).

(2) The retry. scripts/ci-bazel-warmup.sh <flags> <targets> is each Bazel job's first Bazel step: bazel build --nobuild (loading + analysis, which is where fetches happen), 3 attempts, 20 s / 40 s backoff, retried only when the output shows a repository-fetch error (An error occurred during the fetch of repository, fetch_repo: , Error downloading, …). A broken BUILD file fails on attempt 1 and does not sit through the backoff. The warm-up clears --remote_executor= --remote_cache= --bes_backend= after the caller's flags, so it can take --config=ci as-is (its platforms/toolchains decide which repos get fetched) without a BuildBuddy key and without creating a BuildBuddy invocation. .bazelrc is untouched: no remote setting changed, RBE/test-local/DownloadBlob rules as before. No --experimental_remote_downloader (I did not verify BuildBuddy's remote asset API for this org, so it stays out).

scripts/check-ci-bazel-warmup.sh (new step in ci.yaml's shell job) runs the script against a stub bazel and checks that a fetch blip recovers on attempt 2, a fetch outage stops at exactly 3, a non-fetch failure stops at 1, and the remote endpoints are cleared after the caller's flags. It does catch regressions: with WARMUP_ATTEMPTS=1 two of its cases fail.

Evidence

Retry seen red (a real Bazel run, not the stub)

Cold, empty --repository_cache, fresh output base, --repo_env=GOPROXY=https://127.0.0.1:9, WARMUP_BACKOFF_SECONDS=5, target //cni/internal/plugin:capture_netns_test (the #995 target). Exit 1:

>> bazel warm-up attempt 1/3: build --nobuild (fetch + analysis only)
Error in fail: gazelle++go_deps+io_opentelemetry_go_otel_exporters_otlp_otlptrace_otlptracegrpc: fetch_repo: go.opentelemetry.io/otel/exporters/otlp/otlptrace/[email protected]: Get "https://127.0.0.1:9/…": …
ERROR: Build did NOT complete successfully
::warning::bazel warm-up attempt 1/3 hit a repository-fetch error (exit 1); retrying in 5s
>> bazel warm-up attempt 2/3: build --nobuild (fetch + analysis only)
Error in fail: gazelle++go_deps+org_uber_go_zap: fetch_repo: go.uber.org/[email protected]: Get "https://127.0.0.1:9/go.uber.org/zap/@v/v1.28.0.info": dial tcp 127.0.0.1:9: connect: connection refused
ERROR: Build did NOT complete successfully
::warning::bazel warm-up attempt 2/3 hit a repository-fetch error (exit 1); retrying in 10s
>> bazel warm-up attempt 3/3: build --nobuild (fetch + analysis only)
Error in fail: gazelle++go_deps+org_uber_go_zap: fetch_repo: go.uber.org/[email protected]: Get "https://127.0.0.1:9/go.uber.org/zap/@v/v1.28.0.info": dial tcp 127.0.0.1:9: connect: connection refused
ERROR: Build did NOT complete successfully
::error::bazel warm-up: repository fetch failed on all 3 attempts (last exit 1). If the log names proxy.golang.org or github.com, the upstream is down for longer than the backoff: re-run the job later (docs/runbook.md, 'CI: external repository fetches').

Cache restored on the second run

Run 1 (cbd96d4, run 36349170687). root-1 is a new namespace, so diff starts cold, fetches everything with the retrying warm-up, and saves:

diff (108704346741)
  Restore cache for repository
  Failed to restore repository cache
  >> bazel warm-up attempt 1/3: build --nobuild (fetch + analysis only)
  INFO: Elapsed time: 74.869s
  >> bazel warm-up succeeded on attempt 1/3
  Save cache for repository
  Successfully saved cache

In the same run, test/netns/race/integration/e2e start after diff, so they already restore its entry as an exact hit and do not save:

test (108704732286)
  Cache hit for: setup-bazel-root-1-linux-x64-repository-71477991caa60b6cc660c3ed2ad761d812e482c4c1f658ff1cd06ccaf83f52a5
  Successfully restored cache from setup-bazel-root-1-linux-x64-repository-71477991caa60b6cc660c3ed2ad761d812e482c4c1f658ff1cd06ccaf83f52a5
  Cache saving is disabled (cache-save: false)

Run 2 (empty commit c2a5863, run 36349842108 + proxy run 36349842212). Every job restores as an exact hit, including the jobs that were cold in run 1 because they run in parallel with diff:

diff (108706274496)
  Cache hit for: setup-bazel-root-1-linux-x64-repository-71477991caa60b6cc660c3ed2ad761d812e482c4c1f658ff1cd06ccaf83f52a5
  Cache Size: ~1007 MB (1055648415 B)
  Successfully restored cache from setup-bazel-root-1-linux-x64-repository-71477991caa60b6cc660c3ed2ad761d812e482c4c1f658ff1cd06ccaf83f52a5
  >> bazel warm-up succeeded on attempt 1/3        (48.3s; 74.9s cold in run 1)
deps-audit (108706274444)   [cold in run 1: "Failed to restore repository cache"]
  Cache hit for: setup-bazel-root-1-linux-x64-repository-71477991caa60b6cc660c3ed2ad761d812e482c4c1f658ff1cd06ccaf83f52a5
  Successfully restored cache from setup-bazel-root-1-linux-x64-repository-71477991caa60b6cc660c3ed2ad761d812e482c4c1f658ff1cd06ccaf83f52a5
  Cache saving is disabled (cache-save: false)
netns (108706647688)        [the #995 job]
  Cache hit for: setup-bazel-root-1-linux-x64-repository-71477991caa60b6cc660c3ed2ad761d812e482c4c1f658ff1cd06ccaf83f52a5
  Successfully restored cache from setup-bazel-root-1-linux-x64-repository-71477991caa60b6cc660c3ed2ad761d812e482c4c1f658ff1cd06ccaf83f52a5
proxy test amd64 (108706268100)   [own namespace, saved by its run-1 twin]
  Cache hit for: setup-bazel-proxy-1-linux-x64-repository-46958ee0fa080bc5b79f1dfb4a3dcd90e8aeb7f752b9c6845924c58dfbff1aff
  Cache Size: ~1412 MB (1480283458 B)
  Successfully restored cache from setup-bazel-proxy-1-linux-x64-repository-46958ee0fa080bc5b79f1dfb4a3dcd90e8aeb7f752b9c6845924c58dfbff1aff

No fetch_repo line appears in any of those run-2 job logs. The root entry is ~1.0 GB, against the ~1.9 GB of the old shared, never-pruned one.

Cost: warm-ups on a warm cache took 30-61s. Where the next step keeps the analysis (netns: 3.9s build after warm-up), the real step gets most of that back.

Run 2's race went red once on //agent/internal/spire:spire_test, which this PR does not touch: TestNodeSVIDRedeliveryCountsUnchanged failed in run 3 of 3 (an unchanged node SVID must not push, 2 pushes instead of 1). That is a flaky test. Nothing was fetched, and the warm-up succeeded on attempt 1. I re-ran the failed job.

Docs

docs/runbook.md §3, new "CI: external repository fetches (#1001)": both mechanisms, a table for reading a red job (retry absorbed / all 3 attempts failed → re-run / a fetch in a later step → re-run and extend that warm-up / a non-fetch failure → fix it), and where a plain re-run is still the answer. That covers deps-audit's go list -m all, which reaches proxy.golang.org through the Go tool outside Bazel, image pulls, and a cold namespace after a cache-version bump or an eviction.

Checks

  • actionlint: nothing new. Its only findings are the existing github.head_ref-in-inline-script warnings.
  • Locally: //:format.check ran all 4 languages clean, //website:site_test passed (the runbook feeds it), and the --config=lint shellcheck of //scripts:all passed (the new scripts are in its glob).
  • charts/ untouched.

Closes #1001

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

bpalermo and others added 2 commits September 27, 2026 17:44
…fetch, so proxy.golang.org flakes stop failing jobs (#1001)

The repository cache was already restored (setup-bazel repository-cache:
true) but keyed on the root MODULE.bazel alone, shared with the proxy
workspace's jobs, and saved by whichever job finished first. A job that
fetched little -- or a proxy job -- could write the entry every later job
restored as an exact hit and never re-saved, which is how #995's netns job
fetched googleapis/api from proxy.golang.org with a 1.9 GB cache freshly
restored.

- Key on MODULE.bazel + MODULE.bazel.lock + go.mod + go.sum (root) and
  proxy/MODULE.bazel + proxy/MODULE.bazel.lock (proxy), in separate
  cache-version namespaces (root-1 / proxy-1).
- One saver per workflow (ci/main `diff`, the proxy build matrix per arch),
  whose warm-up fetches for all of //...; every other job cache-save: false.
- scripts/ci-bazel-warmup.sh: `bazel build --nobuild` as each job's first
  Bazel step, retried 3x with 20s/40s backoff only on a repository-fetch
  error, never talking to BuildBuddy. scripts/check-ci-bazel-warmup.sh
  pins the contract with a stub bazel in the `shell` job.
- docs/runbook.md: "CI: external repository fetches".

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo merged commit a43a20b into main Sep 27, 2026
25 checks passed
@bpalermo
bpalermo deleted the ci/1001-repository-cache branch September 27, 2026 21:29
bpalermo added a commit that referenced this pull request Sep 27, 2026
Brings in #1016 (repository-cache keys, cache-save: false, ci-bazel-warmup
first steps), #1019 and #1012. publish.yaml keeps both sides: the #1016
setup-bazel cache settings and warm-up step, then the release-environment
Quay robot login.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
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.

ci: Go module fetches from proxy.golang.org fail intermittently in CI (TLS handshake timeout / fetch_repo) — two PR runs red today for nothing

1 participant