fix: make experimental file locks importable on Windows#1927
Open
JWilksBooth wants to merge 1 commit into
Open
fix: make experimental file locks importable on Windows#1927JWilksBooth wants to merge 1 commit into
JWilksBooth wants to merge 1 commit into
Conversation
verifiers.envs.experimental.utils.file_locks and .git_checkout_cache import fcntl unconditionally, so importing verifiers (and therefore vf.load_environment and the entire vf-eval CLI) crashes on Windows with "ModuleNotFoundError: No module named 'fcntl'", surfaced misleadingly as a prompt to install verifiers[all]. Guard the fcntl import and fall back to msvcrt byte-range locking on Windows: - Shared locks degrade to exclusive locks (msvcrt has no shared locks), which is strictly more conservative and preserves the worktree pruning contract. - Contended nonblocking acquisitions raise BlockingIOError, matching flock(LOCK_EX | LOCK_NB) semantics, so _prune_stale_worktrees keeps skipping in-use checkouts instead of crashing. Verified on Windows 11 / Python 3.10.9: lock acquire/release/ reacquire, cross-process nonblocking contention, and the process-lifetime in-use lock in git_checkout_cache. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
verifiers.envs.experimental.utils.file_locks and .git_checkout_cache import fcntl unconditionally, so importing verifiers (and therefore vf.load_environment and the entire vf-eval CLI) crashes on Windows with "ModuleNotFoundError: No module named 'fcntl'", surfaced misleadingly as a prompt to install verifiers[all].
Description
Guard the fcntl import and fall back to msvcrt byte-range locking on Windows:
Type of Change
Testing
Verified on Windows 11 / Python 3.10.9 against this branch's modules loaded by path:
uv run pytestnot run locally (Windows box; POSIX paths untouched and byte-identical in behavior).Checklist
Additional Notes
import fcntl, but only loads with the v1 prime/modal runtimes (off the default import path) — left untouched; happy to guard it the same way if wanted.Note
Medium Risk
Changes cross-process locking semantics on Windows (shared locks become exclusive) in git checkout pruning and experimental env utilities; POSIX behavior is untouched but concurrency contracts differ on the new platform.
Overview
Fixes Windows import crashes (
ModuleNotFoundError: fcntl) forverifiers.envs.experimental.utils.file_locksandgit_checkout_cache, which blockedvf.load_environmentand the eval CLI on that platform.file_locks.pynow probesfcntlat import time and, when missing, usesmsvcrtbyte-range locking via a new_msvcrt_file_lockhelper wired intoshared_file_lockandexclusive_file_lock. On Windows, shared locks become exclusive (no shared mode inmsvcrt), which the PR treats as stricter but safe. Nonblocking contention is normalized toBlockingIOError, matchingflock(LOCK_NB)so callers like_prune_stale_worktreeskeep skipping in-use checkouts instead of failing on bareOSError.git_checkout_cache.pyapplies the same_HAVE_FCNTLguard for process-lifetime in-use locks in_acquire_in_use_lock, usingmsvcrt.LK_LOCKwhenfcntlis unavailable. POSIX paths are unchanged whenfcntlimports successfully.Reviewed by Cursor Bugbot for commit 0c30716. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Fix file lock imports in experimental utils to work on Windows
fcntlimports in file_locks.py and git_checkout_cache.py with try/except blocks that fall back tomsvcrton Windows, gated by a_HAVE_FCNTLflag._msvcrt_file_lockcontext manager that implements byte-range locking viamsvcrt.locking, with blocking and nonblocking modes andBlockingIOErroron contention to mirrorfcntlsemantics.shared_file_lockandexclusive_file_lockuse exclusive 1-byte locks sincemsvcrthas no shared lock primitive.Macroscope summarized 0c30716.