Skip to content

metal gates: the shader validation reader counts macOS 26.5's report form, and has one owner - #1180

Merged
midagedev merged 3 commits into
midagedev:mainfrom
yulmucoffee:metal-validation-report
Nov 9, 2026
Merged

midagedev merged 3 commits into
midagedev:mainfrom
yulmucoffee:metal-validation-report

Conversation

@yulmucoffee

Copy link
Copy Markdown
Contributor

What and why

row_tail_reads and gemm_a4_store run a child of the kernel gate under Metal's shader validation and count its reports. They count only Invalid Metal usage blocks between ===== lines. On macOS 26.5.1 (an M5 Pro) the layer writes each report as a paragraph that opens with Invalid device load at offset N, executing kernel function: "…", with neither string. So both controls read 0 reports, and the clauses were red with "nothing was checked", although the layer had reported the controls' reads (18 for tail_read, 4 for gemm_weight_edge). Found while running #860 (report); it touches #868.

This change makes the reader take both forms. It also moves the child run, the reader and the control-then-own verdict, which were one copy in each of the two clause files, into common.rs.

Release notes: internal — the Metal kernel gate's two shader-validation clauses check again on a Mac whose layer writes its reports as paragraphs; no engine change.

Code shape

  • No second copy. The child run, the reader and the verdict now live once in common.rs (reads_inside); both clauses call it.
  • Model code holds only architecture facts. No model code changed.
  • Dead code is gone. Both old copies, and the Command imports they needed, are removed.
  • No silent failure. The control must still be reported, or the clause is red. A stderr with no report counts 0.
  • Comments state what is true now.
  • No relaxed gate. No band or rule moved. The reader recognizes one more form of the same report. All 811 mutants still turn their clause red (below).
  • cargo fmt and cargo clippy are clean on what I touched (just mac-metal-lint rc 0).

Duplication found or removed: crates/metal/src/bin/gate_metal_qwen35moe_kernels/clauses_matvec.rs:142-204 (Validated, row_tail_under_validation) and clauses_gemm.rs:786-863 (Validated, gate_under_validation), at c7f21a7d2, plus the verdict in row_tail_reads and gemm_a4_store.

What I ran

All on the Mac below, at this branch (one commit on c7f21a7d2) unless it says main.

  • FAIL-first. The new test validation_reports_reads_both_forms holds the reader to both forms and to a stderr with no report. The paragraph sample is cut from this Mac's stderr. The block sample has only the two strings the old reader keyed on, since I have no stderr from a Mac that writes that form. With the paragraph branch removed (the old rule), the test is red:
    assertion `left == right` failed
      left: (0, "")
     right: (2, "Invalid device load at offset 4678, executing kernel function: \"q4k_matvec\"  / buffer: <unnamed>, length:1476, resident:Read Write")
    
  • just lab-metal at main (c7f21a7d2): gate_metal_qwen35moe_kernels: FAIL (qwen35moe_a3b, qwen3moe_a3b). The only red clauses are row_tail_reads (once) and gemm_a4_store (twice), each "shader validation reported nothing for the control". 412 clause lines PASS, 2 SKIP (metallib_equals_source, no Metal Toolchain). The recipe stops before --mutants-all.
  • just lab-metal on this branch, rc 0:
    clause row_tail_reads: PASS (no report in the row-tail launches, 18 for the control)        [qwen35moe_a3b]
    clause gemm_a4_store: PASS (… no report in the 16-row launches under shader validation, 4 for the control)   [qwen35moe_a3b, qwen3moe_a3b]
    gate_metal_qwen35moe_kernels: PASS (14 instances)
    gate_metal_qwen35moe_kernels --mutants-all [<each of the 14 instances>]: PASS (… mutants, each red on its clause)
    
    811 mutants in all, tail_read red on row_tail_reads and gemm_weight_edge red on gemm_a4_store among them.
  • just mac-metal-lint: rc 0.
  • On today's main. The commit rebases onto 1a7bba264 with no conflict; the three files are unchanged there since c7f21a7d2. On that tree, cargo test -p bloomery-metal --bin gate_metal_qwen35moe_kernels: 2 passed (validation_reports_reads_both_forms, every_mutant_finds_its_text_as_often_as_it_names). cargo clippy on the bin: no warnings. cargo fmt --check: clean. I did not rerun just lab-metal there.
  • just contrib-check --tier t0: DONE tier=t0 total=40 red=1 wall=532s red: check-recipes. The red block is the tools/mac-gate.sh self-test, a gate that ignores TERM is KILLed with 137: FAIL (rc 124, wanted 137). The same run at unchanged main ends the same way (DONE tier=t0 total=40 red=1 wall=556s red: check-recipes), with that same line red and three more: the mac-gate self-test's the child of a gate the bound ended is gone, the ref/lease self-test's trace-free-by-waiter, and a Python tool test that needs numpy in this Mac's python3 (SetError: predict needs numpy). Run alone, bash tools/mac-gate.sh --self-test passes 27 of 27 three times on each tree. So I read it as a timing case under the parallel run on this Mac, not this change. This branch does not touch tools/.
  • Not run: just mac-static's lint and combos stop with 69 here (no ~/opt/bloomery-mac-env.sh: no CUDA headers or Linux sysroot). The changed code is in the gate's mac.rs tree, which the Linux build does not compile.

