Repository navigation
fix(gateway-lock): take the read-side lock-file probe shared - #22188
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing to check. [DESIGN-REVIEWED] a256102 Description read[DESCRIPTION-READ] 886ad07ddd0bed158d25235a338e6f456a7656823be0d78a0477c722d207cfef That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing to check. What this change shipsInventory (4 items) — 4 justifiedIntent: let
[FIRST-PRINCIPLES-REVIEWED] a256102 Description read[DESCRIPTION-READ] a303b38ce2861961a058cb44b9256c6646a9b937b43e5ccc67371be46f0eb9f6 That sha256 names the PR description this verdict read. Recompute it with |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
bolichen97
left a comment
There was a problem hiding this comment.
Reviewed head ba2459d. The change looks correct to me and I have no findings.
What I checked:
_lock_is_heldis the firsttry_acquire_lockcall inlock_holder, so the new overlap test parks on the lock file probe, not the home anchor, and twoLOCK_SHprobes on separate descriptors both succeed while the gateway'sLOCK_EXstill refuses them.- The read-only fallback descriptor and the NFS record-lock case both still work: a shared record lock needs only read access.
- The gateway's own
acquire()race window is unchanged, as stated in the description. - This matches the shared anchor probe from #21192, and main has not touched this function since.
- Linked issue #21194 is tier T1; no path is on the security denylist.
Why I am not approving yet: the Harness Parity Gate is red on main itself (a stale claude member-capabilities allowlist row, unrelated to this change), so the Fast Gate failed here and the backend, lint and coverage jobs were skipped. This PR's tests have not run in CI. Once the main fix (#22178 or #22186) lands, please rebase or re-run; I will approve when readiness: passed is on the new head.
Optional nit: one docstring line in _open_probe_descriptor ("read-only descriptor instead, which the shared probe locks as well. Windows opens read-only through") runs past 100 columns; rewrapping it would keep the paragraph consistent.
|
Red on this head is main's, not this PR's: Harness Parity Gate fails with |
|
macOS shard 3 red on this head (job 118129280736) is main's too: |
ba2459d to
a256102
Compare
bolichen97
left a comment
There was a problem hiding this comment.
Approving head a256102.
This head is a rebase onto current main; the patch to gateway_lock.py and its test is identical to the revision I reviewed earlier, so my earlier read still holds: the read-side probe takes LOCK_SH, two concurrent probes no longer collide, the gateway's LOCK_EX still refuses them, and the read-only and NFS fallback paths keep working.
What was blocking before is resolved: main's Harness Parity red is fixed on the new base, and the backend, lint and coverage jobs now ran on this head.
Gates checked on this head:
readiness: passed, PR Readiness green, every required check green.- Design, First Principles, Opus and GPT lanes report no blocking findings; UX skipped (no UI surface).
- Linked issue is tier T1; no file is on the security path denylist; base is main and the branch is mergeable.
One macOS backend shard is still re-running after a cancelled first attempt; it is not a required check and its cancellation was not a test failure.
Problem / Motivation
Goal: Two read-only lock checks on an idle home (
kirocrew stopbesidekirocrew perf sample) never read each other as the running gateway.gateway_lock.lock_holderprobesgateway.lockwith an exclusive try-lock.release()never deletes the file, so an idle home keeps a freegateway.lock. When two checks probe it at the same moment, the second one fails to take the lock and reads it as held. On Linux it can then name the first check's own pid as the holder (source="flock_owner"). Elsewhere it usually ends in an indeterminateLockProbeError.Why it matters
stop,restartand the perf probe act on the answer. A false holder can pointstopat a pid that is not a gateway, and an indeterminate answer makes a command refuse on a home where nothing runs. #21192 fixed the same collision one probe later, in the home-anchor probe.Not a goal
msvcrthas no shared lock, so its probe stays exclusive. The collision there is two syscalls wide and ends inLockProbeError, which the docstring now states.acquire(). Its exclusive attempt can meet a reader's probe exactly as it did before; that window is unchanged.What changed (motivation → approach → change)
Two readers collided because each took the lock file exclusive. A shared lock is refused only by an exclusive hold, and the gateway holds
gateway.lockexclusive for its whole life. So a shared probe still sees a running gateway as held, while two probes on a free file both get it._lock_is_heldinsrc/kiro_crew/gateway_lock.pynow callstry_acquire_lock(fd, exclusive=False):LOCK_SH|LOCK_NBon POSIX, unchanged on Windows. Its docstring states what a Windows collision reads as._open_probe_descriptor's docstring is re-derived: a shared record lock needs only read access, so the read-write open is kept for the FIFO and lease-break reasons, not the lock.Backwards compatibility
Compatible: a held lock still reads as held, and a free one as free; only two concurrent readers change, from a false holder to nobody.
Removes nothing: the same probe runs, with a weaker lock mode that every holder still refuses.
Tests
test_two_overlapping_probes_of_a_free_lock_file_both_read_nobody: two threads calllock_holderon a home with a freegateway.lock, each keeping its lock-file probe until the other has probed. Both answer nobody, with no error. Red onorigin/main(LockProbeError: ... no live holder pid can be established), green here. Skipped wherefcntlis missing.test_the_shared_lock_file_probe_still_reads_a_held_lock_as_held: a realGatewayLock.acquire()holds the file;_lock_is_heldon a second descriptor reads True. Runs on every platform.test/test_gateway_lock.pypasses in a seeded shuffled order (87 passed, 3 skipped).Manual verification
N/A — unit coverage sufficient: the new test reproduces the collision with two real descriptors and real
flockcalls.Related Issues
Closes #21194
Pattern harvest
Rule candidate: review-prompt
Pattern: a non-destructive "is it held?" probe takes an exclusive lock when a shared one would be refused by the same holders.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)