install.sh: a holder's .stage folder can vanish before its rename when a waiter claims the lock (flaky install-binary test)
scripts/install-binary.test.ts › "leaves the lock to a waiter that claims it while the holder removes it, and both succeed" failed once in bun run check fast on a loaded host, then passed 36/36 when the file was run again alone.
The first run (the holder) failed, not the waiter:
mv: cannot stat '/tmp/ovis-install-binary-…/home/.local/share/ovis/releases/.stage-pytqcT': No such file or directory
Ovis: could not move the checked release into place; nothing was changed
expect(one.code, one.out).toBe(0) // Received: 1 (scripts/install-binary.test.ts:307)
So the holder's own staging folder was gone when it renamed it. That points at a sweep (the waiter's, or the holder's own release step) removing a .stage-* folder that a live install still uses. If so, two overlapping install.sh runs could fail for a user, not only in the test.
Seen on branch feat/sidebar-account-pcs (it touches no installer file), on top of origin/main 1e9cc13 + the step1-recheck branch.
I tried the exact “leaves the lock to a waiter that claims it while the holder removes it, and both succeed” case on main at 6946dcb01d78275ac041f088c0b8842921e7c06c. It passed 30/30 on the host and 40/40 in the CI runner image with HERDR_TEST_MODE=unit (Bun 1.4.4). Each run used the test's disposable home and local release fixture.
Neither run lost a .stage-* directory. The installer changes since the reported base did not change the lock claim/drop or staging sweep, so this does not establish that the race is fixed. Leaving the issue open.
Checked again on main at 52791b409, this time forcing the order instead of hoping for it. With named pipes (no sleeps), the waiter contended just before the holder renamed its live .stage-* folder, then claimed the lock while the holder was still removing its retired lock folder. Both installs succeeded in 5/5 runs, and scripts/install-binary.test.ts passed 36/36.
From the code: the only sweep that can remove another run's .stage-* is the start-up sweep in install_binary (rm -rf "$OVIS_HOME"/releases/.stage-*), which runs only after install_lock succeeds. The holder renames its stage before install_unlock, and install_lock_drop renames the lock folder before deleting it, so a waiter cannot hold the lock while the holder's stage is still unrenamed; a fresh holder's lock is never judged stale (kill -0 on its pid). The old-release sweep skips hidden folders.
Together with the earlier 30/30 (host) and 40/40 (runner image) runs, the single failure does not reproduce and the current code leaves no path to it. Closing; if the test fails again, please add the run to #4026 (CI flakes) with its log and the head it ran on.