Skip to content

Acquire rewatch build lock before initialization#8409

Merged
cknitt merged 3 commits intomasterfrom
codex/fix-rewatch-build-lock
May 4, 2026
Merged

Acquire rewatch build lock before initialization#8409
cknitt merged 3 commits intomasterfrom
codex/fix-rewatch-build-lock

Conversation

@cknitt
Copy link
Copy Markdown
Member

@cknitt cknitt commented May 4, 2026

Motivation

build.lock is meant to prevent multiple rewatch build processes from mutating the same project build artifacts at the same time.

Before this change, build::build called initialize_build before acquiring build.lock. That was unsafe because initialization is not read-only: it reads the previous compile state and calls cleanup_previous_build, which can remove stale .ast, .iast, .cmi, .cmj, .cmt, .cmti, and generated JS artifacts under lib/bs.

If two rewatch build processes started at the same time in the same project, both could enter initialization and cleanup concurrently. Only later, when each reached incremental_build, would one process wait on build.lock. By then, both processes may already have inspected or mutated the previous build state, which can lead to racey cleanup and nondeterministic dirty-module state.

Summary

  • Acquire build.lock before build::build runs initialization.
  • Keep the lock held through initialization, compilation, post-build cleanup, and build.ninja writes.
  • Split the incremental compile body into an unlocked helper so incremental_build keeps its existing public locking behavior while full builds can use a wider lock boundary.
  • Add regression coverage proving build::build waits for an existing build.lock before initialization starts.

@cknitt
Copy link
Copy Markdown
Member Author

cknitt commented May 4, 2026

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cknitt cknitt requested a review from jfrolich May 4, 2026 13:50
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 4, 2026

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript@8409

@rescript/darwin-arm64

npm i https://pkg.pr.new/@rescript/darwin-arm64@8409

@rescript/darwin-x64

npm i https://pkg.pr.new/@rescript/darwin-x64@8409

@rescript/linux-arm64

npm i https://pkg.pr.new/@rescript/linux-arm64@8409

@rescript/linux-x64

npm i https://pkg.pr.new/@rescript/linux-x64@8409

@rescript/runtime

npm i https://pkg.pr.new/@rescript/runtime@8409

@rescript/win32-x64

npm i https://pkg.pr.new/@rescript/win32-x64@8409

commit: e6d9fa2

@cknitt cknitt enabled auto-merge (squash) May 4, 2026 14:54
@cknitt cknitt merged commit 2778706 into master May 4, 2026
31 checks passed
@cknitt cknitt deleted the codex/fix-rewatch-build-lock branch May 4, 2026 15: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.

2 participants