Repository navigation
[Merged by Bors] - feat(cache): put with native Azure and S3 backends - #43378
marcelolynch wants to merge 50 commits into
Conversation
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
PR summary 7313852740Import changes for modified filesNo significant changes to the import graph Import changes for all files
|
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
Co-Authored-By: Claude Fable 5 <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
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
Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MyvkiKCDr8TRGaP5HHGeFN
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
Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MyvkiKCDr8TRGaP5HHGeFN
Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MyvkiKCDr8TRGaP5HHGeFN
Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MyvkiKCDr8TRGaP5HHGeFN
Names the tool no longer has take the unknown-command path. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MyvkiKCDr8TRGaP5HHGeFN
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]>
Co-Authored-By: Claude Fable 5 <[email protected]>
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]>
bryangingechen
left a comment
There was a problem hiding this comment.
Two minor things. Let's get this merged!
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]>
|
Thanks! |
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.
|
Build failed (retrying...): |
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.
|
Pull request successfully merged into master. Build succeeded: |
* 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
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)
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-stagedinvocation in CI works unchanged.Major changes:
Upload commands.:
put-stagedis moved to run before the expensive hash-memo build.runPutresolves the destination and dispatches to the selected backend.put-unpackedand thecommitcommands are removed; nothing in the tool reads a commit file.Backends:
--backendoption selects the storage backend on every upload command:azure(the default) ors3. Each backend reads only its own credentials and resolves its own destinationazuresigns with the OIDC bearer token and writes to the chosen--containeron the Azure account.s3signs each request with SigV4: a credential pair, an optional session token, and the regionMATHLIB_CACHE_S3_REGION. It writes the same container layout ({base}/{container}/{key}) under the bucket endpointMATHLIB_CACHE_PUT_BASE_URL, of the formhttps://endpoint/bucketTransfer tools:
azureuploads with curl (the built-in tool, as before);s3uploads with a system rclone when one works on PATH, and with curl otherwiseClear upload boundary.:
Cache/Upload/modules hold everything that moves staged bytes.Upload/Azure.leanandUpload/S3.leaneach implement a complete backend: credential resolution, destination, tool choice, and the transfer entry point.Upload/Curl.leanandUpload/Rclone.leanhave the transfer mechanicsUpload/Dest.leanthe destination contractUpload/Defs.leanthe backend selection and the destination arbitrationDocumentation. The README and
cache --helpdocument the public surface: reads, staging, and the external-cache interface. The upload commands, options, and variables are documented in the newCache/CI.md.Behavior changes beyond the new upload path:
put-stagedwithout--staging-direxits with code 1. Before, it printed a message and exited 0, so a misconfigured CI job reported success and uploaded nothing.--container(and withoutMATHLIB_CACHE_PUT_URL) errors and names the known containers. Before, it defaulted to the baremathlib4container, so a misconfigured job wrote to the lowest-trust namespace.MATHLIB_CACHE_REPO_SCOPEcould reach URL paths and a local temp-file name.MATHLIB_CACHE_SASis retired: the tool does not read it. CI mints OIDC bearer tokens and the broker mints S3 pairs; nothing sets a SAS token.