From: Fabian Huch <huch@in.tum.de>
Subject: [isabelle] Race condition preventing messages in finished_theories outlet
Since Isabelle/74ffd288f3bf, there is a race condition that can prevent
finished_theories messages to be posted. This results e.g. in missing
HTML documents even though the build finished successfully.
The race condition is that the Session.nodes_status_buffer.state gets
resetted within the thread at the beginning of its main loop (l. 432):
val current =state.change_result(st => (st, st.reset))
Once the prover completes, the shutdown() method on line 483 sets the
state to finished and stops the thread, but non-atomically:
def shutdown():Unit = {
state.change(_.finish)
thread.join()
}
This update can be lost, depending on where the thread execution is,
resulting in a missing post when finished is checked (l. 467):
if (current.finished) {
for (thy_snapshot <-current.finished_theories) {
finished_theories.post(
Fabian
From: balazs.toth@lmu.de
Subject: [isabelle] Race condition preventing messages in finished_theories outlet
Hi Fabian,
I think I hit the same race, in my case as missing PIDE exports instead
of missing HTML. In a full AFP build with Isabelle2026, 67 of 1168
session dbs had no PIDE/document_id for any theory, so Find_Facts just
said “No snapshot for theory ...” for the whole session. The affected
sessions looked random.
I don’t think the finish itself gets lost, since state.change is atomic
and reset keeps the flag. What I believe happens is that main() runs
after handle_exit has added the finished theories but before shutdown()
sets finished. It then takes them with finished = false, resets them and
posts nothing, and the last run after shutdown has nothing left.
My claude tells me, that something like this should fix it:
val current =
state.change_result(st =>
(st, if (st.finished) st.reset else st.copy(changed_nodes = Set.empty)))
Balazs
On 05.11.26 17:01, Fabian Huch wrote:
Since Isabelle/74ffd288f3bf, there is a race condition that can
prevent finished_theories messages to be posted. This results e.g. in
missing HTML documents even though the build finished successfully.The race condition is that the Session.nodes_status_buffer.state gets
resetted within the thread at the beginning of its main loop (l. 432):val current =state.change_result(st => (st, st.reset))
Once the prover completes, the shutdown() method on line 483 sets the
state to finished and stops the thread, but non-atomically:def shutdown():Unit = {
state.change(_.finish)
thread.join()
}This update can be lost, depending on where the thread execution is,
resulting in a missing post when finished is checked (l. 467):if (current.finished) {
for (thy_snapshot <-current.finished_theories) {
finished_theories.post(Fabian
From: Fabian Huch <huch@in.tum.de>
Subject: [isabelle] Race condition preventing messages in finished_theories outlet
I think I hit the same race, in my case as missing PIDE exports
instead of missing HTML. In a full AFP build with Isabelle2026, 67 of
1168 session dbs had no PIDE/document_id for any theory, so Find_Facts
just said “No snapshot for theory ...” for the whole session. The
affected sessions looked random.Yes, the problem prevents PIDE exports, so you'll see exactly this effect.
On 11/5/26 18:59, balazs.toth@lmu.de wrote:
I don’t think the finish itself gets lost, since state.change is
atomic and reset keeps the flag.The state change is atomic, yes, but the update does get lost: 'main'
only reads 'current' in the beginning, so if the state is finished after
that but during main(), it will never be read (test() reads the new
value already).
The current code basically relies on the finish update to occur during
the sleep (setting build_progress_delay to 0 reproduces the problem
reliably).
What I believe happens is that main() runs after handle_exit has
added the finished theories but before shutdown() sets finished. It
then takes them with finished = false, resets them and posts nothing,
and the last run after shutdown has nothing left.My claude tells me, that something like this should fix it:
val current =
state.change_result(st =>
(st, if (st.finished) st.reset else st.copy(changed_nodes = Set.empty)))
I initially suspected the reset (and should have re-worded my mail more
thoroughly), but this doesn't seem to be a problem: a) current takes the
old state, not the resetted one and b) shutdown only gets called after
the prover is finished.
In any case, the sources need to be made clearer to solve this problem,
and not 'fixed' to make them even less clear (and certainly not with a
'fix' generated by AI).
Fabian
Last updated: Nov 19 2026 at 01:46 UTC