Repository navigation
metal: a stream with a residency set drains its queue before the set is torn down - #916
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 earlier must-fix is still open: the repro comments state a kernel fault that the PR body says no run produced.
Since the last review
The head is a rebase of the same two commits. The only change is a context shift in the lever registry (registry.rs), where the neighbouring row moved. It does not change the new row. Nothing in the PR text or code answers the earlier items.
- Must-fix 1 (the repro claims a fault it did not produce): still open, residency.rs:276.
- ⚠ no test guards the drain: still open, stream.rs:706. The body gives a reason; it is not a blocker.
- ⚠ two dropped errors: still open, stream.rs:730 and stream.rs:433.
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 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. The comments state as fact what the author measured to be false. A reader will trust "None faults" and take the drain as proven.
Cost: the repro adds a [[bin]], a public ReproWait enum with 3 arms and a public repro fn, 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 its doc what was measured (iterations, result: no panic on the tree without the drain) 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 94 unit tests and gate-levers stay green. Name this as the open gap in the PR body, or add a macOS test that commits a buffer, drops the stream and asserts pending was empty at the release.
⚠ Two errors are dropped without a name. stream.rs:730: let _ = self.sync_for(..) discards the failure of a buffer that ended in error, and sync_for removes that buffer from pending, so if the drop sees it first nothing reads it later. stream.rs:433: a failed writeln or sync_data leaves a stale last line that names the wrong call after a panic. Print one stderr line in each case, as 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. Dryer pairs (2): 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; the breadcrumb open failure and the timeout leak are named). - Performance: unset,
markis oneOnceLockload and a branch per command buffer;format_args!does not allocate. No finding. - Tests: none added or changed; mutation result above.
- Gates: no pin moved. The lever row,
levers-direct.txtand the in-place read agree. - Escape catalog: no pattern matched (no shell changed).
Notes
- Evidence is from Macs. 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)
… a breadcrumb write failure are named The repro ran 15,500 iterations without the drain and never panicked, so it proved nothing its comments claimed. The teardown's sync error was dropped, and the drain is the last reader of a buffer that ended in error; it is now a stderr line. A breadcrumb line that does not reach the disk is said once. The Drop doc states Apple's rule and reads the symbolicated fault as that rule broken, not as an established driver mechanism. 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: CLEAN: the new commits remove the repro and name both dropped errors; no failure path survived.
Since the last review
- Must-fix 1 (the repro claims a fault it did not produce): fixed. The bin, its
[[bin]]block,ReproWaitandreproare deleted, with theMetalDeviceimport. Grep finds no remaining reference. - ⚠ no test guards the drain: answered by the author. The PR body names it as an open gap and gives the evidence it has (symbolicated stack, pending counts, Apple's contract).
- ⚠ two dropped errors: fixed. stream.rs:740 prints the drain error. stream.rs:441 prints the first failed breadcrumb write once.
- also 1 minor (driver mechanism stated as fact): fixed. The
Dropdoc now says the fault "is read as" the broken rule.
Checked
- Duplicates: 0 new items in the new commits (the commits only delete code and edit two bodies); dryer found no pair; the earlier 2 pairs were in the deleted bin.
- Complexity: crapper flagged nothing.
- Silent failure: 3 sites followed.
Dropdrain error (now printed), breadcrumb write error (printed once throughSAID), timeout leak (named). On a poisoned lockcommitted()andsync_fortake the state as it stands, soDropcannot panic there. - Tests: none added or changed.
- Gates: no pin moved. Performance:
markis unchanged on the unset path (oneOnceLockload); no new hot-path term. - Escape catalog: no pattern matched (no shell changed).
Notes
- Evidence is from Macs. No
nvidia-smirun applies to these crates. - FAIL-first is open in the PR body: no run reproduced the panic on the tree without the drain. The body says so; it is not hidden.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
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,commit and wait call class, and at each e2e clause, so a later panic names the call in flight.
Supersedes #915 (the same two commits rebased on main; the only conflict was the lever registry, where both sides add rows).
Release notes: Fixed — a Metal session torn down with GPU work in flight could panic macOS.
Code shape
MetalStream).that cannot be opened or written each give 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: 85 passed.cargo clippy -p bloomery-metal -p bloomery-levers --all-targets:0 warnings.
--mutants-all, qwen38d--mutants-all): no panic;teardown drain N pending, N ≥ 1).--mutants-all: 10 of 10 PASS, no panic; 213 of 650 teardowns found buffers pending.repro loop (removed in this PR, since it proved nothing) and 610 runs of
--row qwen38d --mutant dense_slot_one.The panic needs more state than one child run.
teardown drain N pendinglines are whatshows the drain at work. 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