Subtraction and simplicity report · NVIDIA/hyperflare-inference #332

Raw Markdown for agents: https://autobot.eidonix.com/p/c8e90029-b8ad-4068-9622-fb2e6d1c67a4.md

Subtraction, Simplicity & Conventions — PR #332 (38805ba3)

Key findings

The diff is largely lean and idiomatic. I found no dead code, no unused flags or config knobs, no speculative generality, and no duplicated repo helper introduced by this PR. Four changes are worth making, in descending value:

  1. reachability.rs:254-282 — example selection is three passes, a parallel chosen bool vector, and a sort_unstable() that only undoes pass 2. Replaceable with one partition loop + truncate. HIGH.
  2. capture.rs:3294-3296 — the new report loop bypasses the StartupProgress channel used by every neighbouring message, writes for every rank (non-zero ranks are otherwise silent), and repeats "export: rank N: " on each of up to 11 lines. HIGH (also a convention issue).
  3. reachability.rs:50-72, 221-230 — four pub(crate) items with pub fields have no caller outside the module. Drop the visibility. MEDIUM.
  4. docs/TODO.txt:357-361 — 5-line entry restates the PR body's Limitations where AGENTS.md:517-520 asks for brief entries. LOW.

Nothing in the diff should be deleted in place of a correctness fix: the correctness-lens targets (raw &request.inactive at capture.rs:3239, candidate() as a bool at reachability.rs:153-170) are live logic, not workarounds to remove, so this lens does not recommend removal there.


1. HIGH — Collapse the three-pass example selection into one partition pass, and use Option for the symbol key

heliopause/src/export/reachability.rs:254-282, verbatim:

        let mut examples: Vec<_> = self.unresolved.iter().collect();
        examples.sort_unstable_by_key(|(_, entry)| entry.order);
        let limit = UNRESOLVED_EXAMPLES.min(examples.len());
        let mut selected = Vec::with_capacity(limit);
        let mut chosen = vec![false; examples.len()];
        let mut seen_symbols = HashSet::with_capacity(limit);
        for (index, &(_, entry)) in examples.iter().enumerate() {
            if selected.len() == limit {
                break;
            }
            let symbol_key = functions
                .get(entry.first.function)
                .map_or(Err(entry.first.function), |function| {
                    Ok(function.symbol.as_str())
                });
            if seen_symbols.insert(symbol_key) {
                selected.push(index);
                chosen[index] = true;
            }
        }
        for (index, already) in chosen.iter().enumerate() {
            if selected.len() == limit {
                break;
            }
            if !already {
                selected.push(index);
            }
        }
        selected.sort_unstable();

Three separate mechanisms exist only to coordinate each other: chosen exists only so pass 2 can skip pass-1 members, and selected.sort_unstable() at :282 exists only to undo pass 2's append order. But examples is already in encounter order (the order field is assigned as unresolved.len() at :178 and read at :255), so a single pass that partitions into "new symbol" and "repeat symbol" reproduces the same output. Replace :254-282 with:

        let mut examples: Vec<_> = self.unresolved.iter().collect();
        examples.sort_unstable_by_key(|(_, entry)| entry.order);
        let mut ordered = Vec::new();
        let mut backfill = Vec::new();
        let mut seen_symbols = HashSet::with_capacity(UNRESOLVED_EXAMPLES);
        for (index, &(_, entry)) in examples.iter().enumerate() {
            let symbol = functions.get(entry.first.function).map(|f| f.symbol.as_str());
            if seen_symbols.insert(symbol) { ordered.push(index) } else { backfill.push(index) }
        }
        ordered.extend(backfill);
        ordered.truncate(UNRESOLVED_EXAMPLES);
        ordered.sort_unstable();
        let selected = ordered;

This removes chosen (a Vec<bool> of one entry per distinct address — 2,646 allocations-worth of flags per rank on the author's sample), the limit binding, and all three selected.len() == limit breaks. Behaviour is identical: the capped set is the same, and sort_unstable() over the truncated set yields the same encounter-order presentation. The existing test unresolved_report_prioritizes_distinct_kernel_symbols_before_backfilling (:1030-1141, asserting lines[1..11] contents and the " … 2 more distinct addresses (5 occurrences) not shown" tail at :1102-1105) covers exactly this, so the rewrite is verifiable by the suite that ships with the PR.

Secondary, same block: map_or(Err(entry.first.function), |f| Ok(f.symbol.as_str())) builds a Result<&str, usize> purely to have a total key. Option<&str> (as in the replacement above) says the same thing and matches what :294 already prints for a missing function — function.map_or("unknown", |f| f.symbol.as_str()). The only semantic change is that two different out-of-range function indices collapse into one None bucket instead of two Err(n) buckets; those all render as kernel unknown (unknown) anyway, so the printed examples are unchanged unless two distinct unresolved addresses both have invalid function indices and would otherwise have been shown separately — a case the report text does not distinguish and no test pins.

UnresolvedEntry.order (:60) and the sort at :255 are not flagged: they are the price of HashMap<u64, …> storage and are the cheapest way to get encounter order.

2. HIGH — The new report loop leaves the StartupProgress channel and repeats the rank prefix per line

heliopause/src/export/capture.rs:3294-3296, verbatim:

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

Context in the same function: progress is built at capture.rs:2939-2943 as

    let progress = if request.rank == 0 {
        helios_core::startup::StartupProgress::stderr_rows()
    } else {
        helios_core::startup::StartupProgress::silent()
    };

and every other message in capture_rank goes through it — :2944 (Clear disposable storage), the immediately preceding graph_phase.finish(...) at :3290-3293, and the immediately following progress.phase("Capture compiled modules and globals", None) at :3297. Consequences of bypassing it:

Concrete simplification (net subtraction): make unresolved_report return Option<String> instead of Vec<String> — the empty case at :238-242 already computes exactly that — and print once:

    if let Some(report) = reach.unresolved_report(&output.index.ranks[0].functions) {
        eprintln!("export: rank {}: {report}", request.rank);
    }

(join the body lines with "\n " so the two-space indent at :291 is preserved). That removes the loop, removes the per-line prefix, and makes the occurrences == 0 early return at :240-242 express itself in the type.

Constraint to state plainly: the multi-line example list cannot ride a Phase row. helios/src/startup.rs:414-466 renders exactly one row and truncates it to terminal width (:439 truncate(&(label.clone() + &detail), available)), so routing the ten examples through progress.phase(...)/phase.finish(...) would clip them. That is an argument for the single-eprintln! option above, not for leaving the loop as-is. Either way, this diagnostic is now a second informational stderr channel beside StartupProgress; docs/runtime-core-design.md:151-157 describes both in one sentence ("reported on stderr per rank as a non-blocking diagnostic") without saying which channel each uses, so whichever form is kept should be named there.

Convention anchor: AGENTS.md:188-193 (reject unsupported abstractions and churn) and the consistent phase-per-message pattern of the surrounding code; only four eprintln! sites exist in heliopause/src and the other three are errors (transfer.rs:429 (not opened),1160, processes.rs:147 (not opened)) or a test (capture.rs:4158).

3. MEDIUM — pub(crate) on four items with no caller outside the module

heliopause/src/export/reachability.rs:45-72 and :221-230, verbatim (abridged to the declarations):

/// An 8-byte-aligned kernel argument value inside the recorded address envelope
/// that resolves to no active recorded allocation (a gap between allocations or
/// an inactive range). Such a value may be a stale pointer or a numeric constant;
/// argument typing cannot yet distinguish the two, so export reports these for
/// operator review.
pub(crate) struct UnresolvedCandidate {
    pub graph: String,
    pub node: usize,
    pub function: usize,
    pub argument: usize,
    pub offset: usize,
}
/// The call site a kernel argument blob was scanned for. Every occurrence of
/// the same argument bytes is recorded separately so a report can name the
/// graph, node, kernel, and parameter that carried an unresolved candidate.
pub(crate) struct Site<'a> {
    pub graph: &'a str,
    pub node: usize,
    pub function: usize,
    pub argument: usize,
}
    pub(crate) fn unresolved_count(&self) -> usize {
        self.unresolved
            .values()
            .map(|entry| entry.occurrences)
            .sum()
    }

    pub(crate) fn unresolved_unique_addresses(&self) -> usize {
        self.unresolved.len()
    }

A search across heliopause/src shows every reference to these four names is inside reachability.rs itself: UnresolvedCandidate at :59,183 and the test helper :794; Site at :175,196,377 and the test const :787; unresolved_count at :239 and tests :805,826,851,868,1175,1215,1230; unresolved_unique_addresses at :249 and tests :813,828,872,1216,1231. The only member of this family used from outside is unresolved_report, called at capture.rs:3294.

Concrete change: drop pub(crate) from the two structs and two methods and drop pub from the struct fields. Tests live in mod tests in the same file, so they retain access. This is a smaller, more honest surface, and it lets the two 3-4 line doc comments at :45-49 and :64-66 shrink to one line each, since the crate-internal contract being described no longer exists.

Considered and rejected: merging Site into UnresolvedCandidate. They overlap on graph/node/function/argument (:184-188 copies them field by field), but Site holds &'a str to avoid a String allocation per kernel argument on every node of every graph; folding it into the owned struct would allocate on the hot scan path. Keeping the borrowed twin is the cheaper design.

4. LOW — docs/TODO.txt entry restates the PR body's Limitations paragraph

docs/TODO.txt:357-361, verbatim:

[ ] Measure the unresolved kernel-argument diagnostic on a four-GPU DeepSeek
    V4.1 export (issue #266) and an eight-GPU W4A8 MoE export, recording
    per-rank aligned occurrence and distinct-address counts. Close when both
    exports have run on four-GPU and eight-GPU hardware and the per-rank
    counts and printed per-kernel examples have been reviewed.

AGENTS.md:517-520: "Use docs/TODO.txt for miscellaneous follow-up items. Keep entries brief and link to detailed design or performance notes when needed." The last three lines restate, in the repository, the closing rubric that the PR body's Limitations section already carries (unavailable four-/eight-GPU hardware, counts reviewed). Suggested two lines that keep the missing condition and drop the repeated rubric:

[ ] Measure the unresolved kernel-argument diagnostic (issue #266) on a
    four-GPU DeepSeek V4.1 export and an eight-GPU W4A8 MoE export.

Low importance: docs churn only.


Checked and deliberately cleared (the diff is otherwise lean)

So the report is honest about what was not flagged:

Open questions / could not find

  1. Whether the per-rank, per-line output in §2 is intentional. The PR body's table reports per-rank counts, which implies per-rank output is wanted; but the code has no gate matching StartupProgress::silent() for non-zero ranks, and no test exercises capture.rs:3294-3296 (the call site is untested, as previously reported). So changing it to one Option<String> print is currently unguarded by any test — a two-line test on unresolved_report returning None vs Some would cover it.
  2. Whether exceeding 10 distinct symbols makes the §1 rewrite observable. Both implementations cap at 10 and both fill slots with the first 10 distinct symbols in encounter order (then backfill), so I found no behavioural divergence; the existing test :1107-1140 (twelve symbols, sym_10/sym_11 excluded from lines[1..11]) passes under both. If the author intends backfill to be considered before a later distinct symbol, the current code does not do that either, so this is not a difference introduced by the simplification.