Repository navigation
Crash/reboot resilience + atomic O_EXCL lock (fix WSL2 mkdir non-atomicity) - #48
owenzhang26-sys wants to merge 2 commits into
Conversation
…ocal.json in dirty check fm-spawn waits specifically for a */.treehouse/* cwd rather than any change off the project dir, so a transient default-cwd reading is never misrecorded as the worktree. fm-teardown's dirty check ignores the tracked .claude/settings.local.json that the turn-end hook modifies, so teardown is not blocked by firstmate's own hook.
Crash/reboot resilience: a WSL VM teardown (host sleep, idle timeout, Windows Update reboot) kills tmux and every crewmate at once and nothing relaunched firstmate afterward. systemd/firstmate.service runs bin/fm-resume.sh as a watchdog that recreates the persistent firstmate tmux session on boot and self-heals if it dies (KillMode=process, so stopping the unit never kills a live firstmate). bin/fm-install-autostart.sh installs/removes it. Pair with ~/.wslconfig vmIdleTimeout=-1 to prevent the idle teardown in the first place. Lock correctness: the wake-queue/singleton lock used mkdir as its atomic primitive, but mkdir is NOT atomic on WSL2's filesystem (verified: 4 concurrent mkdir calls succeeded on one path in a barrier race), so the lock double-granted under contention - duplicate watchers, raced wake-queue drains, flaky tests. Replaced with an O_EXCL (noclobber) create, atomic on Linux, WSL2, and macOS, which also writes the holder pid in the same step (no empty-pid window). Dead holders are reclaimed in one call; a live holder's lock is never stolen. Tests: fm-lock-exclusivity (canonical mutex probe + reclaim) and fm-resume (base-index-safe create + idempotency) guard both fixes; the singleton-start test now polls for the invariant instead of a fixed sleep.
|
Thanks for the PR! This branch currently has a merge conflict with the base branch. When you get a chance, please rebase onto (or merge) the latest base branch, resolve the conflict, and push. After that, checks will re-run and the PR will get looked at again. Noted for firstmate#48 at |
|
Q6 polish applied: O1-O8 from the G6 cert report fixed in data/math-fish-q6-split/proof.tex, proof.pdf recompiled clean (9pp, ledger pinned p.1, zero em-dashes). O1/O7 mandatory gates satisfied. No verdict, derivation, or measurement changed; engine empty-half behavior untouched (routes to #63). Fix note: data/math-fish-q6-polish/report.md. |
PRR checklist
UI evidence (item 6): local-only screenshots of the real popup and page badge (stubbed chrome API, synthetic state) at 1280, 390 and 320 px are kept outside the repo with the firstmate task data ( |
Measurement note (from the task worker)
|
* Add private Lavish decision surface * Declare decision and upstream watch surfaces
…heck the publishing guards (kunchenguid#48) * feat(bin): give every new owner a private add-on at first setup and confirm the publishing guards bin/fm-addon.sh create makes the signed-in owner a private repository from a minimal starter, keeps it at projects/<repo> and writes config/addon; with no GitHub sign-in it stops with the sign-in steps. bin/fm-addon.sh guards confirms the user role, installs and confirms the pre-push leak check on the checkout and the add-on (new fm-leak-prepush.sh status), and starts config/leak-words. The first voyage now runs both before the first project, and the team and onboarding docs make the add-on the standard place for an owner's changes. * no-mistakes(review): Ask before creating the add-on; never count it as project * no-mistakes(review): Restore add-on project route; registry rebuild still skips it * no-mistakes(test): Treat skip-to-project requests as step 4 declines * no-mistakes(test): Gate first project on private add-on; fix leak hit * no-mistakes(document): Note add-on create, guards and first-project in docs
Why
A WSL VM teardown (host sleep, idle timeout, or a Windows Update reboot) kills tmux and every crewmate at once, and nothing relaunched firstmate after the VM came back — the fleet stayed dead until the captain reconnected. Separately, the test suite was intermittently flaky.
Crash/reboot resilience
systemd/firstmate.service+bin/fm-resume.sh— a watchdog recreates the persistentfirstmatetmux session on boot and self-heals if it dies.KillMode=processmeans stopping the unit never kills a live firstmate. Verified: restarts ~10s after a kill; survivor session untouched.bin/fm-install-autostart.sh—install/status/uninstall; fully reversible, never touches a running session.~/.wslconfigwithvmIdleTimeout=-1to prevent the idle teardown in the first place (needswsl --shutdownto apply).Lock correctness (root cause of the flakiness)
The wake-queue / watcher-singleton lock used
mkdiras its atomic primitive, butmkdiris not atomic on WSL2's filesystem — a 20-way barrier race produced up to 4 concurrentmkdirsuccesses on one path. The lock therefore double-granted under contention (duplicate watchers, raced wake-queue drains, flaky tests). A canonical mutex probe showed 4–8 double-grants per run.Replaced the primitive with an
O_EXCL(noclobber) create — atomic on Linux, WSL2, and macOS — which also writes the holder pid in the same step, eliminating the empty-pid window. Dead holders are reclaimed in a singletry_acquire(sofm-watch.shtakes over a crashed watcher); a live holder's lock is never stolen. Probe now reports 0 double-grants.Tests
tests/fm-lock-exclusivity.test.sh— canonical mutex probe + dead/live reclaim (guards the lock fix).tests/fm-resume.test.sh— base-index-safe session creation + idempotency (runs against an isolated tmux server).tests/fm-wake-queue.test.sh— singleton-start now polls for the invariant instead of a fixed sleep.Local CI green:
shellcheck bin/*.sh tests/*.sh, all 5 test files, and the repo invariants.Also included
fix(spawn,teardown): fm-spawn waits for a*/.treehouse/*cwd before recording the worktree; fm-teardown ignores the tracked.claude/settings.local.json(turn-end hook) in its dirty check.🤖 Generated with Claude Code