Hardware (if the change is for a machine)

Apple M5 Pro (16-core GPU), 24 GB (hw.memsize 25769803776), Mac17,9, macOS 26.5.1 (25F80), on AC power. Rust 1.99.1 (rust-toolchain.toml). No Metal Toolchain, so metal-lib: path=source. gemm: architecture=applegpu_g17s metal4=true matrix-units=true engine-path=tensor. Fixtures from fixture fetch qwen35moe / qwen3moe, and the two -mlxsplit splits from tools/mlx-fixture.py make (mlx 0.32.4) with the config.json of mlx-community/Qwen3.6-35B-A3B-4bit (38740b84) and mlx-community/Qwen3-30B-A3B-Instruct-2507-4bit (e9675aa3), then prepare.

🤖 Generated with Claude Code

…form, and has one owner

row_tail_reads and gemm_a4_store counted only "Invalid Metal usage" blocks
between "=====" lines. On macOS 26.5.1 (an M5 Pro) the layer writes each
report as a paragraph opened by "Invalid device load at offset N, executing
kernel function: ...", with no such block, so both controls read zero reports
and the clauses were red with "nothing was checked" although the layer had
reported the control's read (18 reports for tail_read, 4 for
gemm_weight_edge).

The child run, the report reader and the control-then-own verdict move from
the two clause files into common.rs (one copy). The reader takes either form;
validation_reports_reads_both_forms holds it to both, and to a stderr that
reports nothing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@midagedev

Copy link
Copy Markdown
Owner

@yulmucoffee Sorry for the slow reply. This sat three days without a look. Thank you for the fix and for moving the reader into one owner.

I merged it with #1187 into one tree and am running just lab-metal and the Metal lint on an M4 Pro (macOS 27.0.1) now. I will merge both when they are green.

(Written by an AI coding agent.)

@midagedev midagedev left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Checked on an M1 Pro (macOS 27.0.1) together with #1187: just lab-metal green, row_tail_reads PASS (18 reports for the control), all mutants red on their clauses.

(Written by an AI coding agent.)

@midagedev

Copy link
Copy Markdown
Owner

I merged main (with #1187) into this branch; the merged tree is the same tree lab-metal ran green on the M1 Pro. I will merge once contrib-check passes. Its earlier failures were GitHub download errors (apt 404, release 504), not this change.

(Written by an AI coding agent.)

@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 two clause copies become one owner in common.rs with semantics preserved, and the reader's new report form is guarded by the control, so an unknown form stays red.

Checked

  • Duplicates: 4 new items (Validated, under_validation, validation_reports, reads_inside) checked by grep; the only other child runner, mutants_all in mac.rs:853, reads exit codes and stdout clause lines, a different fact. The two old copies are gone; net fewer elements.
  • Complexity: crapper did not run; read by hand, validation_reports (common.rs:435) and reads_inside (common.rs:469) are each well under 15; a new function, no growth elsewhere.
  • Silent failure: 3 sites followed. A layer form the reader misses makes checked.reports == 0 and the clause red ("nothing was checked"), never green (common.rs:476). A mixed stderr with a real Invalid Metal usage block counts ≥ 1, so the own run goes red. unwrap_or_default on first feeds only a message built when a report exists. blocks.len() vs the old string-match count differs only when one block holds the string twice; every check (>0, ==0) gives the same verdict.
  • Semantics kept: reads_inside compared line by line with both base copies (clauses_gemm.rs:880-905 and clauses_matvec.rs:226-265 at the base sha): same checks, same order (started, control count, own reports, own.exit?), verdict text unchanged; matvec's red message gains the launches name. Child args at both call sites carry exactly the flags the old copies passed, --instance and --mlx-fixture included.
  • Tests: validation_reports_reads_both_forms holds both forms and the zero case; the paragraph branch removed turns it red (FAIL-first output in the body), the blocks branch removed turns the first assert red.
  • Gates: no band, tolerance or pin moved; the reader widened to a second form of the same report, with the failure shown first.
  • Escape catalog: C1 to C4 are shell-script patterns; this diff touches no script.

Notes

dryer and crapper did not run (ModuleNotFoundError in diagnostics.md), so the duplicate and complexity checks above are grep and hand reads. The PR body carries the Metal gate evidence (Mac, hashes, commands with output); there is no nvidia-smi line, this change being Mac-only, so the gpu label is false.

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

@midagedev
midagedev merged commit d6b0d61 into midagedev:main Nov 9, 2026
6 checks passed
@midagedev

Copy link
Copy Markdown
Owner

Merged. The last red was mine, not this change: a stat -f %m in tools/mac-remote.sh printed the file system on Linux, so the self-test failed in CI. Fixed on main in 05af719. Thank you for the fix.

(Written by an AI coding agent.)

@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: the new commit's direction is right (GNU stat first, as in box.sh, oxide-host.sh and lease-probe.sh), but it edits three separate copies of one rule instead of the file's declared single owner for it.

Since the last review: the last review was CLEAN with no must-fix or ⚠ items, so nothing to carry. The three metal files are unchanged from that review (reads_inside at clauses_gemm.rs:813 and clauses_matvec.rs:155, validation_reports and the both-forms test in common.rs, all as reviewed). The new commits touch only tools/mac-remote.sh: the three mtime probes become GNU-stat-first. On macOS stat -c fails into the BSD branch, so no Mac behavior changes; on Linux (the self-test runs the lock flow there, line 1042) the GNU branch is the live one.

Must fix

1. The remote mtime probe has three owners; this diff edits each separately

tools/mac-remote.sh:151, tools/mac-remote.sh:249, tools/mac-remote.sh:525. One rule — "GNU stat, else BSD stat, else now" — is written three times: inline in SURVEY, in RMTIME, and in the run script's own mtime(). RMTIME's comment declares it "The remote scripts' one mtime" and LOCKS and CLONES already splice it in (lines 259, 298); SURVEY and the run script bypass it. The cost is in this diff: SURVEY's copy had drifted before (no GNU branch at all), so this one rule change needed three edits and had silently lost a branch. Cost of fixing now: the next stat-rule change is one edit instead of three and cannot drift again.

Fix — three edits, net two copies fewer:

  1. Move lines 248-249 to just above SURVEY='{ (host strings splice RMTIME when they are defined, so it must be assigned first) and make the fallback self-contained — SURVEY and the run script define no now; LOCKS (258) and CLONES (297) do, and differ from date +%s only by the listing's own runtime:
# The remote scripts' one mtime: a path's modification time in seconds, GNU or BSD stat, or now when neither reads it.
RMTIME='mtime() { stat -c %Y "$1" 2> /dev/null || stat -f %m "$1" 2> /dev/null || date +%s; }'
  1. In SURVEY, add the splice after mkdir -p "$base" (line 132) and shorten the probe:
'"$RMTIME"'
  echo "LOCK=${l##*/.lock-} $(cat "$l/owner" 2> /dev/null || echo ?/0) $alive $(( $(date +%s) - $(cat "$l/heartbeat" 2> /dev/null || mtime "$l") ))"
  1. Replace the run script's own definition (line 525) with the same splice:
'"$RMTIME"'

Checked

  • Duplicates: grep stat -[fc] over tools/ — the GNU-first order now matches box.sh:181, oxide-host.sh:192 and ref/lease-probe.sh:86; the in-file triplication is must-fix 1. The bare stat -f %m at 1243/1251 runs only in the macOS-guarded flow self-test (line 1214); no sibling copy left behind by this fix.
  • Complexity: crapper did not run (see Notes); the diff adds no function, nothing to split.
  • Silent failure: 3 probe chains followed to their consumers (SURVEY 151 → lock_note 173; LOCKS 275; run script 529); each ends in date +%s/now, so an unreadable heartbeat and failing stats read age 0 — pre-existing shape, unchanged by the reorder, not this diff's.
  • Tests/gates: no band, tolerance or pin moved; the earlier commits' reader is untouched.
  • Escape catalog: C1 to C4 none — the || chains consume exit codes (not C1), no heredoc body or process matching changed, mtime calls stat, not itself.

Notes

  • The PR body says "This branch does not touch tools/" and describes no run for the mac-remote change; the body predates this commit.
  • dryer and crapper did not run (ModuleNotFoundError in diagnostics.md); the duplicate check above is grep and hand reads.

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

@yulmucoffee
yulmucoffee deleted the metal-validation-report branch November 16, 2026 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants