From 37396fc66d541d41e08c6009ad45986ebf7165a8 Mon Sep 17 00:00:00 2001 From: frohsinnllc <231045016+frohsinnllc@users.noreply.github.com> Date: Mon, 13 Jul 2026 03:32:09 +0200 Subject: [PATCH] refactor(cli): run the web-UI staleness walk once, under the build lock The flock wrapper checked _web_ui_build_needed twice (pre-lock fast path and post-lock re-check) and _do_build_web_ui checks it again internally, so a boot that actually built walked the whole web/ source tree three times. The callee's own check already runs under the lock on every path through the wrapper, so it alone is sufficient: drop both wrapper checks. Co-Authored-By: Claude Fable 5 --- hermes_cli/main.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/hermes_cli/main.py b/hermes_cli/main.py index 173a7c99cd10..9bcea1ba6c6d 100644 --- a/hermes_cli/main.py +++ b/hermes_cli/main.py @@ -5160,11 +5160,13 @@ def _build_web_ui(web_dir: Path, *, fatal: bool = False) -> bool: boot re-triggered the build. One process builds under an exclusive flock; the rest serve the existing dist (stale is acceptable) or, when no dist exists yet, block until the builder finishes. + + Staleness is checked once, inside :func:`_do_build_web_ui`, after the + lock is held — so a process that queued behind the builder skips the + rebuild, and the (os.walk-based) check runs at most once per boot. """ if not (web_dir / "package.json").exists(): return True - if not _web_ui_build_needed(web_dir): - return True try: import fcntl except ImportError: @@ -5186,10 +5188,6 @@ def _build_web_ui(web_dir: Path, *, fatal: bool = False) -> bool: return True # No dist at all (first-ever build): wait for the builder. fcntl.flock(lock_file.fileno(), fcntl.LOCK_EX) - # Re-check under the lock: the previous holder may have finished - # the build while this process was waiting or racing for it. - if not _web_ui_build_needed(web_dir): - return True return _do_build_web_ui(web_dir, fatal=fatal) finally: lock_file.close()