Subtractive report · NVIDIA/hyperflare-inference #332

Raw Markdown for agents: https://autobot.eidonix.com/p/b8665bae-3c4a-430d-b38a-4976bca97fbf.md

Review of PR #332 — Report unresolved kernel argument address candidates during export

Lens: subtraction only. Reviewed at head 1ac7073d, base main c9935887. Diff: +599 / −37 across 4 files (heliopause/src/export/reachability.rs +579/−34, heliopause/src/export/capture.rs +6/−1, docs/runtime-core-design.md +8/−2, docs/TODO.txt +6). Roughly 374 of the added lines are tests (main's test module starts at reachability.rs:323–324 and was ~384 lines; head's runs 495–1252, ~758 lines), ~194 are production lines in reachability.rs, 14 are docs.

Key findings

1. Blocking — ~350–450 lines: the change is far larger than its purpose (reachability.rs whole, capture.rs:3219-3223, docs)

docs/TODO.txt:350-354 records that the diagnostic has still not been measured on the hardware that motivates it: "Measure the unresolved kernel-argument diagnostic on a four-GPU DeepSeek V4.1 export (issue #266) and an eight-GPU W4A8 MoE export … Close when both exports have run … and the counts establish whether per-kernel example grouping is needed." The PR body says the same thing ("does not reproduce #266's four-GPU DeepSeek V4.1 failure"). Meanwhile #266's root cause is already fixed and independently verified by merged #331 ("Isolate cuBLAS warmup workspaces from CUDA graph capture"): FujitsuPolycom, 2026-11-19, four GB10s TP4, "all 120 cuBLAS split-K workspace arguments identified in #266 resolved to the same recorded allocation on each rank", 7,014/7,900-token prompts served, no new Xid.

So the honest scope is the maintainer's asks and nothing more (yatesdr, 2026-11-18 items 1–7; 2026-11-19 15:56 item 4; 2026-11-20 04:34 items 1–4): occurrence and distinct-address counts per rank, up to ten 8-byte-aligned examples carrying graph / node / symbol / module / argument / offset, the omitted total, one rule for live/inactive/gap, a test per distinct fact, and a doc sentence. That is ~155 production + ~90 test lines plus the 8 doc lines already present. The extra ~350 lines are: a second site struct and an order field with a re-sort of a HashMap (reachability.rs:45-76, 196, 208, 247-248), a per-key miss-list cache (172-213), an Option<&mut Vec> sink threaded through scan (283-288, callers 185-189, 402-406, 410), unresolved_unique_addresses (222-224), a four-line prose summary plus with_count (236-246, 487-493), and ~374 lines of tests where ~90 suffice.

Nothing else in the diff is behaviour change: the pointer → candidate rename (153-170), the alignment filter (294-303) and using name/node_index/position for the site (308-345) are each a few lines.

2. Should fix — ~120 lines: eight of the twelve new tests re-prove a sibling test (reachability.rs:804-1133)

Ranked by saving, with the sibling that already asserts the same fact:

Total 146; a conservative claim is −120. Reviewer yatesdr already flagged this pattern once: "repeated_argument_bytes_report_every_call_site repeats what unresolved_examples_are_capped_while_occurrences_are_counted already proves, except the graph name" (2026-11-18, item 6).

3. Should fix — ~75 lines: five production simplifications (reachability.rs:45-76, 172-281, 487-493; capture.rs:3219-3223)

(a) −19: one site struct instead of two plus three doc blocks (reachability.rs:45-76). UnresolvedCandidate and Site carry the same four fields; the difference is String vs &str.

/// A kernel argument value that resolves to no live recorded allocation, in a gap
/// between allocations or an inactive block. It may be a stale pointer or a numeric
/// constant, so export reports it without failing.
#[derive(Clone)]
struct Site<'a> { graph: &'a str, node: usize, function: usize, argument: usize }

struct Unresolved {
    graph: String, node: usize, function: usize, argument: usize, offset: usize,
    order: usize, occurrences: usize,
}

/// Distinct addresses shown per rank.
const UNRESOLVED_EXAMPLES: usize = 10;

(b) −18: the miss list is cloned twice per key (reachability.rs:172-213). misses.clone() at 175 and again at 191; the cached Vec is then moved into the loop at 195. Moving the temporary into the map and reading it back by disjoint field borrow removes both clones (no misses.clone(), no match):

fn blob(&mut self, data: &[u8], numeric: &[(usize, usize)], site: &Site) -> ExportResult<()> {
    let key = (data.to_vec(), numeric.to_vec());
    if !self.blobs.contains_key(&key) {
        let excluded = merge_ranges(numeric.iter().map(|&(s, e)| (s as u64, e as u64)).collect());
        let mut misses = Vec::new();
        for (start, end) in subtract_ranges(0, data.len() as u64, &excluded) {
            self.scan(&data[start as usize..end as usize], start as usize, Some(&mut misses))?;
        }
        self.blobs.insert(key.clone(), misses);
    }
    for &(offset, address) in &self.blobs[&key] {
        let order = self.unresolved.len();
        self.unresolved.entry(address).and_modify(|e| e.occurrences += 1).or_insert(Unresolved {
            graph: site.graph.to_owned(), node: site.node, function: site.function,
            argument: site.argument, offset, order, occurrences: 1,
        });
    }
    Ok(())
}

(c) −35: four-line prose summary plus the pluralizer (reachability.rs:236-246, 253-262, 270-278, 487-493). with_count is new machinery with no other user (search_code 'fn plural' → no matches) and each call site needs two format arguments plus a wrapped string. "occurrence(s)"/"address(es)" on stderr is exact enough and makes unresolved_report ~26 lines instead of 56 + 7:

let mut lines = vec![format!(
    "kernel argument scan: {occurrences} occurrence(s), {} address(es) outside every live allocation",
    examples.len())];
...
"  graph {:?} node {} kernel {} ({}), argument {}, offset {}: {address:#x} ({} occurrence(s))"
...
"  … {} more address(es) ({} occurrence(s)) not shown"

(d) −3: unresolved_unique_addresses (reachability.rs:222-224) is self.unresolved.len(), used only at 242 and in four asserts where .len() reads the same.

(e) −3: the print guard duplicates the report's own empty check (capture.rs:3219-3223). unresolved_report already returns an empty Vec when occurrences == 0 (reachability.rs:232-235), so:

for line in reach.unresolved_report(&output.index.ranks[0].functions) {
    eprintln!("export: rank {}: {line}", request.rank);
}

Kept deliberately: the order field and its sort at 247-248 (dropping it would change which ten examples print), and the Option<&mut Vec> sink at 283-288 (removing it makes callers longer than it saves — a wash, not a subtraction).

4. Nit — 3 lines: the reporting rule is documented twice (docs/runtime-core-design.md:154-157 and :339-341)

Both paragraphs say the same thing: aligned argument values in gaps/inactive ranges are reported per rank on stderr without retaining inactive storage. One sentence in each is the most the two contexts need; the second is the one the reviewer asked for, so trim the first.

What I checked and dropped

Open questions


Verdict: should not be merged The change: +599 / −37 lines, 4 files Could remove: about 200 lines with no behaviour lost, in 15 places; about 350–450 lines if cut to what the maintainer asked for Biggest subtractions: