Repository navigation
tools: mutant-run keeps a lost daemon and one copy dir - #189
Conversation
A gate client that exits 84 is LOST-DAEMON, its own count, not a kill and not RED, and the line prints the attach command for the job the log names. --copy holds a flock on that directory so a second run is refused by name. The runner also grows --expect, --clean first, and the copy directory the flock guards.
There was a problem hiding this comment.
Verdict: MUST_FIX: Copy cleanup can delete files outside DIR, and copying the lock file can admit concurrent runners.
Must fix
1. Refuse the filesystem root as a copy destination
tools/mutant-run.sh:594 Kind A: with COPY=/, the ancestor pattern becomes //* and does not match the source tree. The output-directory guard also misses this case. If permissions allow lock creation and git init in /, sync reaches the cleanup at line 470, where paths such as ///fixture/victim delete files across the filesystem.
Reject / before sync; source restoration cannot recover those files. Add after COPY is canonicalized:
[ "$COPY" != / ] || usage "--copy / contains the tree $ROOT"2. Reject newlines in existing destination paths
tools/mutant-run.sh:466 Kind A: an existing DIR/$'junk\n..'/victim becomes two cleanup records: junk and ../victim. If those records are absent from the source list, the removal loop at line 470 deletes the sibling victim outside DIR. The source-path newline check does not cover destination entries.
Reject the path before cleanup; source backups do not cover sibling files. Replace this line with:
case "$rel" in *$'\n'*) usage "--copy refuses an existing path that contains a newline" ;; esac
printf '%s\n' "$rel" >> "$OUT/copy.dest"3. Exclude the lock file from the source list
tools/mutant-run.sh:444 Kind A: a tracked or non-ignored source .mutant-run.lock with nonempty contents enters the rsync list. After fd 9 locks the new destination's empty lock file at lines 626–627, rsync at line 455 replaces that file with a new inode. A second runner can lock the replacement and enter the same DIR while the first still runs.
Exclude this metadata before copying so concurrent runs cannot mix mutations and restores. Replace the exclusion arm with:
'' | target | target/* | .git | .git/* | .mutant-run.lock) continue ;;4. Keep directory suffix formatting in logline
tools/mutant-run.sh:384 and tools/mutant-run.sh:687 repeat the DIR formatting already owned by tools/mutant-run.sh:383 (R14, kind B). One output contract has three implementations.
Reuse the existing owner while these paths are together. Replace logerr with:
logerr() { logline "$1" >&2; }Replace lines 687–691 in run_gate with:
logline "== $run attempt $try $(date +%H:%M:%S)" >> "$OUT/$run.log"Checked
Duplicates: confirmed the three DIR-formatting implementations in item 4; the fix reuses logline and removes branches.
Complexity: only shell code changed; no Rust complexity results.
Silent failure: traced destination records to rm and lock setup to rsync.
Tests: original and suggested scripts pass bash -n. In-memory assertions confirmed the root and newline failures and their guards. Both logging replacements preserve output and streams with and without COPY. All five inline replacements cover added lines.
Gates: no thresholds changed.
Escape catalog: C1–C4 do not change these classifications; no ledger lessons are in force.
Notes
Dryer and crapper did not run because no Rust file changed.
The full self-test was not run because it writes temporary fixtures.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
| case "$OUT/" in "$ROOT"/*) usage "--out $OUT is inside the tree $ROOT, which box.sh syncs" ;; esac | ||
| if [ -n "$COPY" ]; then | ||
| if [ -e "$COPY" ] && [ ! -d "$COPY" ]; then usage "--copy $COPY is not a directory"; fi | ||
| COPY=$(phys_abs "$COPY") |
There was a problem hiding this comment.
Refuse / before cleanup can operate across the filesystem.
| COPY=$(phys_abs "$COPY") | |
| COPY=$(phys_abs "$COPY") | |
| [ "$COPY" != / ] || usage "--copy / contains the tree $ROOT" |
| .git | .git/* | target | target/* | .mutant-run.lock) continue ;; | ||
| esac | ||
| if [ -d "$f" ] && [ ! -L "$f" ]; then continue; fi | ||
| printf '%s\n' "$rel" >> "$OUT/copy.dest" |
There was a problem hiding this comment.
A newline in an existing destination path can create a ../victim cleanup record and delete outside DIR.
| printf '%s\n' "$rel" >> "$OUT/copy.dest" | |
| case "$rel" in *$'\n'*) usage "--copy refuses an existing path that contains a newline" ;; esac | |
| printf '%s\n' "$rel" >> "$OUT/copy.dest" |
| : > "$keep" | ||
| while IFS= read -r -d '' f; do | ||
| case "$f" in | ||
| '' | target | target/* | .git | .git/*) continue ;; |
There was a problem hiding this comment.
Copying different lock-file contents replaces the locked inode and lets a second runner enter DIR.
| '' | target | target/* | .git | .git/*) continue ;; | |
| '' | target | target/* | .git | .git/* | .mutant-run.lock) continue ;; |
|
|
||
| # A line this runner writes. With --copy it names DIR; without, it is echo. | ||
| logline() { if [ -n "${COPY:-}" ]; then echo "$1 dir=$COPY"; else echo "$1"; fi; } | ||
| logerr() { if [ -n "${COPY:-}" ]; then echo "$1 dir=$COPY" >&2; else echo "$1" >&2; fi; } |
There was a problem hiding this comment.
Reuse logline as the owner of the DIR suffix (R14).
| logerr() { if [ -n "${COPY:-}" ]; then echo "$1 dir=$COPY" >&2; else echo "$1" >&2; fi; } | |
| logerr() { logline "$1" >&2; } |
| if [ -n "$COPY" ]; then | ||
| echo "== $run attempt $try $(date +%H:%M:%S) dir=$COPY" >> "$OUT/$run.log" | ||
| else | ||
| echo "== $run attempt $try $(date +%H:%M:%S)" >> "$OUT/$run.log" | ||
| fi |
There was a problem hiding this comment.
Reuse logline as the owner of the DIR suffix (R14).
| if [ -n "$COPY" ]; then | |
| echo "== $run attempt $try $(date +%H:%M:%S) dir=$COPY" >> "$OUT/$run.log" | |
| else | |
| echo "== $run attempt $try $(date +%H:%M:%S)" >> "$OUT/$run.log" | |
| fi | |
| logline "== $run attempt $try $(date +%H:%M:%S)" >> "$OUT/$run.log" |
…out of the copy, and takes the fixture's rc 84 from boxq Shingler #189: --copy / is refused before the sync; an existing DIR path with a newline is refused before cleanup; .mutant-run.lock never enters the rsync list; logerr and run_gate write through logline. The self-test's fake gate gets its 84 from tools/boxq.py attach over a failing ssh stub, so boxq.py stays the code's one producer (boxq-check codes-check). Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Since the last review:
- Root destination refusal: fixed at tools/mutant-run.sh:591.
- Destination newline rejection: fixed at tools/mutant-run.sh:467.
- Source lock exclusion: fixed at tools/mutant-run.sh:445.
- Directory suffix duplication: fixed in logerr:385 and run_gate:690; both reuse logline.
Verdict: CLEAN: All four earlier must-fix items are resolved; the remaining regression-test request is advisory.
Non-blocking
⚠ Add regression cases for the copy fixes: tools/mutant-run.sh:467. The self-test never exercises root refusal, destination newlines, or copying a nonempty source lock file.
Add refusal cases for the first two. For the lock, copy a nonempty source lock while one runner remains active, then assert that a second runner is refused.
The existing contention case takes the destination lock before copying starts, so it cannot catch replacement of that lock during a copy.
Checked
Duplicates: no new functions, types or constants; both logging paths reuse logline.
Complexity: no Rust functions changed; the new shell branches reject invalid paths.
Silent failure: the client and gate exit statuses are captured immediately; rc 84 reaches LOST-DAEMON and sets a failing result.
Tests: bash -n passed. The rc-84 self-test asserts LOST-DAEMON, the attach command and a failing result; those assertions would reject treating 84 as a kill.
Gates: no thresholds moved or tests removed.
Escape catalog: C1–C4 checked; no matching defect in the new commits. The heredoc remains quoted.
Notes
Dryer and crapper did not run because no Rust file changed.
The full self-test was not run because it writes temporary fixtures; validation used static code checks and bash syntax checking.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
Summary
tools/mutant-run.shtreats a gate client exit of 84 asLOST-DAEMON: its own count, not a kill and notRED. The run line printspython3 tools/boxq.py attach sNNNwhen the log namesjob sNNN.--copy DIRholds a flock on that directory until the process exits, so a second run of the same directory is refused by name.--expect NAME=ERE,--clean first, and the copy directory that flock guards. Mutants still run in that directory; the tree the runner was started in is not written.Test
bash tools/mutant-run.sh --self-testexits 0. The new cases failed first: rc 84 was counted as a kill, and a second--copyof a held directory ran. Both pass after the change.