Skip to content

fix(scripts): decide the ctl lock by a noclobber pid file, not by mkdir's exit status - #23

Merged
agent-kit-startup merged 6 commits into
mainfrom
test/concurrent-start-evidence
Nov 30, 2026
Merged

agent-kit-startup merged 6 commits into
mainfrom
test/concurrent-start-evidence

Conversation

@agent-kit-startup

@agent-kit-startup agent-kit-startup commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

test_concurrent_starts_run_one_copy (and its stale-lock variant) started one copy too many now and then on ubuntu-latest, never locally. Each concurrent start now runs under sh -x with its output kept, and a failure prints the three traces, the pidfiles, the lock, the children and copies the fake recorded, the copies' output and the script's status verdict.

The dumps show a lock breach, not a liveness misjudgement. In an Ubuntu 26.04 container, two calls each took $RUN/board.lock with one plain mkdir (no wait, no stale check), both started a copy, and the first call's release found the other's pid in the lock ([ <pid B> <start> = <pid A> <start> ]). On a hosted runner (stale-lock variant), two calls both "created" $RUN/board.lock.reclaim, both removed the stale lock, and the second rmdir of the reclaim directory failed with "No such file or directory".

Cause: ubuntu-latest is now Ubuntu 26.04, whose default mkdir is uutils coreutils 0.10.0 (printed on the runner). It reports success to a call whose directory a concurrent call created a moment before. In a 3-way race on a fresh path, more than one call succeeded in 830 of 2000 rounds; GNU mkdir (24.04, or gnumkdir on 26.04) in 0 of 2000. The lock relied on mkdir being exclusive. Every failing hosted run checked, the first one included, ran on the 26.04 image.

Fix: a call holds $LOCK (and $LOCK.reclaim) only when it also creates the pid file inside under noclobber (set -C), which dash opens with O_CREAT|O_EXCL; mkdir success stays a precondition, so a pidless lock directory is still respected. A call that loses leaves the directory alone, and release removes the file, then the directory, never recursively. On-disk layout is unchanged (<pid> <start> in $LOCK/pid); the lock section stays identical in the three scripts. A new test runs the concurrent starts with a mkdir that always reports success. Probe of the new primitive (mkdir, then noclobber file): no round with more than one winner: 0 of 2000 on 26.04 dash with uutils, 0 of 2000 on 24.04 dash with GNU, 0 of 1000 with bash as sh.

Reproduction, Ubuntu 26.04 container (dash, uutils mkdir, --cpus 2), 40 rounds of the concurrent tests per Python:

  • before: Python 3.10, 6 failures in 240 test runs; Python 3.13, 9 in 240 (both the plain and the stale-lock variants, all three scripts)
  • after: 0 in 240 for each Python, plus 0 in 120 runs of the new test for each
  • Ubuntu 24.04 (GNU mkdir), before the fix: 0 failures in 1200 runs of the plain concurrent test (both Pythons, --cpus 2 and two pinned CPUs).

The failures are not tied to Python 3.13: only 3.13 happened to fail on hosted runners (1 of 20 repeated rounds against 0 of 20 for 3.10), and 3.10 fails as well in the container. CI now sets fail-fast: false on the test matrix so both legs always finish. Which mkdir a Termux device ships was not checked here; the fix does not depend on it.

Each concurrent start runs under sh -x with its output kept; when the test
fails it prints the three traces with exit codes and timings, the pidfiles,
the lock directory and its pid file, the children file, the copies the fake
recorded and the test's processes. The fake now also records its own pid.

ci: let both Python legs finish (fail-fast: false), so a failure on one leg
no longer hides the result of the other.
…ir's exit status

uutils mkdir, the default mkdir on Ubuntu 26.04 (ubuntu-latest), reports
success to a call whose directory a concurrent call created a moment
before: in a 3-way race on a fresh path, more than one call succeeded in
830 of 2000 rounds (GNU mkdir: 0). Two concurrent starts then both held
the lock and both started a copy.

A call now holds $LOCK (and $LOCK.reclaim) only when it also creates the
pid file inside under noclobber, which the shell opens with O_EXCL. A call
that loses leaves the directory alone, and release removes the file, then
the directory, never recursively.
@agent-kit-startup agent-kit-startup changed the title test(ctl): trace concurrent starts and dump the evidence when one copy too many starts fix(scripts): decide the ctl lock by a noclobber pid file, not by mkdir's exit status Nov 30, 2026
@agent-kit-startup
agent-kit-startup merged commit a10fa00 into main Nov 30, 2026
3 checks passed
@agent-kit-startup
agent-kit-startup deleted the test/concurrent-start-evidence branch November 30, 2026 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant