Skip to content

fix(build): clean stale meson lockfile before setup - #2486

Merged
zackees merged 2 commits into
masterfrom
cleanup-stale-meson-lockfile-2484
May 18, 2026
Merged

zackees merged 2 commits into
masterfrom
cleanup-stale-meson-lockfile-2484

Conversation

@zackees

@zackees zackees commented May 18, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes #2484. Follow-up to #2483 (which bumped the meson floor to 1.11.0 and replaced the cryptic NoneType crash with the real underlying OSError).

On Windows, an abandoned or killed meson process leaves a stale meson-private/meson.lock file. The next meson setup invocation hits that stale lock and fails — meson 1.11.0 surfaces the error cleanly now, but the failure itself is avoidable.

This patch adds a small helper cleanup_stale_meson_lockfile() that removes the stale lockfile before invoking meson setup. The helper is tolerant of file-in-use errors on Windows: on failure it logs and continues, so the caller still sees the real underlying error from meson.

Call sites

  • ci/meson/build_config.py::setup_meson_build() — before the main meson setup invocation and before the cache-clear retry.
  • ci/wasm_build.py::ensure_meson_configured() — both the initial setup and the reconfigure-on-source-change branches.
  • ci/wasm_build.py::_recover_stale_wasm_build() — before the self-healing reconfigure attempt.

Test plan

  • bash test --cpp — all tests pass (304/304)
  • bash lint — pass
  • Manual verification: helper correctly handles (a) missing meson-private/, (b) stale lockfile present, (c) lockfile absent.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Improved build robustness by automatically removing stale Meson lockfiles before build/setup attempts (Windows-only), and re-running setup when needed. This reduces persistent build failures and makes retry/reconfigure flows more reliable.

Review Change Stack

On Windows, meson <= 1.10.x crashed cryptically in
DirectoryLock.__enter__ when the underlying lockfile open() raised
an OSError (e.g., from a stale lockfile left by a killed or abandoned
meson process). meson 1.11.0 (PR #2483) fixed the crash itself, but
the underlying cause -- a stale meson-private/meson.lock file --
still produces an avoidable setup failure on Windows.

This patch adds a small helper cleanup_stale_meson_lockfile() that
removes the stale lockfile before invoking meson setup, eliminating
the failure entirely. The helper is tolerant of file-in-use errors:
on failure it logs and continues so the caller still sees the
underlying meson error (now visible thanks to the 1.11.0 bump).

Call sites:
  - ci/meson/build_config.py: setup_meson_build() -- before main
    meson setup invocation (and before the cache-clear retry).
  - ci/wasm_build.py: ensure_meson_configured() -- before the
    initial setup and the reconfigure paths.
  - ci/wasm_build.py: _recover_stale_wasm_build() -- before the
    self-healing reconfigure attempt.

Closes #2484.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented May 18, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1f108704-a885-41f2-aff1-8a30ae50f6e5

📥 Commits

Reviewing files that changed from the base of the PR and between a698783 and 9c9fac6.

📒 Files selected for processing (1)
  • ci/meson/build_config.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • ci/meson/build_config.py

📝 Walkthrough

Walkthrough

Adds a Windows-only helper to remove stale meson-private/meson.lock and invokes it before Meson setup/reconfigure attempts in ci/meson/build_config.py and ci/wasm_build.py, including the WASM stale-build recovery path.

Changes

Stale Meson Lockfile Cleanup

Layer / File(s) Summary
Core lockfile cleanup function
ci/meson/build_config.py
Adds cleanup_stale_meson_lockfile(build_dir: Path) -> bool which deletes meson-private/meson.lock on Windows, logs success or warnings, and returns whether a lockfile was removed.
Build config setup integration
ci/meson/build_config.py
Invokes cleanup_stale_meson_lockfile() immediately before the initial meson setup and before the retry in the stale-cache recovery branch inside setup_meson_build().
WASM build setup and recovery integration
ci/wasm_build.py
Adds _cleanup_stale_meson_lockfile() wrapper that calls the core helper. Calls are inserted before WASM stale-build reconfigure, before source-list-change-triggered reconfigures, and before fresh Meson setup in ensure_meson_configured() and _recover_stale_wasm_build().

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I found a lock left all alone,
A ghost from a Meson that once had flown.
I nibbled the file with careful cheer,
So builds on Windows can now run clear.
Hop, skip, compile — no more stale fear!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding cleanup of stale meson lockfiles before setup, which is the core modification across both modified files.
Linked Issues check ✅ Passed All coding requirements from issue #2484 are met: lockfile cleanup added before meson setup in both ci/meson/build_config.py and ci/wasm_build.py, with cleanup integrated into initial setup, reconfigure, and recovery paths as specified.
Out of Scope Changes check ✅ Passed All changes are directly related to the stated objective of removing stale meson lockfiles before setup. No unrelated modifications to build logic, artifact caching, compilation, or linking were introduced.
Docstring Coverage ✅ Passed Docstring coverage is 88.89% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cleanup-stale-meson-lockfile-2484

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@ci/meson/build_config.py`:
- Around line 400-429: The function cleanup_stale_meson_lockfile currently
unconditionally unlinks the meson-private/meson.lock file and catches OSError
without explicitly handling KeyboardInterrupt and without restricting the
behavior to Windows; change it to only attempt removal when running on Windows
(use platform.system() or equivalent) and move a KeyboardInterrupt except clause
ahead of the generic OSError handler so SIGINT is re-raised; specifically, guard
the lockfile.unlink call inside a Windows-only branch in
cleanup_stale_meson_lockfile and add an explicit except KeyboardInterrupt: raise
before the except OSError as e: logging/ts_print path that returns False.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b339a14c-084a-4ccb-8265-8d44869b3dda

📥 Commits

Reviewing files that changed from the base of the PR and between 1c5f873 and a698783.

📒 Files selected for processing (2)
  • ci/meson/build_config.py
  • ci/wasm_build.py

Comment thread ci/meson/build_config.py Resolved
Apply two corrections to cleanup_stale_lockfile() per CodeRabbit
review on PR #2486 (thread 3262492253):

- Add Windows-only platform guard via os.name != "nt". The stale
  lockfile cleanup is only needed for the Windows DirectoryLock bug.
  On POSIX, the build system uses fcntl/flock (advisory), so removing
  an in-use lockfile could let a concurrent setup bypass the lock.
- Add explicit KeyboardInterrupt handling before the OSError handler,
  routed through handle_keyboard_interrupt() per project convention.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees merged commit ab36dc7 into master May 18, 2026
10 of 11 checks passed
@zackees
zackees deleted the cleanup-stale-meson-lockfile-2484 branch May 18, 2026 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clean stale meson-private/meson.lock before meson setup (Windows)

1 participant