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

Raw Markdown for agents: https://autobot.eidonix.com/p/5e0f6bbf-e337-4d88-af03-1e93df73bef8.md

#2 [high] Finding 1: example selection is two passes + parallel bool array + resort

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();

Why it's more than needed: examples is already in encounter order, so the second pass exists only to backfill, the chosen bool vector exists only to remember pass-1 membership, and selected.sort_unstable() at :282 exists only to undo the pass-2 appending. Equivalent, ~10 lines:

    let mut preferred = Vec::with_capacity(UNRESOLVED_EXAMPLES);
    let mut backfill = Vec::new();
    let mut seen = 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.insert(symbol) { preferred.push(index) } else { backfill.push(index) }
    }
    preferred.extend(backfill);
    preferred.truncate(UNRESOLVED_EXAMPLES);
    preferred.sort_unstable();
    let selected = preferred;

Also removes let limit = ... and the three selected.len() == limit breaks. Behaviour is identical (encounter order of shown lines preserved, capping preserved).

Secondary in the same block: map_or(Err(entry.first.function), |f| Ok(f.symbol.as_str())) builds a Result<&str, usize> purely to have a total HashMap key. Option<&str> says the same thing and matches what line :294 prints for a missing function ("unknown"); the only change is that two different out-of-range function indices share one "unknown" bucket, which is what the report text implies anyway.

Note: order (reachability.rs:60, assigned let order = unresolved.len() at :178) and the sort at :255 are the cost of HashMap storage; keeping them is fine.

#4 [high] Finding 3: new stderr loop bypasses StartupProgress 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: capture_rank builds progress at capture.rs:2939-2943 as let progress = if request.rank == 0 { StartupProgress::stderr_rows() } else { StartupProgress::silent() }; so every other message in this function is a Phase row via progress.phase(...) / phase.finish(...) (:2944, :3246-3293, :3297). Non-zero ranks are otherwise silent (same pattern in binding.rs:409-415). The new loop ignores that: it writes to stderr unconditionally for every rank, and prepends "export: rank {n}: " to each of up to 11+ lines because it has no per-rank report object.

Two containable fixes, either is a net subtraction: (a) keep the raw eprintln! but emit once — unresolved_report returns Vec<String>; joining it (or returning Option<String> from unresolved_report) collapses N writes into one and keeps the rank prefix on a single line: if let Some(report) = reach.unresolved_report(&output.index.ranks[0].functions) { eprintln!("export: rank {}: {report}", request.rank); } (requires the report body lines to lose their two-space indent, or keep join("\n ")). (b) route it through the existing channel: let phase = progress.phase("Report unresolved kernel arguments", None); phase.finish(summary) for the summary and eprintln only for peer ranks. Caveat to state plainly: helios/src/startup.rs:414-466 renders one row and truncates it to terminal width (:439 truncate), so the multi-line example list cannot go through a Phase row as-is — which is an argument for (a), not (b).

Whichever is chosen, the diagnostic is a second informational stderr channel alongside StartupProgress; docs/runtime-core-design.md:349-354 describes both in one paragraph, so the split should be named there or removed.

#7 [high] Research summary

Subtraction/simplicity/conventions lens done for PR #332 (head 38805ba3). Notes saved as scratchpad entries 1–6.

Four findings, ordered by value:

  1. heliopause/src/export/reachability.rs:254-282 — example selection is three passes, a parallel vec![false; examples.len()] (chosen), and a final selected.sort_unstable() that only undoes pass 2's appending. Since examples is already in encounter order, one partition pass plus truncate is behaviourally identical in ~10 lines. Same block: map_or(Err(f), |f| Ok(f.symbol.as_str())) builds a Result<&str, usize> as a HashMap key where Option<&str> (matching the "unknown" printed at :294) is simpler.
  2. heliopause/src/export/capture.rs:3294-3296 — the new loop bypasses the StartupProgress channel that every neighbouring message in capture_rank uses (capture.rs:2939-2943, 2944, 3246-3293), writes to stderr for every rank (non-zero ranks are otherwise silent()), and repeats "export: rank {n}: " on each of up to 11+ lines because the report is a Vec<String>. Returning one Option<String> collapsed, or using a Phase for the summary, removes the repeated prefix and the second informational channel; noted the hard constraint that helios/src/startup.rs:414-466 truncates a Phase row to terminal width, so the example list itself cannot ride a row as-is.
  3. reachability.rs:50-72, 221-230 — UnresolvedCandidate, Site, unresolved_count, unresolved_unique_addresses are pub(crate) with pub fields but have no caller outside the module (only unresolved_report is called from capture.rs:3294); dropping the visibility narrows the surface and lets two 3-4 line doc comments shrink.
  4. Minor, docs: docs/TODO.txt:357-361 re-states the PR body's Limitations paragraph where AGENTS.md:517-520 asks for brief entries.

Explicitly cleared as not subtraction targets (to keep the report honest that the code is otherwise lean): the blobs miss-cache replay (:196-219) and record_unresolved split, with_count (no existing repo pluralization helper), scan's base/Option<&mut Vec> params, the two docs edits, and the larger test block. No duplication of an existing repo helper found, and nothing in the diff warrants deleting rather than patching a correctness issue.

#8 [high] Report skeleton: verdict, ordering, and lens dispositions

Verdict for this lens: the diff is largely lean and idiomatic; no dead code, no speculative flags, no wrapper/enum fallbacks, no duplicated repo helper. Four changes worth making, one of them (finding 2) also a convention issue. Nothing should be deleted outright in place of a correctness fix; the correctness lens owns the inactive/candidate() questions and this lens does not touch them.

Report order (highest value first):

  1. reachability.rs:254-282 — collapse three-pass example selection + chosen bool array + redundant sort_unstable into one partition pass with truncate(UNRESOLVED_EXAMPLES); and symbol_key as Option<&str> instead of Result<&str, usize>. [note 2]
  2. capture.rs:3294-3296 — new stderr loop outside the StartupProgress channel: per-rank unconditional write, repeated "export: rank N: " prefix per line; fix by returning one Option<String> (or a Phase row for the summary only, blocked for the example list by helios/src/startup.rs:414-466 truncation). Convention anchor: capture.rs:2939-2943 (non-zero ranks silent()), capture.rs:2944/3246-3293 (all neighbouring messages via phase). [note 3]
  3. reachability.rs:50-72 & 221-230 — drop pub(crate)/pub from four items with no out-of-module caller; shrink the doc comments accordingly. [note 4]
  4. docs/TODO.txt:357-361 — 5-line entry restating the PR body's Limitations; AGENTS.md:517-520 wants brief entries. Suggested 2-line rewrite. [note 5]

Also stated in the report: what was checked and cleared — blobs miss-cache replay + record_unresolved (buys occurrence counting, not removable for free), with_count (no existing pluralization helper in the repo; only definition is the new one), scan(base, Option<&mut Vec>) params, the two docs edits, the 28-test block, UnresolvedEntry.order. Merging Site into UnresolvedCandidate was considered and rejected (borrowed &'a str avoids a String allocation per kernel argument). [note 6]

Evidence basis: only files in the PR + helios/src/startup.rs, AGENTS.md, .agents/skills/repo-prose/SKILL.md were read to establish conventions; no build/test was run (this lens is static). Grep facts to cite: with_count appears only at reachability.rs:521 (no repo helper); unresolved_count/unresolved_unique_addresses/Site/UnresolvedCandidate appear only inside reachability.rs with unresolved_report as the single external entry point (capture.rs:3294). [note 1]

#1 [medium] Lens scope + repo conventions checked

Lens: Subtraction, Simplicity, Conventions for PR #332 (head 38805ba3). Files read: heliopause/src/export/reachability.rs (full changed regions), heliopause/src/export/capture.rs:2925-2960 & 3230-3310 & 4140-4170, docs/runtime-core-design.md:138-170 & 340-365, docs/TODO.txt:300-361, helios/src/startup.rs:200-360 (Phase/StartupProgress API), AGENTS.md, .agents/skills/repo-prose/SKILL.md.

Conventions that matter here:

#3 [medium] Finding 2: pub(crate) on items with no caller outside the module

reachability.rs:45-72 declares three items pub(crate) with pub fields; reachability.rs:221-230 declares two pub(crate) accessors. grep over heliopause/ shows no caller outside reachability.rs (capture.rs uses only unresolved_report at capture.rs:3294; bindings/tests elsewhere none):

Concrete change: drop pub(crate) from the four items and the pub from their fields; tests live in mod tests inside the same module so they still reach them. Smaller, honest surface; also lets the two long doc comments (:45-49, :64-66) shrink to one line each since the crate-internal contract no longer needs stating.

Verified not duplicated elsewhere: docs/runtime-core-design.md:154-157 and :351-353 are the only doc mentions, so no other module depends on these types.

Note on merging Site and UnresolvedCandidate (both carry graph/node/function/argument; :184-188 copies them field by field): not worth it — Site holds &'a str to avoid a String allocation per kernel argument (one per argument per node per graph), so keeping the borrowed twin is the cheaper design.

#6 [medium] Considered and rejected as subtraction targets

Checked and deliberately NOT flagged, so the report can say the diff is otherwise lean:

  1. blobs: HashMap<(Vec<u8>, Vec<(usize,usize)>), Vec<(usize,u64)>> (:85) plus the replay in blob (:196-219) and record_unresolved (:172-194): a real complexity increase (the value used to be unit), but it buys two things that cannot be had for free — dedupe of repeated argument-blob scans (the whole point of the original HashSet) and occurrence counting for re-encountered sites. Deleting the replay would drop shared-blob occurrences from the tally that the PR body reports, so it is not a simplification of equals. The associated fn taking &mut HashMap is a legitimate borrow-splitting workaround for self.blobs.get + self.unresolved.
  2. with_count (:521-526): no existing repo pluralization helper (grep: only this one), so it is not duplication; two-literal call sites are slightly verbose but the alternative ({} occurrence(s)) is worse prose under .agents/skills/repo-prose/SKILL.md.
  3. scan's new base: usize + Option<&mut Vec<(usize,u64)>> params (:317-322, predicate :330-337, callers :209-215 and :436-444): the None/0 callers (scan_spans, allocation contents) keep the contents path from reporting, which is the stated contract; no wrapper or flag enum was added, so the parameter is the cheapest expression of it.
  4. docs/runtime-core-design.md +8/-2 (:151-158, :349-354): states present behaviour in present tense, no chronology. Fine.
  5. The new test block (:761-1344, 28 tests in the module) is large but each test names a distinct reporting property; no speculative scaffolding or ignored tests added. Not flagging test volume.
  6. UnresolvedEntry.order + the sort at :255 — cost of HashMap storage, keep.

#5 [low] Finding 4 (minor): 5-line TODO entry restates the PR body's Limitations

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 entry restates the PR body's Limitations paragraph (unavailable four-GPU/eight-GPU hardware) in the repository, which AGENTS.md:57-60 pushes out of design docs and the prose skill (:39) says TODOs should do by naming the missing condition and the removal criterion. Suggested two lines:

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

That keeps the missing condition and drops the restated closing rubric. Low importance: docs churn only.