Repository navigation
Make the lock tests and one review test pass on macOS - #205
Merged
Merged
Conversation
On the bash 3.2 that macOS ships, `exec 200>>file` leaves fd 200 pointing at its old file when the fd is already open, and still reports success. A process that inherited a held lock, such as with-lock.sh started by run.sh while it holds its run slot, then flocked the holder's own open file description, was granted it, and returned 0 without contending for the lock it asked for. bot_acquire_lock now closes the fd before opening the lock file, so the open always makes a new open file description. This fixes TestRunLocking::test_acquires_and_blocks_a_second_holder, test_one_slot_behaves_exactly_like_the_single_lock_it_replaced and test_no_count_means_one_slot on macOS.
The stand-in claude in TestReviewRequestQueue counts the entries of the session's gh config directory with `wc -l`. BSD wc pads the count with spaces, so on macOS the recorded line read `GH_CONFIG_DIR= 0-entries` and test_the_session_holds_no_github_credential failed. The stub now strips the spaces; the assertion is unchanged.
5 of 8 tasks
bbondy
approved these changes
Oct 31, 2026
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.
User impact: on macOS, a job run under
with-lock.shby a process that already holds a lock, asrun.shdoes for the PRD sync and the in-progress sweep, is now turned away when a second copy is running; before, both ran. Four tests that failed on every macOS checkout now pass.The problem
On a Mac, a job that is supposed to run one at a time can run twice at once. If the process that starts it already holds a lock, the job is told it has its own lock without ever contending for it.
run.shholds its run slot while it starts the PRD sync and the in-progress sweep, so those are in that position. Three tests intests/test_scripts.pycatch this on a Mac, and a fourth fails there because awccount comes back padded with spaces; Linux CI sees neither.Reproduce
On a Mac (
/bin/bashis 3.2, noflock(1)installed, soscripts/lib/lock.shuses its Python backend), from the root of a checkout:/tmp/demo-holder.sh. It takes a lock the wayrun.shdoes, then starts twowith-lock.shjobs of the same name two seconds apart:/bin/bash /tmp/demo-holder.sh "$PWD".Observed on the parent commit: job B runs while job A is still running.
Expected, and observed with this change: job B is turned away.
python -m pytest tests/test_scripts.py -k "TestRunLocking or test_the_session_holds_no_github_credential"fails 4 tests on the parent commit (second=0wheresecond=1is expected in three,GH_CONFIG_DIR= 0-entrieswhereGH_CONFIG_DIR=0-entriesis expected in one) and passes 12 here.The fix
bot_acquire_lockopens its lock file withexec 200>>file. When fd 200 is already open, the bash 3.2 that macOS ships leaves it pointing at the old file and reports success, so a process that inherited a held lock re-locked its parent's open file description and was granted it. The function now closes fd 200 first, so the open always makes a new description that has to contend with the holder.The review-request test's stand-in
claudecounted a config directory's entries withwc -l, which pads with spaces on macOS (0). It now strips them withtr -d " ". The assertion is unchanged.Which redirections bash 3.2 ignores
exec N>>Brun afterexec N>>A, then asking which file fd N points at:/bin/bash3.2.57The exit status is 0 in every case.
exec 200>&-followed byexec 200>>Bdoes reach B in 3.2, which is why closing first works.Test plan
python -m pytest tests/test_scripts.py -k "TestRunLocking or test_the_session_holds_no_github_credential"— 4 failed onorigin/master, 12 passed herescripts/lib/lock.shreverted — the 3 lock tests fail; with only the test stub reverted — the credential test failsPATH=/opt/homebrew/bin:$PATH python -m pytest tests/test_scripts.py tests/test_concurrency.py -k "TestRunLocking or test_the_session_holds_no_github_credential or Lock or lock"(bash 5.3 first onPATH) — 49 passed with this change and 49 passed withlock.shrevertedpython -m pytest tests/— 1505 passed, 4 skippedruff check .andruff format --check .— passedmake check-reviewdog— no findings (opengrep and pip-audit ran unsandboxed becauselandrunis not installed here)