Repository navigation
test(file-lock): time the lock hand-off against a flat poll, not a fixed bound - #5488
Conversation
…xed bound The busy-lock throughput test failed on macOS CI (24.3 ms against an 8 ms bound) and twice in 22 loaded Windows runs, because it timed wall clock against an absolute limit on runners that overshoot short sleeps. - The test now times release-to-next-holder with the real poll and with a flat 20 ms poll in the same run, and asserts the flat run is at least 4 ms slower. Sleep overshoot adds about the same to both, so a margin holds where a ratio does not. 30 of 30 runs pass under 6 and 12 CPU burners. - The spent marker is gone: it bought no measurable speed and no test needed it. An unlocked entry is re-checked every poll and reaped after the turn. - An entry this user cannot check (another user's, or on NFS) stops counting as ahead once older than the lock timeout, so a dead one can no longer block everyone. It is never deleted, and at worst a live one loses its place, never exclusion. - The module docstring names the sub-millisecond window in which a request arriving as the lock comes free can beat one that is about to queue. - New tests cover the 20 ms poll cap and the dot-name skip in registry discovery.
|
Verdict: Approve The lock hand-off test that failed on slow macOS and loaded Windows runners now compares the real hand-off against a flat 20 ms poll in the same run, instead of using a fixed time limit. It should stop blocking unrelated PRs and still catches the regression it was written for. The lock changes look correct. An entry left by another user, or by NFS, can no longer block a lock forever. The unused "spent" marker is gone, and nothing in the queue's correctness depended on it. No blocking issues. One small note is in the details below. Real-world evidenceN/A: this changes internal lock code and tests, with no CLI, API, MCP or UI surface. No evidence bundle was produced. pytest isn't installed on this review runner, so I couldn't run the tests here. The verdict rests on static review plus the author's Windows runs under load (30 of 30) and their revert checks. 🔍 Technical detailsIssues found 🟢 A stale entry slows that lock for good ( Checked and fine
Strengths
|
… name them An entry this user cannot check (another user's, or on NFS) was aged by this machine's clock against the file server's mtime, so a client an hour behind blocked every waiter for an hour. Once aged out it was skipped silently, and since nobody can delete it the queue never emptied, so every later lock lost its fast path. - Age is now the server's time from both sides: the waiter's own entry mtime plus the monotonic time since it joined, against the stuck entry's mtime. Only a waiter that has no entry of its own, in a read-only folder, still uses this machine's clock. - An aged-out entry is logged once per process, naming the file and saying it can be deleted if no other user's GAIA is running. It stays in the timeout message's list, and the fast path looks past it. - The module docstring lists all three ways queue order can slip, without a timing claim.
…g-window slip A waiter polling past an aged-out queue entry now has a test that it is named exactly once: removing the dedupe made it warn 76 times without any test failing. The module docstring also notes that an entry written just after an arrival listed the queue can be overtaken, a window as long as a directory listing on NFS.
# Conflicts: # tests/unit/test_file_lock.py
|
The stale-entry note is handled: the fast path now looks past an entry that has aged out, so it no longer slows every later lock. The entry is also named in a warning once per process. |
The busy-lock throughput test from #5469 fails on slow or loaded runners. It failed macOS CI (24.3 ms against an 8 ms bound) and 2 of 22 loaded Windows runs, so it can block unrelated PRs. It now times a lock hand-off against a flat 20 ms poll in the same run, and asserts the margin rather than a fixed limit. It passed 30 of 30 runs on Windows under heavy CPU load and still fails when the fast hand-off is reverted. The same change fixes the lock's handling of queue entries this user can't check, such as another user's on NFS:
It also documents the three ways queue order can slip, and drops an unused "spent" marker.
Reproduced by
test_a_busy_lock_keeps_its_throughputon macOS CI (run 39573703043); its replacementtest_a_busy_lock_hands_off_far_faster_than_a_flat_pollpasses here and fails when the 1 ms poll is reverted to 20 ms. The skew bug is reproduced bytest_an_unchecked_entrys_age_ignores_this_machines_clock(client ±1 h); it fails against the previous head and passes here.Test plan
test_a_busy_lock_hands_off_far_faster_than_a_flat_poll30 of 30 under 6 CPU burners and 30 of 30 under 12 on Windows. Measured: real hand-off ~0.7–0.9 ms against ~10–14 ms with a flat poll.skew.py). One stale foreign entry costs 0.34 ms per uncontended lock against 0.31 ms clean (stalecost.py).python -m pytest tests/unit/test_file_lock.py tests/unit/test_concurrent_state_writes.py tests/unit/rag/ tests/test_rag.py tests/unit/test_hub_router.py tests/unit/test_hub_installer.py tests/unit/test_daemon_hub_routes.py tests/unit/test_skills_install_concurrency.py tests/unit/agents/test_registry_load_errors.py -n 4on Windows, with an isolatedGAIA_HOME. Everything passes except three tests that also fail on main in this environment (nopipin the venv; a registry test that ignoresGAIA_HOME).python util/lint.py: black, isort, flake8, pylint and the other checks pass. The tool-description check fails locally only, because it imports this machine's editable install from another checkout; CI's lint passed.🔍 Technical details
LOCK_TIMEOUT_SECONDS.test_an_earlier_entry_seen_before_its_owner_locked_it_still_countsstill guards that._poll_interval20 ms cap, and registry discovery skipping dot-named folders.list_installedalready had one.