Skip to content

fix: pin LEAN_GITHASH for core Lake builds - #14486

Merged
tydeu merged 4 commits into
masterfrom
tydeu/ci-lake-lean-githash
Jul 24, 2026
Merged

tydeu merged 4 commits into
masterfrom
tydeu/ci-lake-lean-githash

Conversation

@tydeu

@tydeu tydeu commented Jul 22, 2026 •

Copy link
Copy Markdown
Member

This PR restores reuse of the Lake artifact cache across core CI builds.

Since #13759, the Linux Lake (Cached) job downloaded the cache but still rebuilt everything, because the cache trace is keyed on Lean.githash, which is the commit hash on the release job that produces the cache, but the stage0 tree hash on the non-release job that consumes it. To fix this, the Lean trace Lake uses is overriden via LEAN_GITHASH to be the stage0 tree hash (rather than whatever Lean.githash may be). This ensures so stage1 .oleans are reusable across commits that do not touch stage0. The override affects only the cache trace, not the compiled .oleans, which still embed the same Lean.githash.

Release builds cannot reuse .oleans embedded with a different Lean.githash. Nonetheless, this change would allow Lake to reuse them if they have the same stage0. To avoid this, restoring .oleans from the cache is now completely disabled for release builds. In practice, this is pure savings, as the .oleans restored from the cache during release builds were unused anyway due to the mismatched githash.

Implementation-wise, CMake serves as the single source of truth for LEAN_GITHASH: it computes the stage0 tree hash once, embeds it as the non-release Lean.githash (as before), and passes it to Lake as LEAN_GITHASH for the core build (via stdlib.make). CI reads the file and sets LEAN_GITHASH in the CI job environment so that the standalone lake cache steps use the same key. The hash is computed with git rev-parse HEAD:stage0 rather than the previous git ls-tree HEAD "{}/../../stage0" --object-only, because it is now also needed at stage 1 where that relative path does not apply. Both commands return the same tree object hash.

🤖 Prepared with Claude Code

@tydeu tydeu added the changelog-no Do not include this PR in the release changelog label Jul 22, 2026
@tydeu tydeu changed the title fix: LEAN_GITHASH for Lake cache in CI fix: set a fixed LEAN_GITHASH for core Lake builds Jul 22, 2026
@tydeu tydeu changed the title fix: set a fixed LEAN_GITHASH for core Lake builds fix: pin LEAN_GITHASH for core Lake builds Jul 22, 2026
@tydeu
tydeu marked this pull request as ready for review July 22, 2026 07:14
@tydeu
tydeu requested a review from kim-em as a code owner July 22, 2026 07:14
@github-actions github-actions Bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Jul 22, 2026
@leanprover-bot

leanprover-bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-07-21 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-manual, reference manual CI should run now. You can force reference manual CI using the force-manual-ci label. (2026-07-22 07:14:40)
  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase 00f9caf44935b96cbeee36082c3abea67ab06792 --onto 49ff95727f98d43984726b26742d17a1ceea9dd5. You can force reference manual CI using the force-manual-ci label. (2026-07-22 22:20:54)

@github-actions github-actions Bot added the mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN label Jul 22, 2026
Comment thread src/CMakeLists.txt Resolved
mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request Jul 22, 2026
@mathlib-lean-pr-testing mathlib-lean-pr-testing Bot added the builds-mathlib CI has verified that Mathlib builds against this PR label Jul 22, 2026
@mathlib-lean-pr-testing

mathlib-lean-pr-testing Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

Mathlib CI status (docs):

  • ✅ Mathlib branch lean-pr-testing-14486 has successfully built against this PR. (2026-07-22 08:10:44) View Log
  • ✅ Mathlib branch lean-pr-testing-14486 has successfully built against this PR. (2026-07-22 17:43:59) View Log
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 00f9caf44935b96cbeee36082c3abea67ab06792 --onto 3259610687883ec1ea48c481aba2469f2f83facf. You can force Mathlib CI using the force-mathlib-ci label. (2026-07-22 22:20:53)

mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request Jul 22, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jul 22, 2026
@tydeu
tydeu force-pushed the tydeu/ci-lake-lean-githash branch from 0a13d2a to 04ad121 Compare July 22, 2026 21:55
@tydeu
tydeu force-pushed the tydeu/ci-lake-lean-githash branch from 942cbea to 70828a2 Compare July 23, 2026 01:02
@tydeu
tydeu force-pushed the tydeu/ci-lake-lean-githash branch from ddccd5f to 15ab3fa Compare July 23, 2026 01:35
@tydeu
tydeu added this pull request to the merge queue Jul 23, 2026
@tydeu
tydeu removed this pull request from the merge queue due to a manual request Jul 23, 2026
@tydeu
tydeu added this pull request to the merge queue Jul 23, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 23, 2026
@tydeu tydeu added the merge-ci Enable merge queue CI checks for PR. In particular, produce artifacts for all major platforms. label Jul 23, 2026
@tydeu
tydeu added this pull request to the merge queue Jul 24, 2026
Merged via the queue into master with commit 156bdc9 Jul 24, 2026
17 checks passed
@tydeu
tydeu deleted the tydeu/ci-lake-lean-githash branch July 24, 2026 04:48
JJYYY-JJY pushed a commit to JJYYY-JJY/lean4 that referenced this pull request Jul 28, 2026
)

This PR early exits "Check rebootstrap" when a rebootstrap does not
change stage0 (e.g., in the CI job for an `update-stage0` commit or for
a subsequent commit that makes no core changes).

After leanprover#14486, an empty commit changes `Lean.githash` without changing
the stage0 tree hash that keys Lake's traces, leaving stage 1 `.olean`s
stale with respect to the rebuilt binaries. This leads to an
incompatible header failure when attempting to read the old oleans with
the new `lean`.

This is solved by aborting the "Check rebootstrap" when the commit would
be empty. If stage0 did not change, there is nothing to rebootstrap
anyway, so running it previously was just a waste of time.

The PR also sets the `LEAN_GITHASH` on a rebootstrap to the new stage0
hash, ensuring any `lake` invocations in the tests invalidate leftover
stale builds keyed on the old githash. This should not occur (tests
should clear previous outputs before running). Nonetheless, a failure
here is hard to diagnose, so this is done defensively.

🤖 Prepared with Claude Code

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
wkrozowski pushed a commit to marcelolynch/lean4 that referenced this pull request Jul 29, 2026
)

This PR early exits "Check rebootstrap" when a rebootstrap does not
change stage0 (e.g., in the CI job for an `update-stage0` commit or for
a subsequent commit that makes no core changes).

After leanprover#14486, an empty commit changes `Lean.githash` without changing
the stage0 tree hash that keys Lake's traces, leaving stage 1 `.olean`s
stale with respect to the rebuilt binaries. This leads to an
incompatible header failure when attempting to read the old oleans with
the new `lean`.

This is solved by aborting the "Check rebootstrap" when the commit would
be empty. If stage0 did not change, there is nothing to rebootstrap
anyway, so running it previously was just a waste of time.

The PR also sets the `LEAN_GITHASH` on a rebootstrap to the new stage0
hash, ensuring any `lake` invocations in the tests invalidate leftover
stale builds keyed on the old githash. This should not occur (tests
should clear previous outputs before running). Nonetheless, a failure
here is hard to diagnose, so this is done defensively.

🤖 Prepared with Claude Code

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
robsimmons pushed a commit that referenced this pull request Jul 29, 2026
This PR restores reuse of the Lake artifact cache across core CI builds.

Since #13759, the `Linux Lake (Cached)` job downloaded the cache but
still rebuilt everything, because the cache trace is keyed on
`Lean.githash`, which is the commit hash on the release job that
produces the cache, but the stage0 tree hash on the non-release job that
consumes it. To fix this, the Lean trace Lake uses is overriden via
`LEAN_GITHASH` to be the stage0 tree hash (rather than whatever
`Lean.githash` may be). This ensures so stage1 `.olean`s are reusable
across commits that do not touch stage0. The override affects only the
cache trace, not the compiled `.olean`s, which still embed the same
`Lean.githash`.

Release builds cannot reuse `.olean`s embedded with a different
`Lean.githash`. Nonetheless, this change would allow Lake to reuse them
if they have the same stage0. To avoid this, restoring `.olean`s from
the cache is now completely disabled for release builds. In practice,
this is pure savings, as the `.olean`s restored from the cache during
release builds were unused anyway due to the mismatched githash.

Implementation-wise, CMake serves as the single source of truth for
`LEAN_GITHASH`: it computes the stage0 tree hash once, embeds it as the
non-release `Lean.githash` (as before), and passes it to Lake as
`LEAN_GITHASH` for the core build (via `stdlib.make`). CI reads the file
and sets `LEAN_GITHASH` in the CI job environment so that the standalone
`lake cache` steps use the same key. The hash is computed with `git
rev-parse HEAD:stage0` rather than the previous `git ls-tree HEAD
"{}/../../stage0" --object-only`, because it is now also needed at stage
1 where that relative path does not apply. Both commands return the same
tree object hash.

🤖 Prepared with Claude Code

---------

Co-authored-by: Claude Code <[email protected]>
robsimmons pushed a commit that referenced this pull request Jul 29, 2026
This PR early exits "Check rebootstrap" when a rebootstrap does not
change stage0 (e.g., in the CI job for an `update-stage0` commit or for
a subsequent commit that makes no core changes).

After #14486, an empty commit changes `Lean.githash` without changing
the stage0 tree hash that keys Lake's traces, leaving stage 1 `.olean`s
stale with respect to the rebuilt binaries. This leads to an
incompatible header failure when attempting to read the old oleans with
the new `lean`.

This is solved by aborting the "Check rebootstrap" when the commit would
be empty. If stage0 did not change, there is nothing to rebootstrap
anyway, so running it previously was just a waste of time.

The PR also sets the `LEAN_GITHASH` on a rebootstrap to the new stage0
hash, ensuring any `lake` invocations in the tests invalidate leftover
stale builds keyed on the old githash. This should not occur (tests
should clear previous outputs before running). Nonetheless, a failure
here is hard to diagnose, so this is done defensively.

