Skip to content

tests: sj-vs-clef's own data directory, gate-bound's FIFO self-test and executable fixtures written in a child, so main's PR check passes - #557

Merged
juliankang4 merged 3 commits into
midagedev:mainfrom
juliankang4:fix-sj-vs-clef-self-test
Oct 20, 2026
Merged

juliankang4 merged 3 commits into
midagedev:mainfrom
juliankang4:fix-sj-vs-clef-self-test

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

main의 PR check(contrib-check t0)를 빨갛게 만들던 테스트 결함 세 가지를 함께 고칩니다. sj-vs-clef self-test는 자기 빈 데이터 디렉터리를 쓰고, gate-bound의 FIFO self-test는 실제 신호 시험과 재시도 정책 시험을 따로 보며, 실행 스크립트를 만드는 테스트 fixture는 자식 프로세스가 스크립트를 씁니다.

What and why

The PR check, contrib-check t0, fails on upstream main because of three test defects, and this PR fixes all three. Two are self-tests inside check-recipes: run 39454031746 on 6661aad8 ends with check-recipes: rc 1. The third is a race in three Rust test fixtures that write a shell script and then run it. On main, need_hook's tests failed 269 of 500 parallel runs with "Text file busy".

The three fixes ship together because each one alone leaves t0 red. With only the self-test fixes (8a30632e), check-recipes passes but test-bloomery-placement still fails with rc 101. With only the fixture fix, check-recipes still fails. The change touches tests, self-tests and test fixtures only. Product code paths and every time bound stay as they are.

1. sj-vs-clef's stub tests read the caller's data (60a999d2)

tools/ref/sj-vs-clef.sh --self-test reads reference rows for its stub tables from the default data path (/root/bloomery-data). On Python 3.12, a runner that cannot read that path raises PermissionError, and 11 of the 116 checks fail. With Python 3.14.4 the same self-test passes even without the fix, so the failure depends on the runner's Python.

  • tools/ref/sj-vs-clef.sh: the self-test exports BLOOMERY_DATA as an empty data directory inside its own temp directory, so the stub tables never read the caller's rows.
  • tools/ref/card-tests/run.sh: the existing self-test call now inherits a BLOOMERY_DATA whose reference files hold invalid JSON. The file names come from the existing e2e.SUITES list. If the isolation is removed, the self-test fails and check-recipes reports it.

Before and after, Python 3.12.12: 11 of 116 checks FAILED, then 116 checks ok.

2. gate-bound's FIFO cases assumed a signal breaks the open (8a30632e)

The fifo-eintr and fifo-giveup cases in tools/gate-bound.sh --self-test assumed that a trapped USR1 always makes the blocking open of a FIFO's write end fail. With Bash 5.3.9 on Linux it does not. When a reader comes, the first open goes on and the command runs, so no retry happens (fifo-eintr-retried: got [0]). With no reader, the open keeps waiting until the case's own 10 s bound ends it with rc 143 instead of 74. The retry and rc 74 branches in bounded are correct; the test could not reach them on this platform.

The self-test now checks two things separately:

  • fifo-signal keeps the real case. A USR1 goes to the runner while its open waits, then the reader starts. The case checks that the trap ran, the reader got the command's output, the command ran and the status is 0.
  • fifo-eintr and fifo-giveup test the retry policy. Inside the test runner only, a wrapper around the existing __bounded_run returns a failed open (no BOUNDED_RAN mark) a set number of times and then calls the real function. The test holds both ends of the FIFO open, so the result no longer depends on how the platform blocks. The existing checks stay: one retry and then the command runs, the give-up named with rc 74 and nothing started, and a bad try count refused with 64.

No product code gained a test mark or branch. The comment above the case carries PIN(2026-10-21): with the reason.

Before and after, Bash 5.3.9: gate-bound self-test: FAIL (4 failures), then gate-bound self-test: ok (0 failures).

3. Executable fixtures race with concurrent spawns (88a09ba2)

Three fixtures write a shell script from the test process and then run it: tests::stub in crates/placement/src/placement/need_hook.rs, tests::fake_tool in crates/serve/src/video.rs and hook_script in crates/gpu-gates/src/bin/gate_serve_start.rs. If another thread spawns a child while the script is open for writing, the child inherits the write descriptor and holds it until its own exec. Meanwhile the kernel refuses to exec the script with ETXTBSY ("Text file busy"). O_CLOEXEC does not prevent this, because the inherited copy closes only at the child's exec, and closing the descriptor in the parent leaves that copy open.

In gate_serve_start, the normal path joins its hashing thread before the hook step. When images() returns an error, though, hf() returns before the join and guarded() goes on to the next clause, so the thread's sha256sum spawn can overlap the hook script write.

Each fixture now has a short /bin/sh child write the script and exit, so the test process never holds a write descriptor on it. The parent waits for the child, checks its exit status and then sets the mode.

  • need_hook.rs: the helper asserts on the writer's spawn and exit status.
  • video.rs: the child creates the file with mktemp, which makes it exclusively with mode 0600, writes it and prints the path. The parent reads the path back as raw Unix bytes, so it does not assume UTF-8. This removes the parent's write, the PID and counter file name and the loop that retried the warm-up run up to 500 times on ETXTBSY. Mode 0700, the TempFile cleanup and the single warm-up run stay.
  • gate_serve_start.rs: a spawn error or a writer that exits nonzero comes back as a GateError. The hook text and mode 0755 are unchanged.

The fix adds no retry, sleep or test serialization.

Before and after, 500 runs with 16 test threads each: need_hook 269 of 500 failed, then 0 of 500 failed. The gate writer went from 312 of 500 failed to 0 of 500 failed, and the video writer with its retry turned off failed 496 of 500 before the fix.

Release notes: Under the hood: the sj-vs-clef and gate-bound self-tests pass on Python 3.12 and Bash 5.3 on Linux, and test fixtures no longer fail at random with "Text file busy" when they run a script they just wrote

Code shape

  • No second copy. The reference file names come from e2e.SUITES, the retry wrapper reuses __bounded_run through declare -f, and the FIFO helper is the existing eintr_case. The three fixture writers follow one pattern but stay in their own crates. The workspace has no test utility crate, and each caller returns a different type (PathBuf with a panic, TempFile, GateError), so a shared helper would add a cross-crate dependency only for fixtures.
  • Model code holds only architecture facts. No model file changed.
  • Dead code is gone. The video retry loop and its file name counter went with the parent write. Nothing else was made unused.
  • No silent failure. A temp directory or fixture that cannot be made exits with a named status, and every script writer checks its spawn and exit status. The FIFO cases assert the trap, the output, whether the command ran, the status and the time bound one by one.
  • Comments state what is true now. The gate-bound comment carries a PIN(2026-10-21): line for the replaced platform assumption, as the template asks for a re-pin. The fixture comment states that only the writer child opens the script for writing.
  • No relaxed gate. No band, tolerance, time bound or lint moved, and no check or test was removed. The real-signal case now asserts that the command pairs with its reader; the retry and give-up checks moved to the injected failed open. The video warm-up run stays; only the ETXTBSY retry around it is gone.
  • cargo fmt with the pinned rustfmt and git diff --check are clean on the fixture commit. I did not run cargo clippy.

Duplication found or removed (path:line), or "none": the three fixture writers (need_hook.rs:241, video.rs:1324, gate_serve_start.rs:325), kept separate for the reason in the first box.

What I ran

Unless a line says otherwise, the runs used a Linux x86_64 host.

sj-vs-clef

On the PR check, run 39454031746 on upstream main 6661aad8 fails check-recipes with both self-test causes: sj-vs-clef.sh self-test: 11 of 116 checks FAILED and four gate-bound FIFO failures.

With Python 3.12.12 and BLOOMERY_DATA unset. Before, on upstream main 564083ea:

bash tools/ref/sj-vs-clef.sh --self-test
sj-vs-clef.sh self-test: 11 of 116 checks FAILED

The failure comes from PermissionError: [Errno 13] Permission denied: '/root/bloomery-data/clef/flash/ref/reference.jsonl'.

After, with the first commit tested as ea41a779 on that base (the same diff as 60a999d2):

env -u BLOOMERY_DATA bash tools/ref/sj-vs-clef.sh --self-test
just check-recipes
sj-vs-clef.sh self-test: 116 checks ok
check-recipes: ok

gate-bound

With GNU bash, version 5.3.9(1)-release (x86_64-pc-linux-gnu). Before, on 60a999d2, whose tools/gate-bound.sh is the same file as main's:

bash tools/gate-bound.sh --self-test
FAIL   fifo-eintr-retried: got [0], want [1]
FAIL   fifo-giveup-no-hang: got [hang/yes], want [yes/yes]
FAIL   fifo-giveup-rc: got [143], want [74]
FAIL   fifo-giveup-named: got [0], want [1]
gate-bound self-test: FAIL (4 failures)

To show that the new cases still catch a broken retry policy, I ran the FIFO cases against two temporary copies of tools/gate-bound.sh at 8a30632e. One copy never retries (break in place of the BOUNDED_RAN test). The other gives up one try late (-gt in place of -ge). Both fail:

mutant=no-retry rc=1
FAIL   fifo-eintr-rc: got [1], want [0]
FAIL   fifo-eintr-retried: got [0], want [1]
mutant=late-giveup rc=1
FAIL   fifo-giveup-rc: got [0], want [74]
FAIL   fifo-giveup-nothing-started: got [started], want [none]
FIFO mutation proof: both retry-policy defects detected

After, on 8a30632e, the full recipe check on two Linux hosts:

just check-recipes
gate-bound self-test: ok (0 failures)
check-recipes: ok

The full t0 on 8a30632e, on the second Linux host, ends with check-recipes rc=0 and test-bloomery-placement rc=101 from need_hook::tests::only_a_refusal_is_kept_for_the_exit, which is the race the fixture commit removes.

Check Revision Result
Python 3.12.12, BLOOMERY_DATA unset 564083ea 11 of 116 checks FAILED
Python 3.12.12, BLOOMERY_DATA unset ea41a779 116 checks ok
bash tools/gate-bound.sh --self-test, Bash 5.3.9 60a999d2 FAIL (4 failures)
FIFO cases against the two mutants 8a30632e both detected
just check-recipes, first Linux host 8a30632e check-recipes: ok
just check-recipes, second Linux host 8a30632e check-recipes: ok

Executable fixtures

The fixture commit was tested as f0182b3c on main 6661aad8; it is the same patch as 88a09ba2 here. need_hook.rs at ec05696d and gate_serve_start.rs at aba47bd5 are identical to the same files at f0182b3c, so those runs cover the final code. At ec05696d, the video and gate writers were still the ones on main.

The need-hook rows repeat cargo test -p bloomery-placement need_hook 500 times with the thread count shown. The last row is one full placement run.

Check Head Result
500 parallel runs, 16 test threads 6661aad8 (main) 269 of 500 failed with errno 26, ExecutableFileBusy, "Text file busy"
500 runs, 1 test thread 6661aad8 (main) 0 of 500 failed
500 parallel runs, 16 test threads ec05696d 0 of 500 failed
cargo test -p bloomery-placement -- --test-threads=16 ec05696d 160 passed, 0 failed

To repeat the video and gate writers without building the GPU crates, a probe extracts each writer function from the source at the tested revision, compiles it with rustc --test and runs 16 copies of the fixture in parallel. One run is one such binary, and each row is 500 runs, or 8,000 writer calls. The original video writer hides the failure behind its retry loop, so the probe also runs a copy with only that retry turned off:

Writer Head Result
video, original ec05696d 0 of 500 failed; the retry loop caught ETXTBSY 1,763 times
video, retry turned off ec05696d 496 of 500 failed with ExecutableFileBusy
gate, original ec05696d 312 of 500 failed with ExecutableFileBusy
gate, child writer aba47bd5 0 of 500 failed
video, child writer f0182b3c 0 of 500 failed
cargo test -p bloomery-serve --lib video::tests -- --test-threads=16 f0182b3c 12 passed; 0 failed

The gate probe also checks that the hook records its stdin, prints its line, ends with exit 75 and has mode 0755.

Failing under 16 threads and never under 1 thread fits the inherited write descriptor described above. 500 clean runs do not prove that every schedule is safe. The fix holds because the test process no longer has a write descriptor for a child to inherit.

Reproduce:

cargo test -p bloomery-placement need_hook -- --test-threads=16
cargo test -p bloomery-serve --lib video::tests -- --test-threads=16

GPU evidence

The repeated fixture runs above ran on a host with this card:

NVIDIA GeForce RTX 5090, 595.99.02, CUDA 13.2

just gate-gpu-serve-start-glm and just gate-gpu-serve-start-ds41 were not run here: both recipes set BLOOMERY_CARD=both (two cards in view), and this host has one card.
The hook_script writer those gates call is the one exercised 500 times in the table above.

Hardware (if the change is for a machine)

Not for a machine. The runs used a Linux x86_64 host with Bash 5.3.9 and the card under GPU evidence. The just check-recipes and t0 runs at 8a30632e also used a second Linux host.

What I ran into

This does not block the PR. crates/gpu-gates/tests/sentence_prompts.rs:95-96 also writes a script from the test process, and I left it as is. Its test binary has one test, and it waits on each child with a blocking output() before it rewrites the script, so no spawn can overlap the write. A search of the tree for other script writers (shebangs, set_permissions, chmod, mode literals) found only sequential setup steps in the shell and Python tools.

AI help

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

@github-actions github-actions Bot added gpu The card engine: crates/gpu*, crates/app needs-gpu Changes code a card must check, and carries no gate run on a card placement Placement planning: crates/placement serve The HTTP server: crates/serve tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo labels Oct 20, 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: No must-fix defect remains in the fixture and self-test changes.

Non-blocking

⚠ Retain the fixture-race reproducer: crates/placement/src/placement/need_hook.rs:245.
The body describes a concurrent writer probe, but the diff does not retain it. Keep the probe under tools/ while it is available, so future ETXTBSY failures can be reproduced without rebuilding the GPU crates.

Checked

Duplicates: the new self-test wrapper delegates to the existing owner. Dryer reported 0 pairs in the scanned crates. The short fixture writers span separate crates; sharing them adds elements.

Complexity: crapper flagged no function. Added branches select self-test failure injection; no hot path changes.

Silent failure: writer and setup failures reach assertions or named exits. Reader output assertions cover the ignored reader status.

Tests, by inspection: dropping the retry at tools/gate-bound.sh:259 breaks the retry assertions. Changing -ge to -gt at tools/gate-bound.sh:264 lets the give-up case run its command and breaks its assertions. Dropping the command invocation at tools/gate-bound.sh:215 breaks the output/started assertions.

Tests, by inspection: removing the export at tools/ref/sj-vs-clef.sh:714 exposes the poisoned reference files to the run-status assertions. The video writer preserves raw path bytes and its warm-up run; all three writers check the child's status.

Gates: no bound or threshold moved. The FIFO case replacement carries a dated PIN and platform-specific failure evidence.

Escape catalog: C1–C4 checked; no matching failure path. The wrapper calls the renamed original, without recursion.

Notes

Dryer did not scan crates/gpu-gates; its changed helper was checked by Grep.
Validator checks were static; no test runs were repeated. The PR reports host fixture runs but no GPU-gate output.

Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_serve_start.rs and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.

🔨 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 e3ce40f into midagedev:main Oct 20, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gpu The card engine: crates/gpu*, crates/app needs-gpu Changes code a card must check, and carries no gate run on a card placement Placement planning: crates/placement serve The HTTP server: crates/serve 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