Skip to content

fix: correctly set initHeartbeats in Lean.Environment.unsafeRunMetaM#12994

Closed
eric-wieser wants to merge 1 commit intoleanprover:masterfrom
eric-wieser:patch-73
Closed

fix: correctly set initHeartbeats in Lean.Environment.unsafeRunMetaM#12994
eric-wieser wants to merge 1 commit intoleanprover:masterfrom
eric-wieser:patch-73

Conversation

@eric-wieser
Copy link
Copy Markdown
Contributor

@eric-wieser eric-wieser commented Mar 19, 2026

This PR ensures that Lean.Environment.unsafeRunMetaM can be run late in a lean process, without thinking it has already consumed all available heartbeats.

@eric-wieser
Copy link
Copy Markdown
Contributor Author

changelog-library

@github-actions github-actions Bot added the changelog-library Library label Mar 19, 2026
@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 Mar 19, 2026
@mathlib-lean-pr-testing
Copy link
Copy Markdown

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase fd5329126bed2c921d53daf1919de58977116e51 --onto 61a3443a9569d548a235f785b9a33984bb7ff622. You can force Mathlib CI using the force-mathlib-ci label. (2026-03-19 23:14:10)

@leanprover-bot
Copy link
Copy Markdown
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase fd5329126bed2c921d53daf1919de58977116e51 --onto cfa8c5a036d6990635c6ec50b02d0e806995cec3. You can force reference manual CI using the force-manual-ci label. (2026-03-19 23:14:12)

@eric-wieser eric-wieser changed the title fix(Lean/LibrarySuggestions): correctly set initHeartbeats fix: correctly set initHeartbeats in Lean.Environment.unsafeRunMetaM Mar 20, 2026
@fiforeach
Copy link
Copy Markdown
Contributor

Thanks for this.

With this change maxHeartbeats gets a special treatment. Are there other options that one might reasonably be expected to be passed to the sub-execution? Are there reasons not to pass all options that were set?

@eric-wieser
Copy link
Copy Markdown
Contributor Author

With this change maxHeartbeats gets a special treatment.

I'm passing initHeartbeats, not maxHeartbeats

Are there reasons not to pass all options that were set?

initHeartbeats is state, not an option.

@fiforeach
Copy link
Copy Markdown
Contributor

I see.

So do I understand correctly that this will initialize the "sub execution" to continue with a potentially nonzero initial value of heartbeats, potentially causing the maximum to be reached even earlier than previously?

@eric-wieser
Copy link
Copy Markdown
Contributor Author

eric-wieser commented Mar 20, 2026

No, the opposite; when code does a heartbeat check, it asserts that getNumHeartbeats <= initHeartbeats + limit. For this to make sense, initHeartbeats needs to be initialized at the point where the relevant code begins, else the limit will instead be enforced from when Lean started up.

@Kha
Copy link
Copy Markdown
Member

Kha commented Mar 31, 2026

Thanks but I'm relatively sure we want #13202 instead (perhaps it doesn't even matter in practice)

@Kha Kha closed this Mar 31, 2026
@eric-wieser
Copy link
Copy Markdown
Contributor Author

I think you do need this one, else a callback that does change the heartbeat limit will not count it correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog-library Library 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.

4 participants