Skip to content

[Merged by Bors] - feat(cache): put with native Azure and S3 backends - #43378

Closed
marcelolynch wants to merge 50 commits into
leanprover-community:masterfrom
marcelolynch:2026/09/CacheStagedPut
Closed

marcelolynch wants to merge 50 commits into
leanprover-community:masterfrom
marcelolynch:2026/09/CacheStagedPut

Conversation

@marcelolynch

@marcelolynch marcelolynch commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

This PR reworks the upload side of the cache tool. It prepares CI to upload to more than one storage location. The defaults stay the same: uploads continue to go to the Azure account, and the put-staged invocation in CI works unchanged.

Major changes:

Upload commands.:

  • put-staged is moved to run before the expensive hash-memo build.
  • All upload commands share one write path: runPut resolves the destination and dispatches to the selected backend. put-unpacked and the commit commands are removed; nothing in the tool reads a commit file.

Backends:

  • The new --backend option selects the storage backend on every upload command: azure (the default) or s3. Each backend reads only its own credentials and resolves its own destination
  • azure signs with the OIDC bearer token and writes to the chosen --container on the Azure account.
  • s3 signs each request with SigV4: a credential pair, an optional session token, and the region MATHLIB_CACHE_S3_REGION. It writes the same container layout ({base}/{container}/{key}) under the bucket endpoint MATHLIB_CACHE_PUT_BASE_URL, of the form https://endpoint/bucket

Transfer tools:

  • selected by the backend: azure uploads with curl (the built-in tool, as before); s3 uploads with a system rclone when one works on PATH, and with curl otherwise
  • rclone receives the S3 credentials through its environment

Clear upload boundary.:

  • The new Cache/Upload/ modules hold everything that moves staged bytes.
  • Upload/Azure.lean and Upload/S3.lean each implement a complete backend: credential resolution, destination, tool choice, and the transfer entry point.
  • Upload/Curl.lean and Upload/Rclone.lean have the transfer mechanics
  • Upload/Dest.lean the destination contract
  • Upload/Defs.lean the backend selection and the destination arbitration

Documentation. The README and cache --help document the public surface: reads, staging, and the external-cache interface. The upload commands, options, and variables are documented in the new Cache/CI.md.

Behavior changes beyond the new upload path:

  • put-staged without --staging-dir exits with code 1. Before, it printed a message and exited 0, so a misconfigured CI job reported success and uploaded nothing.
  • An upload without --container (and without MATHLIB_CACHE_PUT_URL) errors and names the known containers. Before, it defaulted to the bare mathlib4 container, so a misconfigured job wrote to the lowest-trust namespace.
  • A scope that is not a hex commit SHA causes an error. Before, a path-shaped MATHLIB_CACHE_REPO_SCOPE could reach URL paths and a local temp-file name.
  • MATHLIB_CACHE_SAS is retired: the tool does not read it. CI mints OIDC bearer tokens and the broker mints S3 pairs; nothing sets a SAS token.

One upload command: put (alias put-staged) bulk-uploads a staging
directory to the --container of choice, with the same path contract
get reads; a scope adds the per-commit namespace and its marker. The
pack-and-upload commands (put!, put-unpacked, commit, commit!) retire;
pack, stage, and put compose that flow.

Cache/Upload.lean is the upload boundary: credentials (Azure bearer,
SAS, and the S3 pair signed with SigV4), one destination resolution
for every engine, and three transfer engines — the built-in curl
engine, a system rclone (MATHLIB_CACHE_UPLOADER), and the external
uploader hook (MATHLIB_CACHE_UPLOAD_HOOK). The default engine and the
default destination (the Azure account) are unchanged, so CI keeps
working without a variable change.

cache capabilities answers upload-capability probes on the bare
binary. Scopes validate as hex SHAs before they reach a URL path or a
file name.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01BDiRfq7JW28Gqrs45TRDH4
@github-actions

github-actions Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

PR summary 7313852740

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff (regex)

+ S3Credentials
+ S3UploadTool
+ StagedUploadDest
+ StagedUploadDest.fileURL
+ StagedUploadDest.markerURL
+ UploadBackend
+ all
+ azureAuthFrom
+ azureBearerCurlArgs
+ azurePutStaged
+ azureUploadDestFrom
+ containerUploadDest
+ curlConfigIn
+ fileDirPath
+ getAzureAuth
+ getS3Auth
+ getS3Region
+ isValidScope
+ knownContainersLine
+ markerDirPath
+ name
+ parse?
+ pathSegment
+ putFilesViaCurl
+ putStagedViaCurl
+ putStagedViaRclone
+ rcloneAvailable
+ rcloneCommonFlags
+ rcloneEnv
+ rcloneFilesArgs
+ rcloneMarkerArgs
+ runPut
+ s3AuthFrom
+ s3CurlArgs
+ s3EndpointSplit
+ s3PutStaged
+ s3RegionFrom
+ s3UploadDestFrom
+ s3UploadToolFrom
+ stagedUploadDest
+ stagedUploadDestFrom
+ test_azureAuthFrom
+ test_fileDirPath
+ test_isValidScope
+ test_putStagedViaRclone
+ test_rcloneArgs
+ test_rcloneEnv
+ test_s3AuthFrom
+ test_s3CurlArgs
+ test_s3EndpointSplit
+ test_s3RegionFrom
+ test_s3UploadToolFrom
+ test_stagedUploadDestFrom
+ test_uploadBackendParse
+ uploadMarkerWith
+ uploadPutArgs
+ withSavedScopeOverride
- QueryType
- QueryType.desc
- QueryType.prefix
- UploadAuth
- azureContainerName
- commit
- effectiveUploadURL
- formatError
- getFilesInfo
- getUploadAuth
- isGitStatusClean
- leanTarArgs
- markerURL
- putFiles
- putFilesAbsolute
- uploadMarker

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)

✅ Lean-aware diff — post-build, computed from the Lean environment (commit 7313852).

  • +0 new declarations
  • −0 removed declarations

No declaration differences.


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

Current commit 7313852740
Reference commit c4a007f438

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).

@github-actions github-actions Bot added the CI Modifies the continuous integration setup or other automation label Sep 3, 2026
marcelolynch and others added 25 commits September 3, 2026 09:08
put keeps its pack-and-upload semantics: the hash memo scopes the
upload to the files this build links, straight from the local cache,
with no staging copy. It rides the staged upload's destination and
credential resolution, so there is still one write path. put-staged
stays the CI command and the engine-flexible one. Only put-unpacked
and the commit commands retire; nothing reads a commit file.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01BDiRfq7JW28Gqrs45TRDH4
MATHLIB_CACHE_UPLOAD_HOOK had no consumer: CI is served by the native S3
and rclone engines, and external cache operators are served by the
stage-and-upload recipe with any storage client. It was also the one write
path where the non-overwrite guarantee did not hold. StagedUploadDest keeps
the relative-prefix contract, so a hook can return cheaply if a consumer
appears.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Lrc7gydevEU92rjBmdn3dd
CI mints OIDC bearer tokens and the broker mints S3 pairs; nothing sets
MATHLIB_CACHE_SAS. An environment where it is the only credential errors
with the replacement named. With SAS gone no mechanism signs through the
URL query, so sasQuery retires with it.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Lrc7gydevEU92rjBmdn3dd
The workflows that drive uploads ship with the tool revisions they call,
so no CI negotiation surface is needed; a command whose token list is a
standing contract with the workflows earns its keep only when something
probes it, and nothing does.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Lrc7gydevEU92rjBmdn3dd
StagedUploadDest gains fileURL/markerURL and a display label, so every
engine and test addresses one URL builder and the legacy fallback names
the container it lands in. UploadEngine.rclone carries the S3
credentials it signs with, which removes the untyped engine/credential
match in main. uploadMarkerWith owns the marker mechanics both engines
duplicated (temp file, transfer, warn-only failure). put and put-staged
share putStagedViaCurl. fileDirPath replaces the slash-terminated
filePathPrefix, symmetric with markerDirPath. markerUploadURL was
test-only and is gone; IO.ofExcept replaces the match-and-throw blocks.

Co-Authored-By: Claude Fable 5 <[email protected]>
--uploader=NAME replaces the MATHLIB_CACHE_UPLOADER environment
variable: the engine choice is part of the documented command surface,
and environment variables stay reserved for internal toggles. put
rejects the flag, since it always uploads with the built-in engine.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MyvkiKCDr8TRGaP5HHGeFN
The rclone engine takes the command's file list through a --files-from
list file instead of a directory copy. Only the named files leave the
machine, so put's build-scoped guarantee holds on both engines and
--uploader applies to every upload command.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MyvkiKCDr8TRGaP5HHGeFN
--uploader takes curl or rclone; an engine choice is always explicit.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MyvkiKCDr8TRGaP5HHGeFN
Cache/Upload.lean holds the contract every engine consumes: the
credentials, the destination resolution, and the shared marker upload.
Cache/UploadCurl.lean and Cache/UploadRclone.lean each implement one
transfer engine with the same entry shape (source directory, file
names, overwrite, marker). Cache/Uploader.lean resolves the engine from
--uploader and dispatches; put and put-staged call the one dispatch
entry, so main no longer matches on the engine.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MyvkiKCDr8TRGaP5HHGeFN
Cache/Upload.lean is the entry module: engine selection and dispatch.
The contract moves to Cache/Upload/Defs.lean and the engines to
Cache/Upload/Curl.lean and Cache/Upload/Rclone.lean.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MyvkiKCDr8TRGaP5HHGeFN
The path contract (markerDirPath, markerPath), the read-side URL, and
the write mechanics the engines share (uploadMarkerWith) live together;
only the transfer itself stays with each engine. uploadMarkerWith takes
the marker URL, which it only names in its failure warning.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MyvkiKCDr8TRGaP5HHGeFN
runPut resolves the destination, credentials, engine, and marker from
the command inputs and uploads the files its producer action returns;
main supplies only the parsed options and the file source.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MyvkiKCDr8TRGaP5HHGeFN
…oad/S3.lean

Each backend module owns how the tool talks to its storage: Azure holds
the blob headers and bearer-token curl arguments; S3 holds the credential
set, SigV4 curl arguments, the rclone environment, and the endpoint
split. The engine modules keep only transfer mechanics and dispatch to
the backend for request signing. UploadAuth and UploadEngine carry the
S3 credentials as one S3Credentials value instead of three loose fields.

Co-Authored-By: Claude Fable 5 <[email protected]>
Short sentences in the active voice, one topic per sentence. State what
the code does; do not describe alternatives. Expand contractions and
give each retry and failure comment the correct subject.

Co-Authored-By: Claude Fable 5 <[email protected]>
…ackend

The upload commands take --backend=azure|s3 (azure is the default). Each
backend reads only its own credential variables and picks its transfer
tool: azure uploads with curl; s3 uploads with a system rclone when one
works on PATH, and with curl otherwise. MATHLIB_CACHE_PUT_FORCE_CURL
makes the s3 backend upload with curl; only the s3 tool resolution reads
it. The --uploader option is removed. The transfer machinery is renamed
from engine to tool to match.

Co-Authored-By: Claude Fable 5 <[email protected]>
The azure backend writes to the Azure storage account, with the legacy
fallback and its warning; a set MATHLIB_CACHE_PUT_BASE_URL errors there,
since that variable names the s3 backend's bucket endpoint. The s3
backend requires the bucket endpoint and has no fallback.
MATHLIB_CACHE_PUT_URL stays a flat destination override on both
backends. The destination contract moves to Cache/Upload/Dest.lean so
the backend modules can build on it.

Co-Authored-By: Claude Fable 5 <[email protected]>
marcelolynch and others added 3 commits September 8, 2026 16:25
MATHLIB_CACHE_PUT_BASE_URL rebases the container write on either
backend, as MATHLIB_CACHE_BASE_URL rebases reads. The azure backend
defaults to the Azure storage account when the base is unset; bearer
signing carries no host, so a rebased write works with the same curl
path.

Co-Authored-By: Claude Fable 5 <[email protected]>
Comment thread Cache/Upload/Curl.lean Resolved
Comment thread Cache/Upload/S3.lean Resolved
Comment thread Cache/SECURITY.md Resolved
Comment thread Cache/Upload/Curl.lean Resolved
Comment thread Cache/Upload/S3.lean Resolved
Comment thread Cache/CI.md Resolved
Comment thread Cache/README.md Resolved
Comment thread Cache/CI.md Resolved
Comment thread Cache/Test.lean Resolved
Comment thread Cache/Upload.lean Resolved
@joneugster joneugster added the LLM-generated PRs with substantial input from LLMs - review accordingly label Sep 11, 2026

@bryangingechen bryangingechen left a comment

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.

Two minor things. Let's get this merged!

Comment thread Cache/CI.md Resolved
Comment thread Cache/Test.lean Resolved
The marker no longer depends on the --container flag: every destination
has a marker URL, so a flat MATHLIB_CACHE_PUT_URL upload with a scope
writes one too. CI is unaffected: its only upload passes --container.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@bryangingechen

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 14, 2026
mathlib-bors Bot pushed a commit that referenced this pull request Sep 14, 2026
This PR reworks the upload side of the cache tool. It prepares CI to upload to more than one storage location. The defaults stay the same: uploads continue to go to the Azure account, and the `put-staged` invocation in CI works unchanged.


Major changes:

**Upload commands.**: 
- `put-staged` is moved to run before the expensive hash-memo build. 
- All upload commands share one write path: `runPut` resolves the destination and dispatches to the selected backend. `put-unpacked` and the `commit` commands are removed; nothing in the tool reads a commit file.

**Backends**:
- The new `--backend` option selects the storage backend on every upload command: `azure` (the default) or `s3`. Each backend reads only its own credentials and resolves its own destination
- `azure` signs with the OIDC bearer token and writes to the chosen `--container` on the Azure account.
- `s3` signs each request with SigV4: a credential pair, an optional session token, and the region `MATHLIB_CACHE_S3_REGION`. It writes the same container layout (`{base}/{container}/{key}`) under the bucket endpoint `MATHLIB_CACHE_PUT_BASE_URL`, of the form `https://endpoint/bucket`

**Transfer tools**:
- selected by the backend: `azure` uploads with curl (the built-in tool, as before); `s3` uploads with a system rclone when one works on PATH, and with curl otherwise
- rclone receives the S3 credentials through its environment

**Clear upload boundary.**:
- The new `Cache/Upload/` modules hold everything that moves staged bytes. 
- `Upload/Azure.lean` and `Upload/S3.lean` each implement a complete backend: credential resolution, destination, tool choice, and the transfer entry point. 
- `Upload/Curl.lean` and `Upload/Rclone.lean` have the transfer mechanics
- `Upload/Dest.lean` the destination contract
- `Upload/Defs.lean` the backend selection and the destination arbitration

**Documentation.** The README and `cache --help` document the public surface: reads, staging, and the external-cache interface. The upload commands, options, and variables are documented in the new `Cache/CI.md`.

**Behavior changes beyond the new upload path**:
- `put-staged` without `--staging-dir` exits with code 1. Before, it printed a message and exited 0, so a misconfigured CI job reported success and uploaded nothing.
- An upload without `--container` (and without `MATHLIB_CACHE_PUT_URL`) errors and names the known containers. Before, it defaulted to the bare `mathlib4` container, so a misconfigured job wrote to the lowest-trust namespace.
- A scope that is not a hex commit SHA causes an error. Before, a path-shaped `MATHLIB_CACHE_REPO_SCOPE` could reach URL paths and a local temp-file name.
- `MATHLIB_CACHE_SAS` is retired: the tool does not read it. CI mints OIDC bearer tokens and the broker mints S3 pairs; nothing sets a SAS token.
@mathlib-bors mathlib-bors Bot added the bors-staging This PR is currently being built by bors on the staging branch. label Sep 14, 2026
@mathlib-bors

mathlib-bors Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Build failed (retrying...):

@mathlib-bors mathlib-bors Bot removed the bors-staging This PR is currently being built by bors on the staging branch. label Sep 14, 2026
mathlib-bors Bot pushed a commit that referenced this pull request Sep 15, 2026
This PR reworks the upload side of the cache tool. It prepares CI to upload to more than one storage location. The defaults stay the same: uploads continue to go to the Azure account, and the `put-staged` invocation in CI works unchanged.


Major changes:

**Upload commands.**: 
- `put-staged` is moved to run before the expensive hash-memo build. 
- All upload commands share one write path: `runPut` resolves the destination and dispatches to the selected backend. `put-unpacked` and the `commit` commands are removed; nothing in the tool reads a commit file.

**Backends**:
- The new `--backend` option selects the storage backend on every upload command: `azure` (the default) or `s3`. Each backend reads only its own credentials and resolves its own destination
- `azure` signs with the OIDC bearer token and writes to the chosen `--container` on the Azure account.
- `s3` signs each request with SigV4: a credential pair, an optional session token, and the region `MATHLIB_CACHE_S3_REGION`. It writes the same container layout (`{base}/{container}/{key}`) under the bucket endpoint `MATHLIB_CACHE_PUT_BASE_URL`, of the form `https://endpoint/bucket`

**Transfer tools**:
- selected by the backend: `azure` uploads with curl (the built-in tool, as before); `s3` uploads with a system rclone when one works on PATH, and with curl otherwise
- rclone receives the S3 credentials through its environment

**Clear upload boundary.**:
- The new `Cache/Upload/` modules hold everything that moves staged bytes. 
- `Upload/Azure.lean` and `Upload/S3.lean` each implement a complete backend: credential resolution, destination, tool choice, and the transfer entry point. 
- `Upload/Curl.lean` and `Upload/Rclone.lean` have the transfer mechanics
- `Upload/Dest.lean` the destination contract
- `Upload/Defs.lean` the backend selection and the destination arbitration

**Documentation.** The README and `cache --help` document the public surface: reads, staging, and the external-cache interface. The upload commands, options, and variables are documented in the new `Cache/CI.md`.

**Behavior changes beyond the new upload path**:
- `put-staged` without `--staging-dir` exits with code 1. Before, it printed a message and exited 0, so a misconfigured CI job reported success and uploaded nothing.
- An upload without `--container` (and without `MATHLIB_CACHE_PUT_URL`) errors and names the known containers. Before, it defaulted to the bare `mathlib4` container, so a misconfigured job wrote to the lowest-trust namespace.
- A scope that is not a hex commit SHA causes an error. Before, a path-shaped `MATHLIB_CACHE_REPO_SCOPE` could reach URL paths and a local temp-file name.
- `MATHLIB_CACHE_SAS` is retired: the tool does not read it. CI mints OIDC bearer tokens and the broker mints S3 pairs; nothing sets a SAS token.
@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 feat(cache): put with native Azure and S3 backends [Merged by Bors] - feat(cache): put with native Azure and S3 backends Sep 15, 2026
@mathlib-bors mathlib-bors Bot closed this Sep 15, 2026
rosborn added a commit to rosborn/mathlib4 that referenced this pull request Sep 15, 2026
* origin/master: (958 commits)
  chore(Combinatorics/SimpleGraph/Trails): golf and cleanup (leanprover-community#41447)
  refactor(Probability/Kernel): remove redundant case split in Invariant.comp (leanprover-community#43805)
  chore: bump toolchain to v4.34.0 (leanprover-community#43798)
  feat(Data/List/SignVariations): add List.signVariations (leanprover-community#43783)
  feat(LinearAlgebra/Span/Basic): add Submodule.prodEquiv (leanprover-community#43664)
  feat(cache): put with native Azure and S3 backends (leanprover-community#43378)
  feat(Combinatorics/SimpleGraph/Walk): more `transfer` API (leanprover-community#41717)
  feat(SimpleGraph): girth-diameter inequality (leanprover-community#25834)
  feat: make `simps?` and `to_dual?`/`to_additive?` more concise (leanprover-community#43775)
  feat(Basic/IsEmpty/Defs): add Fin.isEmpty_iff (leanprover-community#43763)
  feat(Data/ENNReal/Inv): add ENNReal.div_mul_div_cancel (leanprover-community#37954)
  chore(Tactic/Simproc/ExistsAndEq): fix two typos (leanprover-community#43797)
  feat(LinearAlgebra/Matrix/GeneralLinearGroup/Defs): add the proof of the range of toGL to be the ker of the determinant and the induced equivalence (leanprover-community#41786)
  chore(Data/Num/Lemmas): golf `transfer` tactic (leanprover-community#41167)
  refactor(Data/Nat/Choose/Central): move and rename `four_pow_le_two_mul_add_one_mul_central_binom` (leanprover-community#42606)
  feat(Combinatorics/Graph): edge cut of `Graph` (leanprover-community#37865)
  feat(Algebra/QuadraticAlgebra): classify quadratic algebras by their discriminant (leanprover-community#42708)
  fix: use the PR number in the deprecation reminder message (leanprover-community#43786)
  feat(Data/Fintype/Defs): add DecidableLE (∀ a, β a) (leanprover-community#43425)
  chore: redefine `Finsupp.indicator` using `Finsupp.onFinset` (leanprover-community#33434)
  ...

# Conflicts:
#	Mathlib/Tactic/Linter/DirectoryDependency.lean
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)
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 LLM-generated PRs with substantial input from LLMs - review accordingly ready-to-merge This PR has been sent to bors.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants