Skip to content

tools: mutant-run keeps a lost daemon and one copy dir - #189

Merged
midagedev merged 2 commits into
mainfrom
perf-mutrun
Oct 14, 2026
Merged

midagedev merged 2 commits into
mainfrom
perf-mutrun

Conversation

@midagedev

Copy link
Copy Markdown
Owner

Summary

  • tools/mutant-run.sh treats a gate client exit of 84 as LOST-DAEMON: its own count, not a kill and not RED. The run line prints python3 tools/boxq.py attach sNNN when the log names job sNNN.
  • --copy DIR holds a flock on that directory until the process exits, so a second run of the same directory is refused by name.
  • The same change adds --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-test exits 0. The new cases failed first: rc 84 was counted as a kill, and a second --copy of a held directory ran. Both pass after the change.

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.
@github-actions github-actions Bot added the tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo label Oct 14, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Comment thread tools/mutant-run.sh
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")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refuse / before cleanup can operate across the filesystem.

Suggested change
COPY=$(phys_abs "$COPY")
COPY=$(phys_abs "$COPY")
[ "$COPY" != / ] || usage "--copy / contains the tree $ROOT"

Comment thread tools/mutant-run.sh
.git | .git/* | target | target/* | .mutant-run.lock) continue ;;
esac
if [ -d "$f" ] && [ ! -L "$f" ]; then continue; fi
printf '%s\n' "$rel" >> "$OUT/copy.dest"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A newline in an existing destination path can create a ../victim cleanup record and delete outside DIR.

Suggested change
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"

Comment thread tools/mutant-run.sh Outdated
: > "$keep"
while IFS= read -r -d '' f; do
case "$f" in
'' | target | target/* | .git | .git/*) continue ;;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copying different lock-file contents replaces the locked inode and lets a second runner enter DIR.

Suggested change
'' | target | target/* | .git | .git/*) continue ;;
'' | target | target/* | .git | .git/* | .mutant-run.lock) continue ;;

Comment thread tools/mutant-run.sh Outdated

# 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; }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reuse logline as the owner of the DIR suffix (R14).

Suggested change
logerr() { if [ -n "${COPY:-}" ]; then echo "$1 dir=$COPY" >&2; else echo "$1" >&2; fi; }
logerr() { logline "$1" >&2; }

Comment thread tools/mutant-run.sh Outdated
Comment on lines +687 to +691
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reuse logline as the owner of the DIR suffix (R14).

Suggested change
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]>

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the last review:

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant