Conventions scratchpad · NVIDIA/hyperflare-inference #332

Raw Markdown for agents: https://autobot.eidonix.com/p/b69725c6-8830-4c2f-be87-1ba24531700c.md

#1 [high] Should fix: inactive-range classification duplicated in candidate() and scan()

heliopause/src/export/reachability.rs:131-135 (candidate) and :262-266 (scan) each compute the identical inactive-range predicate: let inactive = self.inactive.partition_point(|&(start, _)| start <= value); inactive > 0 && value < self.inactive[inactive - 1].1 candidate returns Ok(true) for that case; scan recomputes it as in_free_block (line 265) and ORs it into !self.candidate(pointer)? || in_free_block (line 266).

Verified the second copy is logically dead: when in_free_block is true, candidate (called first, and it does not mutate inactive) also returns true, so !candidate is false and the expression reduces to true || in_free_block; when in_free_block is false the expression is exactly !candidate. So !self.candidate(pointer)? || in_free_block == !in_interval_membership(value) always. The duplicate buys nothing and costs a second binary search for every 8-byte window of every kernel argument (millions per graph on the reported exports: 175,329 / 170,544 occurrences).

Why it matters: is exactly the maintainer's open item 2 in the 2026-11-20 review ("One rule, one place. candidate already treats an inactive range as a hit, and scan repeats the inactive lookup ... State that rule once"), and it is the module's own convention: interval predicates are defined once (merge_ranges/subtract_ranges, reachability.rs:12-43) and reused across capture.rs (:23, :1252, :1334, :1408). Two copies of a range predicate invite drift — and capture.rs already has a differently granule-aligned notion of the same thing in live_pieces (capture.rs:1196-1240, alignment applied at :1211-1212), so a third variant is easy to confuse.

Fix: make the classifier return the classification once, e.g. fn classify(&mut self, value: u64) -> ExportResult<Candidate> where Candidate is Inactive | Retained | Unallocated; candidate() keeps its current retention behaviour (reference only for Retained), and scan reports for Inactive | Unallocated. Then delete in_free_block and the second partition_point. Behaviour is unchanged: values in an inactive range are still not retained and are still reported (test kernel_argument_inactive_ranges_are_reported_but_numeric_ranges_stay_lenient, reachability.rs:903-916, keeps passing; note that simply deleting in_free_block and keeping !self.candidate(...) would break it, because candidate returns true for inactive values).

Severity: should fix (blocking per the maintainer's open item, but it is a verified no-op change).

#8 [high] Research summary

Reviewed both changed files (heliopause/src/export/reachability.rs and heliopause/src/export/capture.rs) in context through the conventions-and-duplication lens, against the charter, AGENTS.md, CONTRIBUTING.md, docs/design-review.md, the repo-prose skill, and the maintainer's three review rounds on #332.

Main finding (should fix, and it is the maintainer's still-open 2026-11-20 item 2): the inactive-range predicate is written twice — candidate (reachability.rs:131-135) and scan (reachability.rs:262-266, via in_free_block). I verified from the code that the second copy is logically dead: !self.candidate(pointer)? || in_free_block always equals !candidate, because candidate already returns true for inactive values and does not mutate inactive. So scan pays a second partition_point per 8-byte window for no effect, and the file keeps two copies of a rule that capture.rs already implements a third, granule-aligned way (live_pieces, capture.rs:1196-1240). Fix is to have one classifier return the classification (inactive / retained / unallocated) and delete in_free_block — behaviour-preserving, since deleting the copy alone would break the inactive-range test.

Nits: capture.rs:3137 re-checks unresolved_count() > 0 although unresolved_report already returns an empty Vec; blob (reachability.rs:147-188) clones its cache key up to three times per kernel argument and clones misses in both branches, and the map is still reached through two count accessors (unresolved_count, unresolved_unique_addresses) where one would do; with_count (reachability.rs:455) is a new module-level pluralisation helper where flare-cli and helios both inline the singular/plural suffix; the new per-rank export message is undocumented next to the comparable VRAM-inventory description (docs/model-preparation.md:1471) and the reachability spec (docs/runtime-core-design.md:118-156); and shared_argument_bytes_record_one_example_per_address (reachability.rs:793-807) repeats :751-770 plus :845-870, with two idioms for the same map lookup.

I explicitly cleared several constructs against precedent (HashMap cache swap, explicit order field plus sort, per-rank eprintln! like transfer.rs:429/1152, symbols from the recorded function index, the optional out-parameter on scan) — all consistent. No blocking defect from this lens beyond the still-open duplication item. Findings are in scratchpad entries 1-7.

#9 [high] Summary: PR #332 conventions/duplication review — findings and coverage

PR #332 (mark-yong, head c3cc87e, +434/-30, 2 files). Lens: conventions and duplication. PR state: open, "changes requested" from yatesdr across three rounds (2026-11-18, 2026-11-19, 2026-11-20). Items 1-4 of the latest round are the live ones; items 2 (one rule, one place for the inactive range) and 4 (bookkeeping: one map) are the duplication items in this lens.

File coverage: heliopause/src/export/reachability.rs read in full (1-988, including all new tests); heliopause/src/export/capture.rs read at the changed site (3133-3141) plus its surrounding function (2760-3230), the function-index construction it depends on (2824-2998), encode_kernel (816-896, which writes node.function = index), live_pieces (1196-1240), prepare_allocations (1395-1429), Downloader::for_each/consume (1080-1172), and the module preamble (1-40). Rules read: AGENTS.md, CONTRIBUTING.md (DCO only), docs/design-review.md, docs/runtime-core-design.md:55-200, docs/model-preparation.md:1440-1500, .agents/skills/repo-prose/SKILL.md.

FINDINGS CARRIED (detail in the numbered entries):

  1. Should fix — inactive-range predicate duplicated in candidate and scan; the scan copy is provably dead. (entry 1, same title)
  2. Nit — capture.rs:3137 guard duplicates unresolved_report's own empty check. (entry 2)
  3. Nit — blob clones its cache key up to three times per call, clones misses in both branches, and two count accessors for one map. (entry 3)
  4. Nit — with_count (reachability.rs:455) is a new pluralisation helper where the repo inlines suffixes. (entry 4)
  5. Nit — the new per-rank export message is undocumented next to model-preparation.md:1471 / runtime-core-design.md:118-156. (entry 5)
  6. Nit — duplicate/overlapping new tests and two lookup idioms. (entry 7)
  7. No finding — constructs verified consistent with precedent. (entry 6)

VERDICT for the report: no blocking convention defect of its own; the only item in this lens that a maintainer has called blocking is the duplicated inactive-range rule (finding 1), which is a verified no-op change. Nothing in the diff duplicates an existing helper that should have been reused outright (kernel_symbols is gone; merge_ranges/subtract_ranges are still the shared range primitives).

Caveats to state honestly in the report: cargo test/clippy were not run (no tooling access here), and the two-graph report-ordering and singular hidden-count cases are asserted only in tests I read, not ran. The claim that !candidate || in_free_block == !candidate rests on reading candidate (reachability.rs:131-145): it reads self.inactive and may call self.reference, which never mutates inactive; a unit test that asserts reporting of an inactive value while also asserting no retention would settle it if a reader wants proof beyond reading.

#11 [high] Rerun 2 (head 1ac7073d): prior should-fix resolved; remaining are nits

Verified at head 1ac7073d (4 files, +599/−37). Re-read heliopause/src/export/reachability.rs 1-1252 and capture.rs 3030-3260 (changed site :3184, :3219-3223) plus its context (:1259-1303 live_pieces, :3164 Reachability::new).

RESOLVED since my 2026-11-25 report (do not repeat these as findings):

REMAINING NITS (all verified, none blocking):

  1. capture.rs:3219-3223 guard if reach.unresolved_count() > 0 repeats unresolved_report's own empty-return contract (reachability.rs:230-235, doc comment :226-229, test :989-993). Drop the if and iterate the returned lines; the same function advances its phases unconditionally (:3215-3224).
  2. reachability.rs:172-194 blob rebuilds and clones its cache key ((data.to_vec(), numeric.to_vec()) for the probe at :174, moved again on insert at :191) and clones the whole misses vector on both the hit branch (:175) and the insert (:191), once per kernel argument per graph node. The replaced HashSet insert made exactly one copy of the same key. Repo precedent for lookup-then-use without rebuilding the key: Downloader::for_each (capture.rs:1092-1160) reuses its slots; range primitives merge_ranges/subtract_ranges (reachability.rs:12-43) exist to avoid recomputation.
  3. reachability.rs:215-224 two accessors for one map: unresolved_count() (one production caller capture.rs:3219, one internal :232, five test callers) and unresolved_unique_addresses() (one internal :242, four test callers) where self.unresolved.len() and the values().map(..).sum() are one-liners. Related duplication of a type: Site (:67-72) and UnresolvedCandidate (:50-56) carry the same four fields, with the graph name cloned from one into the other (:202).
  4. reachability.rs:824-839 shared_argument_bytes_record_one_example_per_address is subsumed by unresolved_report_bounds_examples_and_counts_hidden_occurrences (:876-905), which already feeds one node to graph-a and graph-b, asserts the graph-a first site and 24 occurrences / 12 distinct addresses; :782-802 covers the per-address count assertions. The tests also mix two idioms for one map, the first() helper (:760-762) plus direct reach.unresolved[&address] indexing (:799-800, :836-837). Fold the graph-name assertion in and keep one idiom.
  5. (weakest, presentation) reachability.rs:487-493 with_count is a module-scope pluralisation helper; the repository convention is an inline suffix at the message — flare-cli/src/cache_commands.rs:307/309/600/602/612, flare-cli/src/doctor.rs:365/812, flare-cli/src/inspect.rs:888, helios/src/runtime_core/model.rs:619. The only other module-scope free functions here (merge_ranges/subtract_ranges) are cross-module primitives.

Constructs re-checked and still consistent: blobs as HashMap<key, misses> (module already imports HashMap and HashSet, :8); explicit order field plus sort_unstable_by_key (:57-61, :248) matching capture.rs:598; per-rank eprintln!("export: rank {rank}: ...") matching transfer.rs:429/1152 with the rank label that rank-0-only progress rows cannot give; kernel symbol from the recorded function index (:252-258, wire::Function documented at capture.rs:3076-3081) rather than the removed kernel_symbols map; optional out-parameter on scan (:283-287) rather than the crate's FnMut visitor, required because scan mutates self and returns ExportResult.

Caveats: no cargo test/clippy run here; every claim above is from reading the code at 1ac7073d.

#12 [high] Research summary

Reviewed PR #332 at head 1ac7073d (4 files, +599/−37) through the conventions-and-duplication lens: read heliopause/src/export/reachability.rs in full (1-1252), the changed site in capture.rs (:3184, :3219-3223) with its surroundings (:3030-3260) and the live_pieces/Reachability::new callers (:1259-1303, :3164), plus the two docs files. Rules read: AGENTS.md, docs/design-review.md (not opened), docs/runtime-core-design.md, docs/model-preparation.md, docs/TODO.txt.

Nothing blocking, and the one should-fix from my previous turn is now resolved: the inactive-range rule is stated once (candidate, reachability.rs:153-170, returns Ok(false) for inactive and gap values and Ok(true) only after retaining a live interval; scan :294-304 just tests !self.candidate(pointer)?, and in_free_block no longer exists). The alignment filter sits in the reporting path only (:300) while retention stays byte-by-byte, the earlier documentation gaps are filled (runtime-core-design.md:154-157 and :339-341, pending measurement in docs/TODO.txt:350-354), and the summary/hidden-count wording is corrected and test-pinned.

Four nits remain, all verified in the code: a caller guard that repeats unresolved_report's own empty-return contract (capture.rs:3219); blob cloning its cache key and the whole misses vector per kernel argument (reachability.rs:172-194) where the replaced HashSet insert made one copy; two accessors over one map plus a Site/UnresolvedCandidate field-for-field pair (:215-224, :50-72); and a duplicating test with two lookup idioms (:824-839 versus :876-905). A fifth, weaker nit is the new module-scope with_count pluralisation helper (:487-493) where flare-cli and helios inline the suffix. Seven other constructs were compared with their precedents and are consistent. Caveat: I did not run cargo test or clippy; all claims are from reading the code at this commit.

#2 [medium] Nit: caller guard duplicates unresolved_report's own empty check

heliopause/src/export/capture.rs:3137-3141: if reach.unresolved_count() > 0 { for line in reach.unresolved_report(&output.index.ranks[0].functions) { eprintln!(...) } } Reachability::unresolved_report (reachability.rs:205-210) already returns an empty Vec when occurrences == 0, and its doc comment (201-204) says so. The caller therefore repeats the callee's precondition, and the two can only disagree if one changes.

Convention in the same function: phases are driven unconditionally and the callee decides what to emit (graph_phase.finish(...), capture.rs:3133; progress.phase), and unresolved_report_is_empty_without_candidates (reachability.rs:872-876) already pins the empty result as the module's contract. So the guard is redundant; drop the if and iterate the returned lines.

Severity: nit.

#3 [medium] Nit: blob cache clones its key three times per call and keeps two count accessors

heliopause/src/export/reachability.rs:147-188 (blob) introduces a cache shape with no precedent in this module and duplicates the existing dedup key handling by hand:

Also duplicated fact: unresolved_count (190-195) and unresolved_unique_addresses (197-199) both scan/size the same map and both exist only to be summed into the same report line (211-221). unresolved_count() is called twice per report (also capture.rs:3137). The maintainer's 2026-11-19 item 4 asked that the miss lists, counts and example list collapse into "one map from address to its first site and occurrence count"; the map is now one, but the two accessors are still two ways to ask about the same collection. unresolved_unique_addresses() has exactly one production caller (line 217) and one test (747/762/806) — inlining self.unresolved.len() there and keeping unresolved_count removes the second wrapper.

Severity: nit (performance nit for the key cloning; naming/duplication nit for the second accessor).

#6 [medium] Checked and consistent: no finding for these constructs

Constructs checked against repository precedent and found consistent (no finding):

#13 [medium] Nit: caller guard duplicates unresolved_report's own empty check (capture.rs:3219)

Severity: nit. heliopause/src/export/capture.rs:3219-3223

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

What is wrong: Reachability::unresolved_report (heliopause/src/export/reachability.rs:230-235) already returns an empty Vec when occurrences == 0, and says so in its doc comment (:226-229); test unresolved_report_is_empty_without_candidates (:989-993) pins it. The guard repeats the callee's contract, walks the map twice (once here, once at :232), and the two can only disagree if one side changes.

Why it matters: two copies of one precondition in a function that otherwise lets its callees decide what to print — the neighbouring phases are advanced unconditionally (:3215-3224), and the repo's convention is that a report function owns its own emptiness (reachability.rs:211-214 of the pre-rebase version did the same).

Fix: drop the if and iterate the returned lines.

#14 [medium] Nit: blob() clones its cache key and misses vector per kernel argument (reachability.rs:172-194)

Severity: nit. heliopause/src/export/reachability.rs:172-194 (cache declaration :85)

What is wrong: blob builds let key = (data.to_vec(), numeric.to_vec()) (:173), probes self.blobs.get(&key) (:174) — a second look at the same owned key — clones the cached misses vector on a hit (:175), and on a miss moves the key into insert after cloning misses again (:191). So per kernel argument per graph node the cache key bytes are copied twice and the misses vector is cloned in both branches. The construct it replaced (blobs: HashSet<(Vec<u8>, Vec<(usize, usize)>)>, if !self.blobs.insert((data.to_vec(), numeric.to_vec())) { return Ok(()) }) copied the key exactly once and cloned nothing.

Why it matters: this runs on the export path the PR reports as ~22.6k occurrences / 762 distinct addresses per rank over thousands of nodes; the miss list is re-cloned for every node that shares identical argument bytes, which is the common case the cache exists for.

Precedent: the crate's lookup-then-use pattern reuses what it built — Downloader::for_each (capture.rs:1092-1160) reuses slots rather than rebuilding them — and merge_ranges/subtract_ranges (reachability.rs:12-43) exist precisely to avoid recomputing interval work.

Fix: insert only on the miss branch and return a slice/reference from the hit branch so misses is not cloned; hash once (e.g. key on a digest) or keep the key borrow alive across the probe. Presentation/performance only; no behaviour at stake.

#4 [low] Nit: new module-level pluralisation helper rather than inline suffixes

heliopause/src/export/reachability.rs:455-461 adds fn with_count(count: usize, one: &str, many: &str) -> String purely for the new report, with two call sites (215, 218) and one usage for the hidden count (242). No precedent exists in the repository, so this is a new construct; the closest in-repo conventions are:

Note the helper has no unit test of its own; it is only exercised through the two report tests (reachability.rs:833-836 singular, :862-864 plural) and the plural-only hidden-count path (:869). That is adequate coverage, so this is presentation-only.

Severity: nit.

#5 [low] Nit: the new per-rank export message is not documented where the export's other messages are

The new diagnostic is user-visible export output, but no repository document describes it. Precedents that document exactly this kind of export printout:

AGENTS.md:52-60 requires documents to state the designed behavior, and the repo-prose skill (.agents/skills/repo-prose/SKILL.md:26-29) says documentation is a present-state specification, so a newly printed export message belongs in the same place the VRAM inventory is specified. As written, a reader of model-preparation.md cannot know that an export may print export: rank N: kernel argument scan: ... lines, or that they are non-blocking, which is the single most important thing about them (the message body does say the values may be stale pointers or numeric constants, but nothing says the export still succeeds).

Fix: one short paragraph next to the VRAM-inventory description in docs/model-preparation.md stating what the scan reports, that it does not fail the export or retain the inactive storage, and its blind spots (values outside the recorded envelope and values that alias live storage are not reported) — matching the limitations the PR description already lists.

Severity: nit (documentation completeness; the maintainer's open review items do not ask for it).

#7 [low] Nit: duplicate test for distinct-address counting and two lookup idioms in tests

Test-side duplication in heliopause/src/export/reachability.rs. The maintainer already flagged this class of problem in the 2026-11-18 review item 6 (a test that "repeats what unresolved_examples_are_capped_while_occurrences_are_counted ... already proves"), and the same shape is back:

Fix: fold the graph-name assertion into unresolved_examples_are_capped_while_occurrences_are_counted (call graph twice and check graph-a on the first site) and drop shared_argument_bytes_record_one_example_per_address; pick one access idiom.

Coverage gaps worth naming (not duplicates): no test asserts the report's order ordering across graphs beyond graph-a/graph-b first-site, and nothing tests with_count's singular form for the hidden-count line (only the plural … 14 more occurrences not shown, :869).

Severity: nit.