Skip to content

[Merged by Bors] - ci: upload the master cache to R2 from the upload_cache job - #43648

Closed
marcelolynch wants to merge 3 commits into
leanprover-community:masterfrom
marcelolynch:2026/09/CacheUploadR2Leg
Closed

marcelolynch wants to merge 3 commits into
leanprover-community:masterfrom
marcelolynch:2026/09/CacheUploadR2Leg

Conversation

@marcelolynch

@marcelolynch marcelolynch commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

This PR adds a second upload to the upload_cache job. After the Azure upload, the job uploads the same staged .ltar set to the R2 bucket behind the public cache service. The Azure upload is unchanged.

The R2 upload runs only for the master container: master pushes, bors staging builds, and v4.* release tags. Fork builds, dev-branch builds, and nightly-repository builds write other containers, so they skip it.

How the upload works:

  1. A mint step runs the mathlib-ci action mint-s3-credentials. The action returns short-lived S3 credentials as masked step outputs.
  2. An upload step runs put-staged --backend=s3 on the same staging directory. The step maps the credentials into the cache tool's variables, so only that step holds them. It signs in the region auto, which R2 expects. It sets MATHLIB_CACHE_PUT_URL from the secret MATHLIB_CACHE_R2_PUT_URL, and the tool writes {url}/f/{hash}.ltar. With the secret set to https://<account endpoint>/mathlib4-cache/mathlib4, the files land under the bucket prefix mathlib4/, which the cache resolver serves for the mathlib4 and mathlib4-master URL segments.

The job already declares the cache-upload-master environment for the Azure upload. The environment fixes the OIDC sub claim, and its branch policy admits only master, staging, and the v4.* tags. The mint step sends the same token, so the same policy gates it.

The Azure upload is the upload of record. When the mint fails, only the mint step fails (continue-on-error), and the upload step is skipped because the action's success output is unset. When the R2 upload fails, the step warns and the job succeeds (continue-on-error). A skipped or failed R2 upload leaves this run's files out of the bucket until a backfill adds them.

The repository variable MATHLIB_CACHE_BROKER_URL is the switch. It holds the credential endpoint that the action calls. When it is empty, the job runs the Azure upload only. The secret MATHLIB_CACHE_R2_PUT_URL names the destination. When it is unset, the upload step warns and exits without an upload.

Out of scope: a backfill of the files the bucket lacks, a verification of bucket reads, and a completeness marker. Uploads to master carry no scope, so the tool writes no marker.

Fork PRs run master's build_template.yml, so the CI of this PR does not exercise the change. actionlint reports one pre-existing item on the file, the deployment: false key, which master also has. #43378 validated the tool's S3 path, with the flat MATHLIB_CACHE_PUT_URL write, live against R2.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

PR summary 3d053b34e1

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff (regex)

No declarations were harmed in the making of this PR! 🐙

You can run this locally as follows
## from your `mathlib4` directory:
git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci

## summary with just the declaration names:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh <optional_commit>

## more verbose report:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh long <optional_commit>

The doc-module for scripts/pr_summary/declarations_diff.sh in the mathlib-ci repository contains some details about this script.

Declarations diff (Lean -- pending)

Computed after the build finishes.


No changes to strong technical debt.
No changes to weak technical debt.

Current commit 3d053b34e1
Reference commit 1cf325a0cf

This script lives in the mathlib-ci repository. To run it locally, from your mathlib4 directory:

git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci
../mathlib-ci/scripts/reporting/technical-debt-metrics.py pr_summary
  • The relative value is the weighted sum of the differences with weight given by the inverse of the current value of the statistic.
  • The absolute value is the relative value divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).

⚠️ Workflow documentation reminder

This PR modifies files under .github/workflows/.
Please update docs/workflows.md if the workflow inventory, triggers, or behavior changed.

Modified workflow files:

  • .github/workflows/build_template.yml

@github-actions github-actions Bot added the CI Modifies the continuous integration setup or other automation label Sep 10, 2026
@marcelolynch
marcelolynch force-pushed the 2026/09/CacheUploadR2Leg branch 2 times, most recently from 163ac34 to c67067b Compare September 10, 2026 02:06
@mathlib-dependent-issues mathlib-dependent-issues Bot added the blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) label Sep 10, 2026
@marcelolynch
marcelolynch force-pushed the 2026/09/CacheUploadR2Leg branch 2 times, most recently from d2c46a9 to 739eced Compare September 10, 2026 17:24
@mathlib-dependent-issues mathlib-dependent-issues Bot removed the blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) label Sep 15, 2026
@marcelolynch
marcelolynch force-pushed the 2026/09/CacheUploadR2Leg branch 2 times, most recently from 5344d75 to f2b1cb0 Compare September 15, 2026 02:16
@marcelolynch
marcelolynch marked this pull request as ready for review September 15, 2026 02:17
The upload_cache job uploads the staged set a second time, to the R2
bucket, with credentials the cache broker mints. Only the master
container takes this path. The Azure upload runs first and is unchanged.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@marcelolynch
marcelolynch force-pushed the 2026/09/CacheUploadR2Leg branch from f2b1cb0 to f96f1f9 Compare September 15, 2026 02:25
Comment thread .github/workflows/build_template.yml Resolved
MATHLIB_CACHE_S3_REGION: auto
# The flat write puts `{url}/f/{hash}.ltar` under the bucket's `mathlib4/`
# prefix, which the cache resolver serves.
MATHLIB_CACHE_PUT_URL: ${{ secrets.MATHLIB_CACHE_R2_PUT_URL }}

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.

Claude points out that a trailing slash here in the secret will cause a failure in s3EndpointSplit since it rejects empty path segments. Possibly worth a comment and hardening later on.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah I'm aware of this, will fix as a follow up

exit 1
fi
echo "Uploading cache to R2 (the bucket's master prefix)..."
if ! lake env "$CACHE_BIN" put-staged --backend=s3 --staging-dir="cache-staging" --repo="$REPO"; then

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.

A warning from Claude:

--repo="$REPO" is load-bearing here in a way it isn't on the Azure leg. With MATHLIB_CACHE_PUT_URL set there's no container, so fileDirPath keys the layout on the repo (flat = repo == MATHLIBREPO) instead of on flatPath .master, which is repo-independent. Correct today, since MATHLIB_CACHE_PRIMARY == 'master' implies REPO == leanprover-community/mathlib4 — but any other repo would write f/{repo}/.ltar, which nothing reads, and the upload would still exit 0. That's a silent success rather than the tolerated warning this step knows how to emit.

runPut already defaults it (repo?.getD MATHLIBREPO), so dropping --repo pins the flat layout unconditionally and lets REPO come out of the step's env: too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yep, this is a bit awkward but my next step here is to completely separate "developer cache" from "master cache" and then this will become cleaner

@bryangingechen

bryangingechen commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Thanks!
bors r+

@mathlib-bors mathlib-bors Bot added the ready-to-merge This PR has been sent to bors. label Sep 15, 2026
mathlib-bors Bot pushed a commit that referenced this pull request Sep 15, 2026
This PR adds a second upload to the `upload_cache` job. After the Azure upload, the job uploads the same staged `.ltar` set to the R2 bucket behind the public cache service. The Azure upload is unchanged.

The R2 upload runs only for the `master` container: master pushes, bors `staging` builds, and `v4.*` release tags. Fork builds, dev-branch builds, and nightly-repository builds write other containers, so they skip it.

How the upload works:

1. A mint step runs the mathlib-ci action `mint-s3-credentials`. The action returns short-lived S3 credentials as masked step outputs.
2. An upload step runs `put-staged --backend=s3` on the same staging directory. The step maps the credentials into the cache tool's variables, so only that step holds them. It signs in the region `auto`, which R2 expects. It sets `MATHLIB_CACHE_PUT_URL` from the secret `MATHLIB_CACHE_R2_PUT_URL`, and the tool writes `{url}/f/{hash}.ltar`. With the secret set to `https://<account endpoint>/mathlib4-cache/mathlib4`, the files land under the bucket prefix `mathlib4/`, which the cache resolver serves for the `mathlib4` and `mathlib4-master` URL segments.

The job already declares the `cache-upload-master` environment for the Azure upload. The environment fixes the OIDC `sub` claim, and its branch policy admits only `master`, `staging`, and the `v4.*` tags. The mint step sends the same token, so the same policy gates it.

The Azure upload is the upload of record. When the mint fails, only the mint step fails (`continue-on-error`), and the upload step is skipped because the action's `success` output is unset. When the R2 upload fails, the step warns and the job succeeds (`continue-on-error`). A skipped or failed R2 upload leaves this run's files out of the bucket until a backfill adds them.

The repository variable `MATHLIB_CACHE_BROKER_URL` is the switch. It holds the credential endpoint that the action calls. When it is empty, the job runs the Azure upload only. The secret `MATHLIB_CACHE_R2_PUT_URL` names the destination. When it is unset, the upload step warns and exits without an upload.

Out of scope: a backfill of the files the bucket lacks, a verification of bucket reads, and a completeness marker. Uploads to `master` carry no scope, so the tool writes no marker.

Fork PRs run master's `build_template.yml`, so the CI of this PR does not exercise the change. `actionlint` reports one pre-existing item on the file, the `deployment: false` key, which master also has. #43378 validated the tool's S3 path, with the flat `MATHLIB_CACHE_PUT_URL` write, live against R2.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@mathlib-bors mathlib-bors Bot added the bors-staging This PR is currently being built by bors on the staging branch. label Sep 15, 2026
@mathlib-bors

mathlib-bors Bot commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

@mathlib-bors mathlib-bors Bot changed the title ci: upload the master cache to R2 from the upload_cache job [Merged by Bors] - ci: upload the master cache to R2 from the upload_cache job Sep 15, 2026
@mathlib-bors mathlib-bors Bot closed this Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bors-staging This PR is currently being built by bors on the staging branch. CI Modifies the continuous integration setup or other automation ready-to-merge This PR has been sent to bors.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants