Simplicity report · NVIDIA/hyperflare-inference #332

Raw Markdown for agents: https://autobot.eidonix.com/p/801be1ae-43d7-4ad3-8daa-380f1d92cb97.md

Lens D (simplicity) review — PR #332 "Report unresolved kernel argument address candidates during export"

Head reviewed: 1ac7073d (4 files, +599/−37). Lens D only; other lenses are other reviewers'. Everything below was read in the code at that head. Rules cited: docs/design-review.md:16 ("Keep Helios as simple as possible"), AGENTS.md:188-193 (reject unsupported abstractions and churn; refactoring must remove a demonstrated source of defects or cost), AGENTS.md:194-199 (focused, meaningful validation), docs/verification.md:21-23 (covered edits need no new test; "Do not add tests that merely restate implementation text or assertions").

Key findings


Should fix

S1. heliopause/src/export/capture.rs:3219-3223 — the emptiness guard repeats the callee's own early return

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

unresolved_report already returns an empty Vec when there is nothing to say: it computes let occurrences = self.unresolved_count(); and returns immediately on occurrences == 0 (reachability.rs:231-235). Every entry carries occurrences >= 1 (reachability.rs:195-211 increments or inserts with occurrences: 1), so "sum is zero" and "map is empty" are the same condition — the caller's guard can never disagree with the callee, and iterating an empty vector is free.

Why it matters: it is a second statement of one invariant in a second file, so a later change to the report's own emptiness rule has to be mirrored here or the two drift; it is also the sole reason unresolved_count is pub(crate) (reachability.rs:215) instead of private (its only other caller, reachability.rs:232, is inside the module). That is exactly the gratuitous public surface and parallel logic AGENTS.md:188-193 asks us to reject.

Fix (smaller version): delete the if and loop unconditionally; make unresolved_count a private fn.

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

Behaviour is unchanged: nothing is printed when there are no candidates.


Nits

N1. heliopause/src/export/reachability.rs:58-62, 195-211, 247-249 — full site record retained for every distinct address, then all of them sorted, to print ten

UnresolvedEntry { first: UnresolvedCandidate, order, occurrences } keeps a String graph name plus four usize fields for every distinct address — 2,646 / 2,637 per rank in the description's four-GPU table, ~762 / ~832 in the author's later aligned run — while the report prints at most UNRESOLVED_EXAMPLES = 10 (:76, :249). Then unresolved_report collects and sorts the whole map (:247-248) to take ten.

Fix: make the retained site optional and fill it only below the cap; the insertion order is preserved by order, so output is identical and the sort shrinks to at most 10 elements:

struct UnresolvedEntry {
    first: Option<UnresolvedCandidate>,
    order: usize,
    occurrences: usize,
}
...
.and_modify(|entry| entry.occurrences += 1)
.or_insert_with(|| UnresolvedEntry {
    first: (order < UNRESOLVED_EXAMPLES).then(|| UnresolvedCandidate { ... }),
    order,
    occurrences: 1,
});
...
let mut examples: Vec<_> = self.unresolved.iter().filter(|(_, e)| e.first.is_some()).collect();
examples.sort_unstable_by_key(|(_, entry)| entry.order);

Hidden counts then come from subtraction (occurrences_total - shown), which removes the examples[UNRESOLVED_EXAMPLES..] slice-sum too (:264-279). This is a cost fix on the export hot path, not a behaviour change; it keeps exactly the ten examples the report prints.

N2. heliopause/src/export/reachability.rs:222-224 — unresolved_unique_addresses has no caller of its own

The accessor is a one-line wrapper (self.unresolved.len()) used once in production — inside the same module, at :242 — plus test assertions at :779, :794, :838, :1068. Each of those four tests already asserts the same quantity one line earlier as reach.unresolved.len() (:772, :793, :835; :1068 sits beside the unresolved.contains_key assertions at :1064-1066), so the wrapper's purpose — naming the number for the report — is served by writing .len() at the one production site. The duplicated assertions are the kind docs/verification.md:22-23 tells us not to add.

Fix: inline self.unresolved.len() at :242 and delete the method; drop the four duplicate assertions (or keep one of the len() forms). Also note unresolved_count's pub(crate) disappears with S1.

N3. heliopause/src/export/reachability.rs:50, 67, 252-258 — pub(crate) on module-local structs, and a fallback that cannot fire in export

UnresolvedCandidate and Site are pub(crate) with pub fields, but both are used only inside heliopause/src/export/reachability.rs (production and its #[cfg(test)] module; SITE at :753 is module-local). Then the kernel name is looked up defensively twice per example:

let function = functions.get(candidate.function);
... function.map_or("unknown", |function| function.symbol.as_str()),
... function.map_or("unknown", |function| function.module.as_str()),

That None arm cannot be reached from export: graph() rejects an out-of-range function index before it ever records a site (:322-324, invalid("graph function index is out of bounds")), and capture.rs:3001-3081 pushes one wire::Function per kernel in node order, moved into output.index.ranks[0].functions at capture.rs:3208, which is the slice the caller passes at capture.rs:3220. Two error strings and a branch exist for a state the type system could exclude.

Fix: drop pub(crate)/pub to module-private on both structs, and index directly:

let function = &functions[candidate.function];
... function.symbol, function.module,

Consequence to accept deliberately: unresolved_report_bounds_examples_and_counts_hidden_occurrences passes &[] (:890) and asserts the resulting kernel unknown (unknown) text (:898). That test currently pins only the unreachable state; give it a real wire::Function (as :848-861 already does) and assert the real symbol. The functions/kernels parallel-order invariant is read from capture.rs, not proven by a test; a test that builds the index through the export path would settle it, and indexing would turn any future violation into a panic at export instead of a silently printed "unknown".

N4. heliopause/src/export/reachability.rs:783, 865-867, 894-896 — the summary sentence is written twice in tests, and the "capped" test does not test the cap

The 300-character summary literal is reproduced verbatim in two tests (:865-867, :894-896), so any wording change to the printed line at :236-246 has to be edited twice. And unresolved_examples_are_capped_while_occurrences_are_counted (:783-802) never calls unresolved_report and uses 12 in-cap addresses, so it asserts nothing about capping; the real cap coverage is :877-905.

Fix: assert the summary line once (keep it in :877-905, the test that also proves capping and the hidden-count line) and rename :783 to what it verifies — e.g. kernel_argument_candidates_record_one_entry_per_address_with_offsets — with the summary assertion removed.

N5. heliopause/src/export/reachability.rs:172-194 — every repeated call site clones the cached miss vector

blob() keys a cache on (data.to_vec(), numeric.to_vec()) and, on a hit, clones the whole vector of (offset, address) pairs; on a miss it also builds the vector inside scan and then clones it again to store (:191). Before this change the equivalent call site returned early, so the clone is new work per repeated argument blob, and the key is re-materialised from the caller's bytes each time. Argument blobs repeat heavily across graph nodes, which is the reason the cache exists.

Fix: keep the original borrow-and-iterate shape the cache was built for — fill the cache in place, then iterate the stored vector — e.g. split the borrow so the miss vector is written through entry/insert and the reporting pass runs over &self.blobs[&key] after the memoisation borrow ends (disjoint fields: self.blobs and self.unresolved need separate borrows, so a small fn remember(&mut self, misses: &[(usize, u64)], site: &Site) keeps both sides simple and turns both clones into one pass). If the borrow split is awkward enough to prefer the clone, that is a defensible choice — but then the double clone on the miss path (:191) should at least go.

N6. heliopause/src/export/reachability.rs:250 and :156-170 — a dead rebind and a name that reads inverted

:250 let address = *address; is dead: the iteration pattern for &(address, entry) in examples.iter() already binds address by value, which is why the line compiles as a self-assignment of a copy. Delete it.

candidate (:156, called at :298 as !self.candidate(pointer)) returns true when the value did resolve to a live allocation and it retained it. Only call site reads !self.candidate(..), so the code reads as "not a candidate" at the point where the value is being pushed as a candidate. Rename to retains (and read !self.retains(pointer)) — a one-word change that removes the double negation. Its doc comment (:153-155) also restates its own three lines of code, which AGENTS.md:190-191's "comment expansion" line covers; one sentence naming the two rejection cases is enough.

N7. heliopause/src/export/reachability.rs:45-49 vs :237-239 vs docs/runtime-core-design.md:154-157 vs :339-341 — one explanation written four times

The same rule ("8-byte-aligned value inside the envelope that resolves to no active allocation — a gap or an inactive range — may be a stale pointer or a numeric constant") appears as the UnresolvedCandidate struct doc, as the printed summary sentence, as a design paragraph, and again as the stderr-phase sentence. docs/runtime-core-design.md:339-341 restates what :154-157 already says, so the docs hunk adds the same fact twice.

Fix: keep the printed line (it is the operator-facing contract) and the design paragraph at docs/runtime-core-design.md:154-157; cut the struct doc to a one-liner and drop the second docs sentence at :339-341, or vice versa. Not a behaviour question — just one fact in four places where one plus the output text would do.

N8. heliopause/src/export/reachability.rs:1130-1131 — an unrelated assertion inside the inactive-boundary test

freed_interval_boundaries_report_kernel_candidates_without_retaining_storage ends each loop iteration with

aligned.reference(&storage.name).unwrap();
assert!(aligned.reached.contains(&storage.name));

That asserts reference stores a name, which is unrelated to inactive-range boundaries and is already covered (:582-583). It also means each of the six loop iterations does work the test's name does not claim.

Fix: delete the two lines; the test then asserts exactly the reachability/reporting partition it is named for.


Open questions / what could not be found