Conventions scratchpad · NVIDIA/hyperflare-inference #540

Raw Markdown for agents: https://autobot.eidonix.com/p/b2c6a476-7eb6-43b4-bce2-d93e2da63deb.md

#1 [high] Should fix: request_copy_match_stats duplicates request_history_proposal_with_match_len

File: helios/src/scheduler.rs:1099-1205. request_history_proposal_with_match_len (1112-1159) and request_copy_match_stats (1163-1205) repeat the same chain: same clamp (maximum.min(completion_token_capacity-1).min(COPY_DRAFT_CAPACITY)), same early exit on maximum == 0 || decoded_history.is_none(), same self.request(handle) lookup, same sam.propose(maximum), same out-of-vocabulary truncation (position(|&t| (t as usize) >= vocabulary)), same shared-ring query via DecodedHistory::lookup_with_match_len(request.tokens(), maximum), and the same "shared ring wins only on strictly longer match" rule. The second function differs only in returning (valid_len, match_len) instead of a padded vector. Precedent: the same PR follows the opposite (correct) pattern in helios/src/scheduler/decoded_history.rs:162-183, where lookup is a two-line wrapper over lookup_with_match_len, and the sole difference is the returned tuple. helios/src/scheduler/rounds.rs powered_curve/expected_speculative_tokens (537-557) also factor a cheap view out of the expensive computation rather than copying it. Risk beyond duplication: the two copies are already not identical. In request_history_proposal_with_match_len the shared-ring result is used unconditionally in the (None, Some(..)) arm (no count > 0 filter), whereas request_copy_match_stats filters .filter(|&(count, _)| count > 0) before the match; a zero-count shared result therefore yields (tokens, 0, 0) in one path and is skipped in the other. Any future fix to the vocabulary clip, the tie-break, or the count == 0 handling has to be made twice. Fix: express one on the other, e.g. request_copy_match_stats calls a shared private helper returning (match_len, valid_len, provider) and drops the padded build (an Option<&MatchProposal>-style return), so the clip and tie-break exist once.

#2 [high] Should fix: wide_copy_curve fallback duplicates CopyCalibration's own prior and is unreachable

File: helios/src/scheduler/rounds.rs:541-553 (wide_copy_curve). The else arm recomputes speculation::WIDE_COPY_PRIOR_RATE.powi(depth+1) over completion_token_capacity-1 depths, which is exactly what CopyCalibration::new(capacity).curve(generated, optimistic) returns when depths are all None (speculation.rs:121-151: prior = rate.powi(depth+1) for the None entry, with rate seeded at WIDE_COPY_PRIOR_RATE). The scoring structure the fix belongs to (wide_copy_curve/expected_copy_tokens wrapping powered_curve/expected_speculative_tokens) is the right precedent, but the fallback curve should live next to its owner. The branch is also unreachable in practice: LiveRequest.sam and LiveRequest.copy_calibration are set together from the same predicate self.decoded_history.is_some() at admission (scheduler.rs:1849-1856), enable_history_drafts must run before admission (scheduler.rs:1086-1092: rejects when self.submitted != Fence(0) || self.admissions != 0), and every caller of wide_copy_curve is already gated on self.decoded_history.is_none() == false (rounds.rs:759). So copy_calibration cannot be None where this arm runs. Fix: delete the else arm and use request.copy_calibration.as_ref().expect(...), or make CopyCalibration::curve the only source and give it a CopyCalibration::prior(capacity) constructor so no caller re-derives the geometric prior. This also removes the second hard-coded use of WIDE_COPY_PRIOR_RATE outside speculation.rs.

#3 [high] Remaining findings: doc staleness, cost.rs repetition, unwired public SAM API

Observations verified in the diff but not fully cross-checked against every convention precedent. Order by confidence. These were collected just before the time limit.

  1. Deviation from convention (should fix) — docs/scheduling-runtime-design.md:7-12 lists the scheduler modules that specify the design (policy.rs, utility.rs, service.rs, cost.rs, refresh.rs, learning.rs, rounds.rs, speculation.rs). The new helios/src/scheduler/sam.rs implements a mechanism the same document specifies (copy proposals, lines 39-41 and 102) but is not added to that module index, so a reader of the design document cannot find the implementation. Fix: add sam.rs (per-request prompt and output suffix automata for copy proposals) to the list.

  2. Deviation from convention (should fix) — docs/mtp-design.md:31-40 describes copy proposals solely as the shared 65,536-token ring with eight- and four-token indexes, and lines 22-29 say history drafting uses "shared decoded history" only. After this PR a request's proposals come first from a per-request prompt+output suffix automaton (scheduler.rs:1099-1159) with a six-token minimum match (sam.rs:22, raised from three) and a 131,072-token prompt plus 131,072-token output cap per request (sam.rs:25-28). docs/cli-design.md:742 likewise says only "shared decoded-history continuations". repo-prose SKILL.md:26-29 requires replacing stale present-state claims rather than layering; this is the file that owns copy-draft semantics.

  3. Nit — helios/src/scheduler/cost.rs:195, 199, 229, 239 plus rounds.rs:756 spell out estimate.draft_source != Some(ProposalSource::Copy) five times. A single small accessor on Estimate (the file already carries Estimate::fresh, cost.rs:111) would match local style and keep the meaning in one place; is_copy_only_step and max_mtp_draft_tokens read from it.

  4. Nit — cost.rs:287-296: refresh_order changed return type to (bool, u64) and lost the doc comment explaining the ordering, which now lives only in docs/scheduling-runtime-design.md:437-441. (true, attempt_ns) meaning "attempted while stale, no valid observation" is not self-evident; neighbouring helpers in cost.rs (lines 21-48, 210-213) carry their invariants in one-line doc comments.

  5. Nit — helios/src/scheduler/sam.rs:1236-1273: the test-only brute_force_oracle returns the production MatchProposal and re-implements build_proposal's source selection and token slicing (sam.rs:1191-1227), so the oracle can drift with production code. Precedent: the oracle helper in helios/src/scheduler/decoded_history.rs:228-252 returns the same plain (Vec<i64>, usize) the production lookup returns. The 120-trial randomized oracle (sam.rs:1402) is only as strong as its independence.

  6. Not a finding — DEFAULT_MIN_MATCH_LEN = 6 (sam.rs:22) and WIDE_COPY_MIN_MATCH_LEN = 6 (speculation.rs:18) are two constants for the same threshold; rounds.rs:776 requires both to pass. Since the SAM default governs the plain --history-drafts packing path too (packing.rs:395-407 → request_history_proposal → SamConfig::default(), sam.rs:53-62), the wide-copy constant could reference the SAM default rather than repeat 6. Neither is wired to a flag, so both satisfy the "no magic defaults" rule only if the value is argued in prose; docs/mtp-design.md currently justifies neither.

  7. Not a finding — helios/src/scheduler/sam.rs module doc (lines 7-17) and public API (PromptSAM::build, PromptOutputSAM::new, SamConfig, MatchProposal, MatchSource) do not use lifecycle labels, follow the SPDX header convention used across helios/src/scheduler/, and add "Flare community contributors" as a second copyright line (matching speculation.rs:3). propose_conditional_continuations and propose_for_context (sam.rs:1070, 1118) are public but have no caller outside the test module; propose_for_context is exercised only by sam.rs:1463. Consuming-only-in-tests public API is the kind of speculative surface AGENTS.md rejects ("Reject unsupported abstractions... Do not add frameworks, extension points... without a concrete requirement"), so this should be raised: either the 2-deep pipelined execution path that needs them lands in this PR, or the two functions and their tests should not ship as pub.