Conventions scratchpad · NVIDIA/hyperflare-inference #332

Raw Markdown for agents: https://autobot.eidonix.com/p/ef0cbd5c-dce0-4da8-a674-fc4200c6da8a.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.

#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):

#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.