🤖 Prepared with Claude Code

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
legion-implementer Bot added a commit to sjawhar/lean4 that referenced this pull request Nov 28, 2026
…LEAN_GITHASH (#6)

* ci: tag-build dispatch, no fork release assets, tests without LEAN_GITHASH

This member changes only `.github/`.

A dispatch of `ci.yml` with the new input `release_tag` builds as the run on
that tag would, before the tag exists:

    gh workflow run ci.yml --ref <branch> -f release_tag=v4.36-machcsl-r21

The step "Check for custom releases" of `configure` gives the input as its
output, so the run has check level 3, `stamped` builds, the job matrix and
target stage of the tag's run, and the same CMake options: a fork's tag gives
the build no `RELEASE_TAG` and no special version, so in both runs the version
stamp is the commit's githash. "Pack" compresses as on a tag. `IS_NIGHTLY` is
false whenever `release_tag` is set: the `action` input defaults to "release
nightly", and a dispatch with `release_tag` must take no nightly path.

The `release` job runs only on a tag push to leanprover/lean4. On a fork it
attached the CI's build artifacts to the tag's release. A fork's release holds
only the files that are published by hand (on theorem-labs/lean4, the measured
tarball and its `.sha256`), so the job no longer runs there. A dispatch is no
tag push, so it publishes nothing.

The steps "Test" and "Check rebootstrap" run the tests without `LEAN_GITHASH`.
The step "Build Stage 0 & Configure Stage 1" writes it to `GITHUB_ENV` (line
158 of build-template.yml at the trunk, line 163 in v4.36-machcsl-r20) from
`build/stage1/lake-githash`: the stage0 tree hash. `stdlib.make` passes that
value to the core build itself; the Lake cache steps (Download, Upload and
Verify Lake Cache, which run `build/stage0/bin/lake`) take it from the job's
environment (leanprover#14486). A stamped build runs none of these cache
steps (`lake-cache` is `!stamped`).

The tests of stage 2 (and of stage 1) do not need it: they run that stage's own
Lake and Lean, and with no override Lake takes the githash of that Lean (`lean
--githash`), as it does outside CI. Both stages are built with `USE_GITHASH`,
so that githash is the commit's, and the override names another Lean. Under
it, Lake scopes its remote cache by the override and queues, claims and reads
nothing remote (`remoteCacheQueueService?` in `Lake/Config/Env.lean`). That
failed the Lake tests inputLockClaims (cases 9a and 9b), remoteCacheClaim,
remoteCacheRead, remoteCacheRefused, remoteCachePush and usageCutoffRemote in
the job "build / Linux release" on the tag v4.36-machcsl-r20. Outside CI, the
runner's value of the variable gives the same failures, and without it the
tests pass (remoteCachePush's failing check needs a CMake build to reach). The
tests ran without the variable before leanprover#14486. "Check
rebootstrap" (which the Linux release job runs at check level 1 and up, so on a
tag, after "Test") exported the new stage0 hash for its stage 1 tests as a
defensive measure against stale builds (leanprover#14575). Without the
override Lake still keys every trace by the githash of the Lean it runs, which
the update-stage0 commit changes, so no test reuses a stale build.

Part of LINUX-1736.

Omp-Session: 01a21fea-50cc-71ef-b840-72b8c7ab62bb
Legion-Role: implementer

* ci: validate release_tag, keep it out of shell source, fork-only

Review of the previous commit found that the `release_tag` input reached
`GITHUB_OUTPUT` as typed, and that "Set check level" put that output into
its Bash source: a line break could change the step's outputs, and shell
metacharacters could change what Bash runs.

"Check for custom releases", the only step that reads the input, now takes
it as environment data and refuses it unless it is a tag name: `v` and then
letters, digits, `.`, `_` or `-` (`^v[0-9A-Za-z._-]+$`). The error names the
rule and prints the refused value escaped with `printf %q`, on one line.
"Set check level" no longer reads the tag text: it reads whether that step
gave a tag, as the Boolean `CUSTOM_RELEASE`. This also covers a fork's tag
push, whose name the step passed into Bash source in the same way. The other
places that read the input (`IS_NIGHTLY` in `configure`, "Pack" in
build-template.yml) use it only in a Boolean expression.

The input is for forks. On leanprover/lean4 the step refuses it with an
error, where before such a dispatch silently built at check level 1; the
input's description says so.

A dispatch with `release_tag` has a concurrency group of its own (the
group gets the suffix `-release-tag`), so that it and a nightly re-release
dispatch on the same ref no longer cancel each other.

Part of LINUX-1736.

Omp-Session: 01a21fea-50cc-71ef-b840-72b8c7ab62bb
Legion-Role: implementer

* ci: fork tag build without macOS aarch64 and Windows tests, tsanitize on 64 GB

The decision on the jobs of the fork's tag build other than Linux release
(LINUX-1736, E3(5)), applied in the build matrix of `configure`. "The fork's
tag build" is a fork's tag push or a dispatch with `release_tag`: the runs
in which "Check for custom releases" gives a tag, which the matrix script
now reads as the Boolean `forkTag`. On every other event (pull_request,
merge_group, a push to master, schedule, a nightly, leanprover/lean4's own
tags) the matrix is unchanged.

- macOS aarch64 and Windows: not tested in the fork's tag build; they still
  build there, as a compile check. With `test` false their Test step does
  not run, nor the steps that only read its results (Protect and Unprotect
  Source Tree, Check Source Tree Clean, Embed Test Output, Test Summary,
  Check Test Binary, all conditioned on `matrix.test` or on the Test step's
  conclusion in build-template.yml, which is unchanged). The fork publishes
  no macOS or Windows build. On r20's tag 27 Lake tests and
  elab/openssl.lean failed on macOS aarch64: the fork's Lake tests assume
  GNU tools and a newer bash than macOS's bash 3.2, and the runner's OpenSSL
  is 4. The fork's tests assume a POSIX system, so Windows failed 40 tests in
  a rehearsal of r21's tag build; #12 keeps its build working.
- Linux tsanitize: in theorem-labs/lean4's tag build it runs on the GitHub
  larger runner `ubuntu-24.04-16core` (16 CPUs, 64 GB). On ubuntu-latest the
  runner was lost about 39 s into elab/async_http_h1_incremental.lean, on
  r20's tag and on the rehearsal; upstream gives this job 32 CPUs and 64 GB.
  A probe run on theorem-labs/lean4 (run 46126841398, 2026-11-28) got that
  label in the organization's runner group `proofs`, with 16 CPUs and 62 GiB
  as `free -g` counts. Elsewhere (sjawhar/lean4, where the label does not
  exist) the job keeps ubuntu-latest. Its `-j2` stays: the bound is the
  memory of the TSAN tests, and 64 GB is upstream's memory too. The job has
  no `timeout-minutes` of its own (GitHub's 360 minutes); it built in about 54
  minutes on the 4-CPU hosted runner.
- Linux aarch64 and Linux fsanitize are unchanged.

Part of LINUX-1736.

Omp-Session: 01a21fea-50cc-71ef-b840-72b8c7ab62bb
Legion-Role: implementer

* ci: fork tag build only on a tag push or a release_tag dispatch

Review of the previous commit found that a `workflow_dispatch` from a
tag ref without `release_tag` (for example a nightly re-release, the
`action` input's default) also counted as the fork's tag build: "Check
for custom releases" runs on any tag ref of a fork and gives the ref's
tag name, so `forkTag` was true, and that dispatch lost the tests of
macOS aarch64 and Windows and, on theorem-labs/lean4, moved Linux
tsanitize to the larger runner.

`forkTag` now also requires a tag push (`push` of a `refs/tags/` ref) or
a dispatch whose `release_tag` is not empty. The check level is selected
as before.

The comment on Linux tsanitize now says only what is known: on
ubuntu-latest the runner was lost about 39 s into
elab/async_http_h1_incremental.lean (on r20's tag and on a rehearsal of
r21's), the larger runner is for its memory, the probe run 46126841398
got `ubuntu-24.04-16core` on theorem-labs/lean4, so the workflow selects
it only there, and the job keeps upstream's `-j2`, which upstream uses on
64 GB, the same memory. It no longer says that the label exists nowhere
else, nor that memory bounds the tests.

Rendered with the matrix script of `configure`: a tag push on
theorem-labs/lean4, a `release_tag` dispatch on sjawhar/lean4 and a pull
request give the same matrix as with the previous commit; a dispatch from
a tag ref without `release_tag`, on either repository, gives the matrix of
the commit before it again.

Part of LINUX-1736.

Omp-Session: 01a21fea-50cc-71ef-b840-72b8c7ab62bb
Legion-Role: implementer

* ci: no Lake cache upload where the repository has no cache endpoint

The pull requests within the fork failed at `Upload Lake Cache`, before
their tests ran. The step's condition leaves out only pull requests from
other repositories, but the fork has neither the secret LAKE_CACHE_KEY
nor the variable LAKE_CACHE_ENDPOINT. So `lake cache put` ran with an
empty key and the endpoint `/a1`, and stopped with "curl produced invalid
JSON ... Enter host password" and "URL using bad/illegal format", exit 1.

The step now also needs `vars.LAKE_CACHE_ENDPOINT != ''`. Where the
variable is set, as on leanprover/lean4, nothing changes. `Verify Lake
Cache` and `Restore Build` run only after a successful upload, so they
are skipped too. `Download Lake Cache` stays as it is: it reads
Reservoir, not that endpoint, and it is `continue-on-error` (on the fork
it stops in about two seconds with "no outputs found for any revision").

Part of LINUX-1736.

Omp-Session: 01a21fea-50cc-71ef-b840-72b8c7ab62bb
Legion-Role: implementer

---------

Co-authored-by: legion-implementer[bot] <343353655+legion-implementer[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

builds-mathlib CI has verified that Mathlib builds against this PR changelog-no Do not include this PR in the release changelog mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN merge-ci Enable merge queue CI checks for PR. In particular, produce artifacts for all major platforms. toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants