Skip to content

tools: cover a failed lane cleanup in the batch self-test - #717

Merged
juliankang4 merged 2 commits into
midagedev:mainfrom
juliankang4:fix-tool-self-test-races
Oct 23, 2026
Merged

juliankang4 merged 2 commits into
midagedev:mainfrom
juliankang4:fix-tool-self-test-races

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

셸 자체 시험 세 개가 잠금 파일 재사용, 시작 지연, 긴 임시 경로 때문에 실패하던 것을 고치고, 정리 실패 시험도 하나 더합니다.

Part of #565. Tracked in #699.

What and why

Three shell self-tests fail on main for reasons that have nothing to do with the code they check. Each one assumes something about its environment that the test does not set up. A fourth change adds the lane-cleanup error case that an earlier bot review asked for.

  1. tools/ref/lease.sh: the trace write-failure case reuses the lock file tlock3. The slow-fork case before it can still hold a shared lock on that file, so the case's exclusive flock -n is refused and the write-failure check never runs. The case returns 1 where it expects 0. This came in with df872d5f6c53.
  2. tools/ref/load-groups.sh: stall_case starts its idle bound before the child process has printed its first arm line. A child that starts slowly is killed before it begins, so the case reports left= where it expects left=1 2. This came in with cd5bd6659263 (tools: load-groups.sh kills a process that prints nothing for BOUND seconds #169). Two cleanup fixtures in the same function make the same assumption.
  3. tools/gate-batch.sh: the missing-hook case expects the one-line summary to end with the missing command's name. The summary keeps only the first 200 characters of the log line, and under a long TMPDIR the path pushes the name past that limit. This came in with bae2648b1d55.

Changes:

  • tools/ref/lease.sh: the write-failure case takes its own lock file, tlock5. Before it runs, the test holds a shared lock on tlock3 on descriptor 8, so going back to the shared name brings the defect back, and the setup exits at once if that shared lock cannot be taken.
  • tools/ref/load-groups.sh: lg_pre now starts the short idle bound, so the bound runs from the first arm line and the outer lg_process call gets a ten times longer budget for startup. The child sleeps one second longer than the idle bound before it prints its arm line. A new case runs a child that prints nothing, and checks that it is killed once, that all three arms end with the termination status 143 and that no arm is left. The two cleanup fixtures use the same budget. The driver's own pre-start timeout is unchanged.
  • tools/gate-batch.sh: the missing-hook case reads the command name from the full hook log and checks only the status 127 on the summary line. A separate case writes a 250-character first line and a second line to a fixed log, and checks that the summary holds exactly the first 200 characters. The result no longer depends on how long the temporary path is.
  • tools/gate-batch.sh: lskip_case runs the real stop_lanes and then injects the status 70. The new case checks that the error is returned and that no result line is printed. This covers the cleanup failure case that the review of tools: wait for stopped batch fixture writers before cleanup #338 listed as non-blocking.

No product code, public API, GPU path, gate band or pin changes. Only the self-test blocks in three shell files change.

Release notes: internal: three shell self-tests no longer depend on lock-file reuse, process start time or the length of the temporary path.

Code shape

  • No second copy. The new cases reuse lg_pre, check, want and stop_lanes. No new function or helper was added.
  • Model code holds only architecture facts. No model code changes.
  • Dead code is gone. The assumptions about the shared lock name, early idle bound and path suffix are removed.
  • No silent failure. A refused shared-lock setup exits with a named code, and the new cleanup case checks that a stop_lanes that errors returns its error.
  • Comments state what is true now.
  • No relaxed gate. No band, tolerance or lint moves. Each test asserts the same contract, on a setup that holds it.
  • cargo fmt and cargo clippy do not apply to shell files. bash -n and git diff --check are clean on the three files.

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

Closes deferred: tools/gate-batch.sh #338 bot review (non-blocking).

What I ran

The three original self-tests fail on the unchanged files, each on the assumption described above. The run used a copy of the base checkout on a Linux host with a long TMPDIR:

FAIL trace-write-fail-rc: got [1], want [0]
FAIL stall-left: got [left=], want [left=1 2]
FAIL start hook: and is one stderr line with the shell's 127: 0 lines match /^gate-batch: start hook \(rc=127\): .*no-such-hook/
gate-batch self-test: 54 of 55 ok
SUMMARY 3 of 3 expected outcomes

On this branch, the same cases run on a DGX Spark (Linux aarch64), again with a long TMPDIR made of three 70-character directory levels:

CASE_RESULT lane-cleanup rc=0 expected=pass PASS
CASE_RESULT lane-cleanup-mutant rc=1 expected=fail PASS
CASE_RESULT lease-shared-earlier-probe rc=0 expected=pass PASS
self-test: ok (0 failures)
CASE_RESULT load-groups rc=0 expected=pass PASS
HOOK_ASSERTIONS 3 failures=0
CASE_RESULT gate-batch-long-tmp rc=0 expected=pass PASS
SUMMARY 5 of 5 expected outcomes

The lane-cleanup mutant removes the || return $? guard, so the injected rc 70 becomes 0 and the new assertion fails with rc 1, as expected. The self-test: ok (0 failures) line is the native load-groups.sh --self-test, which ran in full.

Not run: the full lease.sh --self-test and the full gate-batch.sh self-test on this head. I ran the changed case blocks only. A first attempt to run the whole lease self-test was cut off before it finished, so I do not count it. Also not run: any Rust test, clippy, GPU test or speed comparison, because no product code changed.

Reproduce, from the repository root:

bash -n tools/ref/lease.sh tools/ref/load-groups.sh tools/gate-batch.sh
git diff --check upstream/main...HEAD
bash tools/ref/load-groups.sh --self-test

Hardware

The base run was on a Linux host. The branch run was on a DGX Spark (Linux aarch64). These tests run shell on the CPU only and use no GPU or model files.

What I ran into

This does not block the PR. Two of the three introducing commits have no pull request on GitHub, so the Low entries in #699 name the commit only.

AI help

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

@github-actions github-actions Bot added the tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo label 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 changes are confined to self-tests and cover lock isolation, startup termination, cleanup errors, and log truncation.

Checked

Cleanup: the new case injects status 70 after real lane cleanup and requires that status with no result output. By inspection, removing the propagation guard at tools/gate-batch.sh:1784 fails those assertions.

Lease: the fixture holds the earlier lock shared and uses a separate lock for the failed-write case at tools/ref/lease.sh:1248. A refused setup lock exits 70. The existing assertions require one named diagnostic, status 0, and an empty trace ID.

Startup: the fixture restores the short idle bound when an arm begins at tools/ref/load-groups.sh:280. The new silent-child case requires one timeout diagnostic, three arm records with status 143, and no remaining arm. Cleanup fixtures retain their status assertions.

Truncation: the missing command is checked in the full log. The fixed-log assertion at tools/gate-batch.sh:1989 requires exactly the first 200 characters. By inspection, a 201-character limit or inclusion of the second line fails it.

Structure and gates: no duplicate owner or unneeded abstraction identified. No production bands or pins move. No escape-catalog defect identified: the cleanup status is captured explicitly and the saved function alias avoids recursion.

Validation: bash -n passed separately for all three changed files.

Notes

Full runtime suites were not run during validation. The PR reports the full load-groups self-test and changed lease/batch case blocks; it does not report full lease or gate-batch suites on this head.

🔨 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 adbd8b6 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

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