Repository navigation
Lock the mandate record with flock (work-system 1.28.4, pr-flow 1.8.2) - #95
Merged
Merged
Conversation
gering
force-pushed
the
task/flock-round-lock
branch
from
October 27, 2026 14:01
f926fd1 to
0ffb351
Compare
- Replace the mkdir lock with flock(2) on .MANDATE.lock: breaking an "abandoned" mkdir lock could delete a live booker's lock (ABA), so a concurrent round booking was lost (test_mandate CI flake) - The kernel frees the lock when its owner dies; the pid/age staleness rule is gone. python3 takes the lock (macOS has no flock(1)); without it a write is refused with exit 4 - git calls close the lock descriptor so no daemon can inherit it - An old lock directory is refused with the rm -rf to run - A filesystem that refuses flock is named, not reported as contention - Every writer re-ensures the .MANDATE.* exclude; close-request counts the persistent .MANDATE.lock as a lane file, so the zero-loss auto-close still applies - Exit-4 docs (continue, pr-flow REVIEW-ROUTING) match the new causes; CHANGELOG asks to reload 1.28.2 sessions before a lane books again - Tests: live holder, killed holder, no fd leak into git, symlink/FIFO/ old-dir refusals, no python3, refused flock, restored exclude, lock file exempt in close-request Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gering
force-pushed
the
task/flock-round-lock
branch
from
October 28, 2026 22:43
0ffb351 to
42928e9
Compare
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.
Why
test_mandate.py's concurrentroundtest flaked in CI: all 8 bookings reported success, yet one was lost. The cause is a real race in the record lock, which has been onmainsince #91. Breaking an "abandoned"mkdirlock is ABA:kill -0on A's pid fails, so B judges the lock stale and deletes it. That lock is now C's.A directory cannot be deleted conditionally, so no staleness rule fixes this.
What
mandate.shlocks the record writers (round,reviewed,fixed,acknowledged) withflock(2)on.MANDATE.lock. Bash holds fd 9 andpython3 -Ilocks it; this is the samefcntl.flockpattern asfollowups.py. macOS has noflock(1).gitis wrapped to close fd 9, so a daemon git spawns (fsmonitor) cannot inherit and hold the lock..MANDATE.*exclude covers it.Evidence
16 concurrent bookings per run: 1 of 40 runs lost a booking on 1.28.2, 0 of 160 after this change.
Tests
New tests cover a live holder (waited for, then exit 4, nothing booked), a holder killed with
kill -9(freed with no rule), and the fd 9 leak into git. The leak test uses a PATH shim; it fails with the wrapper removed. Further tests cover the refusals for an old directory, a symlink (not followed) and a FIFO (no hang), and for no python3. The obsoletemkdirshim and stale-pid tests are removed.check-structure.pypasses locally.Version 1.28.4, because #93 holds 1.28.3.
🤖 Generated with Claude Code
https://claude.ai/code/session_013pcrPYhUMWQ1gkrrqtSmic