Repository navigation
fix(watch): don't wait forever when msvcrt.locking is unsupported (#4924) - #4926
AndresDiagoM wants to merge 1 commit into
Conversation
On Windows, _rebuild_lock treated every OSError from msvcrt.locking as "another rebuild holds the lock". On a filesystem that cannot byte-range lock at all (the WSL share \wsl.localhost raises EINVAL on every call), the blocking `graphify update` CLI slept in a `while True` forever, and the non-blocking git hooks queued their change and returned, with no lock holder ever left to drain the queue. Only EACCES/EDEADLK now count as contention. Any other errno is treated as "locking unsupported": the rebuild proceeds without a lock and a warning on stderr names the lock file. That path does not take over .rebuild.lock (no PID write, no unlink on release), because a WSL-side flock holder may own it and unlinking it would let a second WSL-side caller in on a fresh inode (Graphify-Labs#4273). An empty lock file this call created only to probe the lock is removed again before the rebuild. Fixes Graphify-Labs#4924 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks for the pull request, @AndresDiagoM. A maintainer will review it soon. Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions. A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic. |
There was a problem hiding this comment.
Graphify reviewed this change.
No issues found by static checks — no coupling regressions or blocking issues in the code graph. That is not the same as safe to merge: see what was not checked.
Not checked: tests were not run; formal verification proved 0 of 1 changed function(s) (1 not verified).
Formal verification. PR-changed functions: 0/1 verified (0 proven, 0 may-equivalent, 0 distinguished) · 1 not verified (1 vacuous).
Not verified on this run: \_rebuild\_lock (vacuous: never exercised).
Graphify review — findings
Fixes _rebuild_lock hanging or never rebuilding on Windows when msvcrt.locking can't take a byte-range lock at all, such as the \\wsl.localhost share (#4924). Only contention errnos (EACCES/EDEADLK) are retried now, with blocking callers polling and non-blocking callers yielding False; any other error warns on stderr and proceeds unlocked, so rebuilds on that filesystem are no longer serialized. That fallback leaves a pre-existing .rebuild.lock untouched since a WSL-side flock holder may own it, and only unlinks the file if this call created it and it is still empty, which is the cleanup that could remove a file another process just created.
No blocking issues surfaced. 2 lower-confidence candidates did not survive cross-model review.
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 890 functions depend on the 543 functions this change touches.
Health — grade A; 10 existing hotspot(s) in the area this change touches (pre-existing, not introduced here):
_rebuild_code()— 213 callers, 67 callees (high)dispatch_command()— 5 callers, 142 callees (high)main()— 121 callers, 3 callees (high)_run_cli()— 11 callers, 8 callees (high)watch()— 6 callers, 11 callees (high)_check_shrink()— 17 callers, 3 callees (high)_reconcile_graph_html()— 8 callers, 5 callees (high)_inputs_unchanged()— 4 callers, 4 callees (medium)- …and 2 more
Verification — 890 functions in the blast radius were not formally verified this run (proofs are advisory here).
Gate & verification
graphify gate
PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.
Advisory (not blocking):
- verification_scope: 634 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
31 of 487 test file(s) selected (6%) via static blast radius.
tests/test_cache_stale_import_target.py— impacttests/test_compact_graph_json.py— impacttests/test_csharp_method_owner_labels.py— impacttests/test_elixir_import_resolution.py— impacttests/test_elixir_qualified_calls.py— impacttests/test_elixir_unqualified_call_scope.py— impacttests/test_export_direction.py— impacttests/test_external_stub_endpoints.py— impacttests/test_go_receiver_member_calls.py— impacttests/test_incremental_unscanned_placeholders.py— impacttests/test_java_member_calls.py— impacttests/test_kotlin_grammar.py— impacttests/test_labeling.py— impacttests/test_language_override_lifecycle.py— impacttests/test_lost_saved_semantic_nodes.py— impacttests/test_markdown_code_spans.py— impacttests/test_no_cluster_undeclared_endpoints.py— impacttests/test_pr10_watch_overrides.py— impacttests/test_python_inherited_method_calls.py— impacttests/test_python_injected_factory_calls.py— impacttests/test_python_property_reads.py— impacttests/test_python_pytest_fixture_receivers.py— impacttests/test_rust_use_trees.py— impacttests/test_skill_persisted_scan_options.py— impacttests/test_solidity_inherited_calls.py— impacttests/test_terraform_modules.py— impacttests/test_undirected_two_file_import_cycle.py— impacttests/test_update_no_change_gate.py— impacttests/test_watch.py— impact, changed-testtests/test_watch_identity_cache.py— impacttests/test_watch_manifest_location.py— impact
Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.
Docs that may be stale (advisory)
CHANGELOG.md§ 0.9.63 (2026-09-16) (lines 654-661): references changed symbolssleep
Formal verification
Could not verify: Could not verify \_rebuild\_lock.
The verifier did not have enough to check \_rebuild\_lock, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: all 9 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous
|
Landed in 0.9.101 (published to PyPI), cherry-picked with your authorship preserved. Fixes #4924. Thanks @AndresDiagoM. |
What does this PR do?
Fixes #4924.
On Windows,
_rebuild_locktreated everyOSErrorfrommsvcrt.lockingas "another rebuild holds the lock". On a filesystem that cannot byte-range lock at all, such as the WSL share\\wsl.localhost\<distro>\...(where the call raisesEINVALevery time), that made the blockinggraphify updateCLI (block_on_lock=True) sleep in awhile Trueforever. The non-blocking git hooks queued their change and returned "Rebuild already in progress", with no lock holder ever left to drain the queue.The Windows branch now looks at the errno:
EACCES/EDEADLKis contention, and behaves as before: blocking callers wait and retry every 50 ms, non-blocking callers getFalse.yield True, like the existing fallback when neitherfcntlnormsvcrtexists), and a warning on stderr names the lock file.In that unsupported case the caller does not take over
.rebuild.lock: it writes no PID into it and does not unlink it on release. On a WSL-share repo the file can belong to a WSL-sideflockholder. Overwriting its PID, or unlinking the path, would let the next WSL-side callerflocka fresh inode while the first is still rebuilding (the #4273 race). If this call created the file only to try the lock, it removes that still-empty file again before the rebuild starts, so no stale lock is left behind (GH-858).The POSIX branch is unchanged.
Type of change
Verification & Invariants
Invariants:
_rebuild_lockonly for another holder, never for a condition that cannot change.Tests, in
tests/test_watch.py. They run the msvcrt branch on any OS through a stand-inmsvcrt, withfcntlhidden.time.sleepis replaced so a loop that never ends fails the test instead of hanging it.test_rebuild_lock_blocking_does_not_spin_when_filesystem_cannot_locktest_rebuild_lock_non_blocking_proceeds_when_filesystem_cannot_locktest_rebuild_lock_unsupported_filesystem_leaves_another_holders_lock_file_alone[True/False]: a pre-existing.rebuild.lockwith a foreign PID must keep its content and inodetest_rebuild_lock_blocking_still_waits_while_msvcrt_lock_is_contendedtest_rebuild_lock_non_blocking_still_yields_false_while_msvcrt_lock_is_contendedThe "leaves another holder's lock file alone" test also fails on an earlier version of this branch, which wrote its PID and unlinked the file in the unsupported case. I checked that the real two-OS race it guards against exists:
flock.graphify-outthrough\\wsl.localhost.With that earlier version, L2 got the lock while L1 still held it. With this PR, L1's PID and the file stay intact, and L2 gets
Falseuntil L1 releases.Limitations:
_rebuild_lockis a no-op on Windows, so the #1037 race is still unfixed there #3881), now limited to filesystems where locking cannot work at all. Before this PR they hung forever instead. Keeping Windows-side serialization there would need a separate lock on a local path (e.g. under the temp dir, keyed by the resolvedgraphify-out); I left that out to keep this to one concern.EACCESfor a contended lock andEINVALon\\wsl.localhost. I have not tested an SMB share; a filesystem that reported contention with some other errno would now proceed unlocked instead of waiting.graphify updatefrom Windows on a\\wsl.localhostrepo no longer hangs, but it can still fail on files with uppercase names. That is a separate bug infile_hashpath normalization, reported infile_hashopens the lowercased path on Windows, so files with uppercase names fail on case-sensitive dirs (\wsl.localhost) #4925; this PR does not touch it.How was this tested?
On Windows,
uv runcould not fetch dependencies on this machine (TLS interception:invalid peer certificate: UnknownIssuer). The Windows runs therefore used an existing venv of this project (CPython 3.13.5) withPYTHONPATHpointed at this branch; I checked thatgraphify.watchwas imported from this branch. The Linux runs useduv runin WSL (CPython 3.10.12, separate venv).Graphify-specific checklist
_rebuild_lock).