Correctness scratchpad · NVIDIA/hyperflare-inference #548

Raw Markdown for agents: https://autobot.eidonix.com/p/7bbc33d5-dfbe-4aa4-ad71-90470c1d1eb8.md

#1 [high] Should fix: e2e histogram includes cancelled/tool-limited responses, contradicting the stated exclusion rule

helios/src/server/http.rs:631-635 (non-stream) and http.rs:614-617 (stream) observe flare_request_e2e_seconds in the Delivery::Complete arm. That arm is reached for responses whose generation the runtime counted as cancelled: at http.rs:563-567, when encoder.tool_limit_reached, generation.cancel() is called, and the runtime then counts it in metrics.cancelled, never in request_completed (runtime.rs:1343-1364 / 1334-1342). The terminal event still flows through GenerationEvent::Finished → Delivery::Complete → e2e observed.

Why it matters: docs/api.md (new paragraph, lines ~296-311) states "Cancelled and failed requests enter only flare_requests_cancelled_total and flare_requests_failed_total", and the PR description repeats "Cancelled and failed requests stay out of these histograms". For flare_request_e2e_seconds that is not true of the cancelled-by-tool-limit path, so a dashboard comparing flare_request_e2e_seconds_count against the runtime histograms/counters mixes populations.

Fix: gate the observation (e.g. skip when encoder.tool_limit_reached/termination is Cancelled), or narrow the documentation sentence so it covers only the runtime histograms (queue/prefill/decode/tpot/prompt tokens). Verified in code; a test with a tool-limit-reaching request would settle whether e2e is really observed there.

#6 [high] Research summary

Reviewed PR #548 (request latency histograms + Linux process metrics) through the correctness lens: read all 8 changed files in context (metrics.rs, runtime.rs, http.rs, latency.rs, server.rs, process.rs, phase_tests.rs, docs/api.md), followed both request_completed call sites, the reserve_and_pack/complete/publish/park paths, and both HTTP delivery arms, and checked the repo's rules (charter, AGENTS.md, docs/design-review.md).

Two findings worth fixing: (1) flare_request_e2e_seconds is observed on any Delivery::Complete, so responses the runtime counts as cancelled (the encoder.tool_limit_reached → generation.cancel() path at http.rs:563-567, which never reaches request_completed) still land in the e2e histogram, contradicting the new docs sentence and the PR description that cancelled requests appear only in flare_requests_cancelled_total; (2) streaming e2e is only recorded if the client drains the SSE body while the non-streaming path records before the body is polled, an asymmetry that makes flare_request_e2e_seconds_count diverge from flare_requests_completed_total for streamed requests and is not stated in docs/api.md.

Also noted as lower-severity items: first_scheduled_ns is stamped for GraphKind::Vision lanes too (question, may be intended given the docs wording); parse_stat's last-) heuristic returns Some on some malformed comms rather than omitting; process_open_fds counts its own directory read (+1 vs the standard exporter, but the HELP text says so). Verified-correct: the counter and histograms share one function with no leftover direct completed.fetch_add sites, bucket indexing and cumulative rendering are consistent, the non-Linux build of process.rs compiles cleanly (all libc use is Linux-cfg'd), and the JSON snapshot is untouched. Evidence limitation: the live scrape ran on a cherry-pick onto a fork commit, no CI checks exist on the head, and the Windows build and full suite were not run.

#7 [high] Citation sheet for the two findings and secondary items

Finding 1 (Should fix, e2e vs cancelled):

Finding 2 (Should fix, streaming e2e requires body drain):

Secondary items:

Coupling check: Metrics::request_completed at metrics.rs:452-480 is the only increment of completed; the two former sites were runtime.rs:1832 (user/text stop, now 1841-1846) and 1984 (natural finish, now 1993-1998).

#10 [high] Research summary

Verdict on the pushed head (a34c4d06): one new blocking build break, one should-fix counting divergence, otherwise the earlier findings are resolved. (Scratchpad notes #1–#9 describe the pre-push state; note #1 and #2 are now fixed — this report carries the new findings, as only finish was available this turn.)

Blocking (new, introduced by "Exclude cancelled responses and reuse host helpers"):

Should fix (new):

Nits: parse_stat's new state-character allow-list (metrics/process.rs:26, "RSDZTtWXxKPI") silently drops every stat-derived metric if a kernel ever reports another state letter; validating that the following fields parse would bound the same risk without a hard-coded alphabet.

Verified fixed since the last review: the tool-limit exclusion plus the single observation point before yield Delivery::Complete (http.rs:598-606) closes my finding #1, and the new assertion at runtime/phase_tests.rs:4604-4613 pins it; the streaming-drain asymmetry is now stated in docs/api.md:303-306, closing finding #2; the vision-step caveat is documented (docs/api.md:309-311), closing the open question in #3. "Hoist completion values" makes request_completed and the Finished event share prompt_tokens/generated_tokens (runtime.rs:1993-2001 vs :2017-2019), so the histograms and the response usage can no longer disagree. I re-derived parse_stat's index arithmetic (utime field 14 → nth(10), stime 15, starttime 22, vsize 23, rss 24) and it matches the fixture; raise_open_file_limit(0) (eos/src/unix.rs:138-147) returns the current soft limit with no side effect, so process_max_fds is sound; the process_open_fds +1 is now disclosed in its HELP text (process.rs:113).

#11 [high] Blocking: process.rs references feature-gated crate::runtime_core, breaking --features server

BLOCKING (new on head a34c4d06, introduced by "Exclude cancelled responses and reuse host helpers" d64c3ea3).

Evidence:

Fix: move open_descriptors (helios/src/runtime_core/protection.rs:291-302) into eos/src/unix.rs beside page_size (eos/src/unix.rs:73-75) and raise_open_file_limit (:138-165), and re-export it through crate::os — the same route the commit already used for the other two, and where AGENTS.md:20-21 puts host OS operations. Alternatively gate the call on the feature.

Caveat to state in the report: verified by cfg reading only; no compile was possible here and the head has no CI checks. cargo check --manifest-path helios/Cargo.toml --features server settles it immediately.

#13 [high] Research summary

Reviewed PR #548 at head a34c4d06 through the correctness lens. No new commits since the last round, so I re-verified the open findings against the current tree and they all still stand.

Blocking — --features server no longer compiles. helios/src/server/metrics/process.rs:68 calls crate::runtime_core::open_descriptors(), but helios/src/lib.rs:22-26 declares pub mod runtime_core only under #[cfg(feature = "runtime-core")], and helios/Cargo.toml:25's server feature does not enable runtime-core (helios/Cargo.toml:21 is a separate feature). The three references to crate::runtime_core under src/server are now session.rs:10 (not opened) (gated by server.rs:26-29), runtime/prompt_tests.rs:13 (not opened) (gated by #[cfg(all(test, feature = "runtime-core"))], runtime.rs:3983), and this ungated one. The configuration breaks the documented commands at docs/model-development.md:99-100 (not opened) and docs/scheduling-runtime-design.md:735-736 (not opened); CI (.github/workflows/native-serving.yml:63 (not opened),68) only builds runtime-core,server, which is why it is invisible there. Fix: move open_descriptors (helios/src/runtime_core/protection.rs:291-302) into eos/src/unix.rs beside page_size (eos/src/unix.rs:73) and raise_open_file_limit (:138) and re-export through crate::os (helios/src/os.rs:8), the route the same commit already took for the other two helpers, or gate the call. Verification is by feature/cfg reading — the head has no CI checks and I could not compile; cargo check --manifest-path helios/Cargo.toml --features server settles it.

Should fix — e2e exclusion is response-scoped, completions are per generation. helios/src/server/http.rs:598-605 skips the e2e observation when the shared encoder flag encoder.tool_limit_reached (protocol/encode.rs:89, set at :506) is set, but one response can carry several generations (generations: Vec<Option<Generation>>, built per choice at http.rs:351-353; n choices are accepted for /v1/completions, protocol/decode.rs:742-755, and http.rs:299 sizes from prepared.len()). A choice that finishes naturally before a sibling trips the limit is counted by Metrics::request_completed (runtime.rs:1841-1846, :1996-2001) and its queue/prefill/decode/prompt histograms, yet loses the e2e observation for the whole response, so flare_request_e2e_seconds_count < flare_requests_completed_total and the new docs/api.md sentence "Cancelled and failed requests enter only flare_requests_cancelled_total and flare_requests_failed_total" is false for that choice. Fix: decide per finished generation (e.g. skip only when the termination used at http.rs:526 is Termination::Cancelled), and pin it with an n: 2 test where one choice hits the tool limit.

Nit — parse_stat hard-codes the stat state alphabet. process.rs:26 rejects any state letter outside "RSDZTtWXxKPI" and returns None, which silently removes process_cpu_seconds_total, process_virtual_memory_bytes, process_resident_memory_bytes and process_start_time_seconds together, contradicting the module doc (process.rs:4-6) that only unreadable or unparsable sources are omitted. Validating that the five consumed fields parse (utime/stime/starttime/vsize/rss, indices re-derived and matching the fixture) bounds the same risk without a fixed alphabet.

Verified sound in code: Metrics::request_completed (metrics.rs:452-480) is the sole writer of completed, so recomputation of counter and histograms cannot diverge inside the runtime; queue/prefill require first_scheduled_ns/first_token_ns with saturating subtraction, decode and TPOT require generated_tokens > 1, and Incoming keeps its stamps through parking/readmission (runtime.rs:1334-1342, :2106-2121); each process metric renders independently so one bad /proc file never fails a scrape; raise_open_file_limit(0) (eos/src/unix.rs:138-165) only reads the soft limit; all new libc use is cfg(target_os = "linux") with a no-op non-Linux render (process.rs:8-14). Evidence limits: no CI on the head, no compile here, and the author's live scrape ran on a cherry-pick onto a fork commit rather than main.

Earlier findings are fixed on this head: the tool-limit e2e exclusion plus single observation point before yield Delivery::Complete, the documented streaming-drain asymmetry, the documented vision-step caveat, and hoisted prompt_tokens/generated_tokens shared between request_completed and the Finished event.

#14 [high] Report of 2026-11-27, run 2 (post-Autobot-comment, no new commits)

Verdict: blocking. No new commits since the last report (head still a34c4d06); the three findings from note #12 were re-verified line-by-line against the current tree, and nothing new was found. Nine changed files read in context: metrics.rs, metrics/process.rs, runtime.rs, http.rs, latency.rs, server.rs, phase_tests.rs, runtime_core/{mod.rs,protection.rs}, docs/api.md.

BLOCKING (unchanged, #12/#11) — --features server does not compile:

SHOULD FIX (unchanged) — e2e exclusion is response-scoped, completions per generation:

NIT (unchanged) — process.rs:26 hard-coded state alphabet "RSDZTtWXxKPI" → None removes cpu/vsize/rss/start_time together, contradicting module doc process.rs:4-6; validate the five parsed fields instead.

VERIFIED SOUND this round (no finding): metrics.rs:452-480 is the only writer of completed; queue/prefill gated on first_scheduled_ns/first_token_ns with saturating_sub; decode+TPOT require generated_tokens>1 (metrics.rs:470-479); RequestTimes survives parking (runtime.rs:2106-2121, 1334-1342); reserve_and_pack stamps every lane's first scheduled step (runtime.rs:2187-2203, called from submit at :2275); each process metric renders independently (process.rs:62-125); raise_open_file_limit(0) only reads the soft limit (eos/src/unix.rs:138-165); all new libc use is cfg(target_os="linux") with a no-op non-Linux render (process.rs:8-14); parse_stat index arithmetic (utime 14→nth(10), stime 15, starttime 22, vsize 23, rss 24) matches the test fixture at process.rs:141-148.

Evidence limits to state: no CI checks on the head; no compile available here (finding 1 rests on the cfg/feature graph); the author's live scrape ran on a cherry-pick onto fork commit 5ffe4d54, not main; the "merges in either order with #537" claim is asserted, not tested.

#16 [high] Report of 2026-11-27, run 3 (head 055663a, process metrics removed)

Head reviewed: 055663a7.

RESOLVED since last report:

STILL OPEN (should fix): helios/src/server/http.rs:606

VERIFIED SOUND on this head:

Evidence limits: still no compiler here; the cfg/feature claim above is from the file list plus search, which is sufficient since the file is gone.

#17 [high] Research summary

Reviewed PR #548 at head 055663a through the correctness lens. The previous round's blocking build break is gone: commit 54e06b30 deletes helios/src/server/metrics/process.rs (not opened) outright, drops mod process and the metrics::process::render call, and returns open_descriptors to a private fn in runtime_core/protection.rs (not opened), so --features server no longer reaches feature-gated runtime_core. No process_* series remain anywhere in the tree, which also makes the earlier docs nit moot and matches the documentation now shipped in docs/api.md (not opened).

One should-fix finding remains: helios/src/server/http.rs:606 gates the single response_completed call on the response-wide encoder.tool_limit_reached, while generated[] is per choice. In a multi-choice completions response where one choice trips the parallel-tool limit, the sibling choices the runtime counted as completed record no e2e, choice-count, or max-choice-token observation, so flare_request_e2e_seconds_count can diverge from flare_requests_completed_total for a reason docs/api.md (not opened) does not state. Reachability today needs tools plus more than one generation, which the decoder currently rejects for Completions, so it is at minimum latent — same defect class as the earlier cancelled-response finding, fixable by tracking the cancelled indices at http.rs:531-532.

Everything else I checked held: request_completed is still the sole writer of the completion counter, the output_limit derivation matches reason == "length", time histograms stay unobserved for zero-token completions, RequestRecord survives park/requeue with max_tokens set once at first admission and preemptions bumped at the park, cache_lookup_tokens is added at the same site as cache_lookups, the three rejection reasons are wired only at the stated paths with 503s uncounted, and the new documentation statements match the code. Evidence limit: no compiler or live scrape here, and the author's own scrape ran on a cherry-pick rather than main.

#18 [high] Should fix: response-wide tool_limit gate drops siblings' e2e observations — fix options and what settles it

FINDING (should fix): helios/src/server/http.rs:604-612

// One observation per successful response: a tool-limit cancellation reaches
// this point but the runtime counts it as cancelled, so it is excluded.
if !count && !encoder.tool_limit_reached {
    state.model.metrics().response_completed(
        admitted_at.elapsed().as_nanos() as u64,
        decoded.request.choices,
        &generated,
    );
}

Evidence chain:

Fix options:

  1. Track cancelled indices in the stream (set a Vec<bool> or reuse generated with a sentinel when finishing a choice with Termination::Cancelled at http.rs:531-532) and pass only the surviving choices to response_completed; still observe e2e once when at least one choice delivered.
  2. If the behaviour is intended, say so in docs/api.md next to the e2e population text: the whole response is excluded when any choice hits the parallel tool limit, so the e2e count can trail the completion count by the sibling choices too.

What would settle it: a phase test (see helios/src/server/runtime/phase_tests.rs:4303-4370 for the HTTP fixture pattern used by full_http_admission_counts_a_queue_limit_rejection) posting a two-choice completions request with tools enabled and asserting either flare_request_e2e_seconds_count == 2 (siblings counted) or == 0 (response-wide exclusion) against flare_requests_completed_total. Today the request cannot even be built, which is itself the evidence that the path is latent.

#2 [medium] Should fix: streaming e2e depends on the client draining the SSE body, undocumented asymmetry with non-stream

http.rs:600-620: for streaming, the Delivery::Complete(_) arm runs inside the filter_map that back Sse, so flare_request_e2e_seconds is observed only if the client actually polls the stream to its end. A client that disconnects mid-stream (the common cancel path) never reaches it.

http.rs:629-641: the non-streaming path observes e2e in the handler before the JSON body is polled, so it records even when the client never reads the response — the added test first_response_http_nonstream_records_only_when_completed_body_is_offered (phase_tests.rs:4461-4465) asserts exactly that (count 1 for the poll_body == false case).

Why it matters: flare_request_e2e_seconds_count therefore diverges from flare_requests_completed_total for streamed requests (which are the majority for chat), in the opposite direction from the non-stream case, and docs/api.md says only "counts each successful generation from admission to the completed response" — unlike the neighbouring flare_time_to_first_response_seconds sentence, which does say "once the client reads it". The asymmetry is a real, operator-visible property that the docs do not state.

Fix: state in docs/api.md that streaming observations require the client to read to the end, and that non-streaming records at handler completion; alternatively record e2e on the runtime completion path for both. Verified by reading the two arms; the streaming early-disconnect case would need a test.

#3 [medium] Note: first_scheduled_ns is also stamped by GraphKind::Vision lanes

metrics.rs:452-480 request_completed divides decode / u64::from(generated_tokens - 1) for flare_time_per_output_token_seconds. decode is last_token_ns - first_token_ns, i.e. the interval between the first and last committed token. With exactly two tokens the denominator is 1, so TPOT equals the full first→last interval, which is correct-ish; with N tokens it divides by N-1, correct.

However at runtime.rs:1773-1775 the stamps are set inside the per-token loop only for tokens whose active[slot] entry matches a.request == token.request, and last_token_ns is overwritten for every emitted token of that request, including tokens that are then discarded by a stop (stopped.push + continue at 1780-1795 for reasoning/grammar failures, and 1822-1828 for emit_output failure). For a request that fails mid-step the stamps are updated but request_completed is never called, so no divergence in output — the observation is simply skipped, consistent with the doc.

Real edge found: reserve_and_pack (runtime.rs:2187-2203) stamps first_scheduled_ns for lanes of a GraphKind::Vision step too (it loops all step.lanes before the kind == Vision branch). A vision step is not a generation step that "includes the request" for prefill purposes, so for an image request the queue time ends at the vision step rather than at the first prefill step, making flare_request_queue_seconds understate queue delay and flare_request_prefill_seconds absorb the vision work. Worth confirming against how vision lanes are scheduled; the doc says "the first model step that includes the request", which the vision step arguably is, so this may be intended — flag as a question, not a defect, unless the lane kinds say otherwise.

#4 [medium] Nits/notes: process.rs parse heuristics and non-Linux compilation

process.rs:22-31 parse_stat splits on the last ). /proc/self/stat command name cannot contain )? It can — the comm field is parenthesized and may contain ) and spaces; the kernel does not escape them, so taking the last ) is the standard heuristic but is wrong for a process whose name itself ends with ) plus following text (e.g. comm == "a) b" gives tail from the inner )). This is a documented upstream ambiguity (proc(5) says use the last )); it only affects the metrics, never panics, and a misparse would shift all five fields consistently — but parse_stat returns Some rather than None in that case, so the reported CPU/memory would be wrong rather than omitted. The module doc claims a malformed file omits the metric; a systematic offset in the tail is not detected. Low practical impact (flare's own comm is fixed), so nit at most.

process.rs:65-67 process_open_fds counts entries of /proc/self/fd, and the read_dir handle itself is one of them — the code acknowledges this in the HELP text ("including the directory read that counts them"). Prometheus' client_golang excludes it, so the number is +1 relative to the conventional series. Since the HELP text says so, this is a documented deviation, not a defect; worth a nit only if parity with the standard exporter matters.

process.rs:79-114: process_cpu_seconds_total and process_start_time_seconds use (stat[0] + stat[1]) as f64 / ticks as f64; u64 addition can overflow only after ~2^64 ticks, not reachable. rlim_cur is printed via Display for rlim_t, fine.

process.rs:12-13 #[cfg(not(target_os = "linux"))] let _ = text; compiles on Windows — the functions parse_stat, parse_btime, metric, render_linux are all cfg(target_os = "linux"), and libc is a non-optional dependency in helios/Cargo.toml:50, so the non-Linux build of this module references no libc item. The Windows build was not run by the author (stated), but nothing in this file introduces a Windows-only compile error; libc::rlimit/getrlimit/RLIMIT_NOFILE are inside the Linux cfg. No blocking platform finding. Note helios/src/os.rs and dashboard.rs already use libc under unix cfgs, so precedent exists.

#5 [medium] Verified-correct items and evidence limitations

  1. Cherry-picked base. Author states the branch was built on the AzallazA fork commit 5ffe4d54, cherry-picking this change because that model needs the fork's Engram encoding (upstream PR #482). The live-scrape evidence therefore exercises this diff on a fork, not on main; the conflict resolution "kept only the added function". This is disclosed, so not a defect, but the merge-risk claim ("merges in either order" with #537) is asserted, not tested — CI on head has no checks (orientation packet) and the author did not run the full helios suite or Windows build.

  2. Prompt-token histogram includes tokens reused from the prefix cache (metrics.rs help text; docs/api.md). prompt_tokens at runtime.rs:1838-1839 is carried.prompt_tokens.unwrap_or(live.prompt_tokens), which is the full prompt length including reused tokens — consistent with the documented wording. Fine.

  3. Flare_time_to_first_response_seconds histogram lives in FirstResponseSamples (latency.rs:34-37) rather than Metrics, so it is not exposed in the JSON snapshot (server.rs:645-658 returns before render_histogram) — consistent with docs "histograms appear only in the Prometheus text". render_histogram is called at server.rs:671 after the median gauge, before input metrics; no duplicate series names (checked: no other flare_time_to_first_response_seconds).

  4. Histogram rendering emits # HELP/# TYPE and buckets in ascending bound order with cumulative counts from per-bucket atomics; +Inf bucket equals total, and _count uses the same cumulative value, so consistency holds even under concurrent observation only approximately (a concurrent observe between the last bucket load and the _count line cannot happen because cumulative is reused). Sum uses u64 nanoseconds, so a >584-year total would wrap; irrelevant.

  5. Metrics::request_completed is called at both former completed.fetch_add sites (runtime.rs:1841 user/text stop in complete, runtime.rs:1993 natural finish in publish); grep confirms no remaining direct completed.fetch_add in helios/src/server. Counter and histograms therefore cannot diverge for completed requests. Verified against main: the only two sites on main were runtime.rs:1832 and 1984.

  6. Bucket boundaries: position(|bound| exposed <= bound) with the last bound infinite guarantees an index; unwrap_or(N-1) is unreachable. 0.1 etc. are exactly representable enough that 100_000_000 ns → 0.1 s lands in the le="0.1" bucket (test asserts le="0.1" is 0 for 169 ms... actually asserts 250 ms in le="0.25" and 0 in le="0.1"), matching Prometheus convention.

#8 [medium] Rules cited and evidence-limitation notes

Rules the review should cite:

Disclosed limitations in the PR description (accurate as far as I could check): Windows build not run; full helios suite not run; messages_image_hints_end_after_expansion_for_text_and_segmented_templates not run (needs FLARE_TEST_TEMPLATE_DIR from tests/frontend/prepare_templates.py). Live scrape was taken from a cherry-pick of this diff onto AzallazA fork commit 5ffe4d54 (upstream PR #482 dependency), not on main, and that instance also served the authoring agent's own requests, so the reported deltas exceed the three test requests — stated plainly in the description. CI on head ebecef1 has no checks (orientation packet). The claim that this PR and #537 "merge in either order" is asserted, not tested: they touch different functions in metrics.rs (request histograms beside the completion counter here; page gauges beside cached_pages there).

Also worth stating in the report: the author's own histogram observation buckets in the live scrape are consistent with the three-request window only after allowing for session requests (le="64" gained 1, le="2048" gained 4), which the description explains; nothing in that evidence contradicts the code reading.