Skip to content

tools: resolve replay lists before entering arm directories - #725

Merged
juliankang4 merged 8 commits into
midagedev:mainfrom
juliankang4:fix-tool-output-owner
Oct 23, 2026
Merged

juliankang4 merged 8 commits into
midagedev:mainfrom
juliankang4:fix-tool-output-owner

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

출력 폴더를 두 실행이 동시에 쓰면 로그와 결과가 서로 덮어써지고 실패한 검사가 통과로 보일 수 있어서, 폴더마다 소유자를 한 명만 두도록 도구를 고쳤습니다.

Part of #565. Tracked in #699.

What and why

Three tools write their results into an output directory that two runs could end up sharing, and one of them also loses its input list. This PR gives each run its own output directory and keeps each run's result out of reach of other runs.

  • tools/contrib-check.sh named its log directory after the second it started in. Two runs in the same second shared one plan.tsv, so a run that asked for a deliberately failing unit (CONTRIB_INJECT_FAIL=1) could have its plan replaced by the other run and report success. The directory now comes from mktemp -d, so it is target/contrib-check/<time>.<unique>/.
  • tools/gate-batch.sh only refused an --out directory once run.log existed. Two batches started together could both get past that check before either wrote the file, then overwrite each other's logs and claims. The default directory has the same race when two batches start in one second, so it also comes from mktemp -d now. An explicit --out is reserved through a new output_dir_take and output_dir_drop pair in tools/nightly/units.sh, which takes the directory with an atomic mkdir of .run-owner and releases it on exit. A leftover marker from a killed run is refused, not guessed stale.
  • tools/batch-replay.sh judged each arm by reading $OUT/<arm>.rc, a public file in a directory another invocation could write to. If its own arm had ended badly, a success rc file from another run could make it report success. It now keeps its verdict in its private work directory and only copies the receipts to --out for the reader. It also reserves --out through the same owner pair and refuses an output that already holds an arm, a log or a receipt, including a dangling symlink.
  • tools/batch-replay.sh accepted a relative LIST path, checked it, then changed into each arm's work directory, where the same relative path points somewhere else or nowhere. The list is now made absolute right after it is checked. The usage line and header comment now list --out DIR, which the script already accepted.

docs/contrib/local-check.md and the header comments describe the new log directory names.

The output owner lives in one place, tools/nightly/units.sh, and both gate-batch.sh and batch-replay.sh call it. tools/ref/lease.sh keeps its own temporary directory because that one only captures output and is not an output namespace.

Release notes: Fixed: contrib-check, gate-batch and batch-replay no longer share output directories between concurrent runs, and batch-replay accepts a relative list path.

Code shape

  • No second copy. Output directory ownership is one pair of functions in tools/nightly/units.sh, called by both runners.
  • Model code holds only architecture facts. No model code is touched.
  • Dead code is gone. Nothing was left unused; the old <time>-only directory and the public .rc verdict path are removed.
  • No silent failure. Creating, taking, finding existing output and releasing the directory each return a named error (status 73 for a refused or occupied directory); the replay verdict comes only from its private state.
  • Comments state what is true now. The touched comments and the contributor doc describe the current directory layout.
  • No relaxed gate. No band, tolerance, lint or existing test was moved or removed.
  • cargo fmt and cargo clippy are clean on what I touched: not applicable, the diff has no Rust files. bash -n and ShellCheck results are below.

Duplication found or removed (path:line), or "none": none.

What I ran

Environment: an x86_64 Linux host, bash, python3. The change is host shell tooling with no GPU, model or kernel path, so no GPU gate applies. tools/nightly/selftest.sh gained a --output-only mode that runs the real directory-allocation and receipt blocks from the three scripts and exercises them with two concurrent runs, an existing output, a dangling symlink and an arm that ended badly beside foreign rc files.

Before the fix, on the base tree:

OUTPUT_TEST_ROOT="$NR_BASE_WT" bash tools/nightly/selftest.sh --self-test --output-only
output-owner self-test: 11 of 20 ok

Nine of them fail there: the same-second contrib-check requested failure, the automatic gate-batch directory, the single owner for gate-batch and for batch-replay, both existing-output refusals, both dangling-symlink refusals, the arm that ended badly next to foreign rc files, and the relative list path.

After the fix, on this head:

bash tools/nightly/selftest.sh --self-test --output-only
output-owner self-test: 20 of 20 ok
bash -n tools/contrib-check.sh tools/gate-batch.sh tools/batch-replay.sh tools/nightly/units.sh tools/nightly/selftest.sh && git diff --check
output-owner host checks complete

The same self-test also covers the gaps the touched scripts already had: an injected failure in the gate-batch teardown must reach the exit code, and batch-replay must keep its resource table and its budget detection for both a current and an older base. Each guard is also tested against a copy with that branch removed, and the test catches the removal.

shellcheck -x -S warning tools/contrib-check.sh tools/gate-batch.sh tools/batch-replay.sh tools/nightly/units.sh tools/nightly/selftest.sh

ShellCheck 0.11.0 reports five warnings (SC2163, SC1010 twice, SC2034 twice) on the base tree and the same five on this head. Compared by file, source line, caret, code and message, ignoring line numbers in the headers, this PR adds none.

I did not run the full contrib-check or the workspace cargo checks, because the diff touches no Rust.

Hardware (if the change is for a machine)

Not applicable. The change is host shell tooling only.

What I ran into

This does not block the PR. The five ShellCheck warnings above exist on main already and are unchanged here.

AI help

AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.

@github-actions github-actions Bot added documentation Improvements or additions to documentation tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo labels Oct 23, 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: CLEAN: The supported finding is a non-blocking gap in cleanup-test coverage.

Non-blocking

⚠ Test the final output-owner cleanup: tools/nightly/selftest.sh:62 extracts only the allocation block and its initial EXIT trap.
The final tools/gate-batch.sh:6433 trap is never executed by these tests; removing its output_dir_drop call cannot affect their results.
Exercise that trap on normal completion and teardown failure. Match the PR body's 20/20 claim to the resulting run; the current output-only suite contains 18 checks.

Checked

Duplicates: gate-batch and batch-replay share output_dir_take/output_dir_drop in tools/nightly/units.sh.
Complexity: no Rust code changed.
Silent failure: allocation errors return nonzero; replay verdicts consume private arm receipts.
Tests: static inspection confirms that the final cleanup mutant leaves the extracted test fragments unchanged. Tests were not rerun during validation.
Gates: no existing pins, thresholds or cases moved or removed.
Escape catalog: no C1–C4 match in the reviewed changes.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@juliankang4

Copy link
Copy Markdown
Collaborator Author

The review is done and the contribution check passed, so I'm merging this.

@juliankang4
juliankang4 merged commit 561daaa into midagedev:main Oct 23, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation 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