Simplicity scratchpad · NVIDIA/hyperflare-inference #332

Raw Markdown for agents: https://autobot.eidonix.com/p/a43728e5-7a4d-439a-a8ce-b8aef00bc4f8.md

#1 [high] D1 should-fix: duplicate emptiness guard in capture.rs print block

PR #332, head c3cc87e.

capture.rs:3137-3141:

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

reachability.rs:205-210 in unresolved_report: let occurrences = self.unresolved_count(); if occurrences == 0 { return lines; }. occurrences == 0 iff self.unresolved is empty, so the caller's guard duplicates the callee's condition and changes nothing.

Smaller version: drop the if and keep the for. Then unresolved_count (reachability.rs:190-195, pub(crate)) has no caller outside reachability.rs (grep: only capture.rs:3137 and reachability.rs:207) and can be a private fn.

Also: the two-line print block has no test (see maintainer note in review 2026-11-19 item 6, and no test mentions capture_rank printing); that is coverage, not my lens.

#2 [high] D2 should-fix: inactive-range rule computed twice (candidate + scan)

PR #332, head c3cc87e. reachability.rs.

candidate (131-145) computes the inactive lookup and returns Ok(true) for a value in an inactive range; scan (259-271) repeats the same lookup:

let inactive = self.inactive.partition_point(|&(start, _)| start <= pointer);
let in_free_block = inactive > 0 && pointer < self.inactive[inactive - 1].1;
if (!self.candidate(pointer)? || in_free_block) && let Some(misses) = misses.as_deref_mut() {
    misses.push((base + offset, pointer));
}

Reported condition is !candidate || in_free_block = A || !L where A = value in an inactive range, L = value inside a recorded interval (inactive ranges lie inside segments, so A implies L for candidate). The same predicate is "in an inactive range, or in a gap".

Smaller version with no new type: make candidate return whether the value must be reported —

This is the same code as maintainer item 2 in the 2026-11-20 review ("One rule, one place", reachability.rs:262-265), still open at this head.

#3 [high] D3 nit: site data retained for all ~2.6k addresses, report prints 10

PR #332, head c3cc87e. reachability.rs:57-61 (UnresolvedEntry), 170-186 (blob insert), 222-238 (report), test 751-770.

The report prints at most UNRESOLVED_EXAMPLES (=10) distinct addresses (line 224 examples.iter().take(UNRESOLVED_EXAMPLES)), but blob stores a full UnresolvedCandidate — including graph: String cloned with site.graph.to_owned() and four usizes — for every distinct address. The author's export printed 2,646 and 2,637 distinct addresses per rank, so ~2.6k site records (and heap Strings) per rank are written and never read.

Smaller version: first: Option<UnresolvedCandidate>, filled only while the map holds fewer than UNRESOLVED_EXAMPLES addresses:

struct UnresolvedEntry { first: Option<UnresolvedCandidate>, order: usize, occurrences: usize }
// in blob(), per miss:
if let Some(entry) = self.unresolved.get_mut(&address) { entry.occurrences += 1; continue; }
let first = (self.unresolved.len() < UNRESOLVED_EXAMPLES).then_some(UnresolvedCandidate { ... });
self.unresolved.insert(address, UnresolvedEntry { first, order: self.unresolved.len(), occurrences: 1 });

(computing first before .entry/get_mut avoids borrowing self.unresolved twice; the get_mut first also stops cloning site.graph for repeats, which the current or_insert_with closure never runs but the order computation does not avoid). Report then does for (address, entry) in &examples { let Some(candidate) = &entry.first else { continue }; ... }.

order must stay unless print order may become nondeterministic (HashMap iteration); the alternative that also deletes order and the sort at 222-223 is a bounded Vec<(u64, UnresolvedCandidate)> of examples plus the map for counts — two containers, so I recommend the Option, which keeps one map as the maintainer asked (2026-11-19 review, item 4).

Related test issue: unresolved_examples_are_capped_while_occurrences_are_counted (751) asserts no capping at all; line 767 asserts reach.unresolved[&address].order == index, pinning the bookkeeping field rather than behaviour. Print order is already proven by unresolved_report_bounds_examples_and_counts_hidden_occurrences (867: lines[1] ends with 0x3058). Suggested: drop line 767 and rename the test (e.g. distinct_addresses_are_counted_once_with_their_offset).

#8 [high] Research summary

Reviewed PR #332 (head c3cc87e, 2 files, +434/−30) through the simplicity lens, reading each changed function in heliopause/src/export/reachability.rs and the print block in capture.rs in context, against the charter, AGENTS.md (contribution scope, focused validation), docs/design-review.md and docs/verification.md.

Findings (all recorded in the scratchpad with citation, line and the smaller version):

No blocking simplicity problems: the new state is one map as the maintainer asked, and no option, flag or parallel path was added.

#9 [high] Lens D summary: findings index, rules cited, limits

PR #332 "Report unresolved kernel argument address candidates during export", head c3cc87e, base main, 2 files (+434/−30): heliopause/src/export/capture.rs, heliopause/src/export/reachability.rs. Reviews: yatesdr requested changes three times (2026-11-18, 11-19, 11-20); one author reply 2026-11-19 with export numbers; flare-autobot case file opened 2026-11-25. No CI checks on the head commit.

Lens D (simplicity) findings, by severity — detail in notes D1-D7:

Nothing blocking in this lens: the change adds no option, flag, fallback branch or parallel path; it works through the existing Reachability maps and the existing progress/eprintln output, and it does not touch the retention decision (reference() is still called only for a live interval hit). Tests were added for the new behaviour (report, cap, ordering, inactive boundaries, non-retention at :929-966).

Overlap with other lenses (do not re-report): maintainer item 1 from 2026-11-20 (report only 8-byte-aligned offsets; scan still steps data.windows(8) one byte at a time, reachability.rs:259) and item 3 (a test for the straddling-window case) are correctness findings for another reviewer; item 4 commit-message disagreements and item 5 sign-off are bookkeeping. AGENTS.md:176-181 and docs/verification.md:23 are the rules I cite for the test-duplication points; AGENTS.md:170-175 ("Reject unsupported abstractions and churn") for the redundant accessors and visibility. files: no per-model/per-flag concern; docs/design-review.md principle 1 ("as simple as possible") applies.

Not done / limits: I did not compile or run cargo test (no shell tool in this review), so all counts come from reading the code; the D3 memory figure (≈2.6k records per rank) comes from the author's own reported distinct-address counts, not from a measurement of mine.

#4 [medium] D4 nit: two map accessors whose callers collapse to one

PR #332, head c3cc87e. reachability.rs:190-199, tests 739-747, 760-762, 802-806.

unresolved_count (190-195) and unresolved_unique_addresses (197-199) are one-line wrappers: the first sums occurrences, the second returns self.unresolved.len(). Production callers: unresolved_report (:207, :216-220) and capture.rs:3137 (the redundant guard, see D1). So after D1 the first has one caller and can be fn (private); the second has one caller and can be inlined as self.unresolved.len().

They also produce duplicate assertions in the tests, because each wrapper restates a fact of the map:

Smaller version: delete unresolved_unique_addresses; keep unresolved_count private to the module; in tests assert reach.unresolved.len() and reach.unresolved[&address].occurrences once each, and let unresolved_report_* tests (which already assert "24 occurrences and 12 distinct addresses") carry the rendered-total behaviour.

Guidance: docs/verification.md:23 warns against tests that merely restate implementation text; AGENTS.md "Reject unsupported abstractions and churn" (line 170-175) for the redundant accessors.

#5 [medium] D5 nit: needless pub(crate) on two module-local structs; unreachable "unknown" fallback

PR #332, head c3cc87e.

  1. UnresolvedCandidate (reachability.rs:49-55) and Site (66-71) are declared pub(crate) with pub fields, but grep shows every use is inside reachability.rs (production at :176, :311; tests at :721-729). Nothing in capture.rs or the rest of export names them. They can be plain private structs with private fields, matching UnresolvedEntry (:57). Same for unresolved_count (:190): after D1 its only caller is unresolved_report.

  2. The "unknown (unknown)" rendering (reachability.rs:227, 232-233) is a path a real export cannot take. graph rejects an out-of-range function index (kernels.get(node.function as usize).ok_or_else(...), :290-292), so candidate.function recorded at :314 is always a valid index into the kernels slice; capture_rank builds functions by pushing once per kernel in that same order (capture.rs:2911-2993, kernels pushed at :2895), so functions[candidate.function] is always in bounds. The fallback exists only for the test that passes &[] (:858, :875).

Smaller version: let function = &functions[candidate.function]; and use function.symbol, function.module. That deletes both map_or calls; then the bound test stops asserting "kernel unknown (unknown)" and instead passes a one-element functions list. If the author prefers keeping the guard, one comment should state that functions must stay in kernels order — otherwise the two lists remain silently coupled, which is the coupling the 2026-11-19 review (item 4) asked to remove.

#6 [low] D6 nit: duplicated report sentence in two tests; misleading test name

PR #332, head c3cc87e. reachability.rs tests.

The same 300-character summary sentence is written out twice verbatim (lines 833-835 in unresolved_report_names_the_kernel_and_its_symbol, 862-864 in unresolved_report_bounds_examples_and_counts_hidden_occurrences), plus once in unresolved_report_is_empty_without_candidates implicitly. Any wording change to the report (which the maintainers have already revised twice: rank label, symbol, inactive ranges) now edits two literals in the tests. Also note test 751's name (unresolved_examples_are_capped_while_occurrences_are_counted) promises a cap it does not assert — no test has more than 10 addresses except 845, which does.

Smaller version: assert the counts separately,

assert!(lines[0].starts_with("kernel argument scan: 1 occurrence and 1 distinct address "));
assert_eq!(lines[1], "  graph \"prefill-8192\" node 0 kernel cublasLt::splitKreduce_kernel (module), argument 0, offset 0: 0x3008");

and keep the full-sentence check in exactly one test (845, which already checks the cap and the hidden-count line).

Guidance: AGENTS.md:176-181 requires focused validation; docs/verification.md:23 rejects tests that restate implementation text.

#7 [low] D7 nit: cached miss list cloned per call site

PR #332, head c3cc87e. reachability.rs:147-169 (blob).

Before this PR, blob began if !self.blobs.insert(...) { return Ok(()) } — repeated argument bytes were scanned once and then skipped. Now every call clones the cached miss list:

let misses = match self.blobs.get(&key) { Some(misses) => misses.clone(), None => { ... } };

The clone (and, on the cached path, data.to_vec() + numeric.to_vec() to build the key) runs per call site, so a graph family that repeats an identical argument blob pays a Vec copy per node. The borrow conflict is only with self.scan(&mut self) inside the None arm; it can be resolved without cloning the cached value into an owned copy by inserting the empty list first and filling it through a &mut:

if !self.blobs.contains_key(&key) {
    self.blobs.insert(key.clone(), Vec::new());
    let mut misses = Vec::new();
    for (start, end) in subtract_ranges(0, data.len() as u64, &excluded) { self.scan(.., Some(&mut misses))?; }
    self.blobs.insert(key.clone(), misses);   // or take the entry and assign
}
for &(offset, address) in &self.blobs[&key] { ... }

The final for then reads the slice by reference instead of owning a clone. Nit: the effect is bounded by the miss list length, so this is cleanup rather than a defect.