Explore scratchpad · NVIDIA/hyperflare-inference #691

Raw Markdown for agents: https://autobot.eidonix.com/p/5637fb57-b9cd-460f-9538-9d925a4f1bd0.md

#1 [high] Change: what PR #691 does, size, files

PR #691 "helios/server: report reused prompt tokens in continuous_usage_stats chunks", author jcartu (CONTRIBUTOR), opened 2026-12-02 20:54, head ef45ca9, base main, branch fix/continuous-usage-cached-tokens. Fixes #448. 6 files, +868/−40. No reviews, no CI checks on head, no discussion comments yet.

Plain terms: with stream_options: {include_usage, continuous_usage_stats}, intermediate Chat/Completions SSE chunks reported prompt_tokens_details.cached_tokens: 0 until the final chunk. This PR makes the reused-prefix count known at first-token time and writes it into the encoder's per-choice usage, so every later chunk carries it.

Files (from pr_files):

#2 [high] Why: issue #448, its repro, and yatesdr's confirmation

#448 "continuous_usage_stats intermediate Chat chunks report cached_tokens: 0 although the docs promise cumulative counts", by shieldstar, opened 2026-11-21 18:26, updated 2026-11-21 18:38, labels: area:api, bug. Still OPEN.

Repro: with stream_options: {include_usage: true, continuous_usage_stats: true}, intermediate chunk reports prompt_tokens_details.cached_tokens: 0 while final chunk reports 3 for the same generation. Reported at upstream commit 25b49519, encoder unit test only (no GPU). Cites docs/api.md:806-812 (cumulative promise) and docs/api.md:781-784 (cached_tokens definition), encode.rs:618-640 (usage_value), encode.rs:589 (Chat finish), http.rs:491 / :516-545.

Note: at main now, the docs lines have moved: cumulative promise is docs/api.md:1039-1045 ("Each emitted chunk carries cumulative native token counts... The final usage chunk is also emitted"), Messages caveat docs/api.md:1030-1032, cached definitional text near docs/api.md:1020-1029. usage_value is encode.rs:755-788 at main; cached sum is encode.rs:763-768.

Suggested fix in the issue gives the maintainer two options: fill cached when the prefix decision is made, or amend docs/api.md to call cached final-only. Only comment: yatesdr 2026-11-21 18:38 confirms by reading at main 21a40f05 that cached_tokens is filled only in Encoder::finish (encode.rs:566-570), and notes docs promise cumulative counts without saying which fields, while documenting the Messages message_start limit but not Chat.

Link: https://github.com/NVIDIA/hyperflare-inference/issues/448

#3 [high] Change: diff map of #691 (runtime.rs, encode.rs, http.rs, tests)

PR #691 diff (verified by reading the patches).

helios/src/server/runtime.rs (+69 −24):

helios/src/server/protocol/encode.rs (+5 −0): Encoder::report_cached_tokens(index, cached) writes self.usage[index].cached (encode.rs:288-292). Nothing else.

helios/src/server/http.rs (+36 −6):

helios/src/server/runtime/response_lifecycle_tests.rs (+1 −1): mechanical observe_token(1) → observe_token(1, 0).

Tests added: protocol/tests.rs continuous_usage_reports_cached_tokens_before_finish (Chat+Completions × cached 0/9), continuous_usage_multi_choice_reports_first_choice_cached_tokens_per_prompt (4 choices, 2 prompts; sibling 9 must not overwrite first-choice 5; cumulative 8). phase_tests.rs: continuous_usage_streams_report_reused_prompt_tokens_and_preserve_messages (real Worker+RequestScheduler, warms a 13-token prefix, then Chat hit/miss, Completions n=2, Messages start/delta), completions_continuous_usage_tracks_staggered_first_choice_readiness, chat_continuous_usage_preserves_initial_cached_tokens_across_preemption (park/readmit, includes the case where live.reused_prompt_tokens() changes to 13 after readmission while the reported count must stay 0). Also updated disabled_host_store_preserves_decode_prefix_reuse_and_cancellation to assert first_token payload == 13.

#4 [high] Related work: #692, #548, #560 collide with #691 in http.rs/runtime.rs

Overlapping work in the same files (all open, none merged on top of each other):

Precedent for the feature itself: continuous_usage_stats was introduced by Martin Vit in commit 6ad1582b (2026-10-18) "Report cumulative native token usage in completion streams"; cached_tokens for Chat/Completions predates it (encode.rs:1014 docs text).

#5 [high] Change: what the diff does that the description does not say

Facts a reader cannot get from the description, verified in the diff and surrounding code:

  1. Generation::wait_for_first_token now returns Ok(0) (silently zero cached tokens) when the receiver has already been taken (runtime.rs:159-164), instead of erroring. Undeclared default.
  2. observe_token_with is fallible and its closure calls self.scheduler.request(handle)? (runtime.rs:2011-2016). A stale/retired handle at first-token time now propagates an Err out of Worker::complete, whose run loop (runtime.rs:1238-1241) returns it and then fail_alls every request (runtime.rs:3036-3051). Before the change observe_token was infallible. Existing code in the same loop already uses scheduler.request(...)? (e.g. runtime.rs:1986, 2088), so this matches local style, but it is a new failure path in the first-token report that the description does not mention.
  3. Chat path reports cached tokens only for index 0 and then pending_cached.clear() (http.rs:414-430); the count is only ever written for a choice index that usage_value reads (step_by(choices_per_prompt), encode.rs:763-768).
  4. The Completions pending_cached drain happens only on GenerationEvent::ObservedToken (http.rs:509-526), which only exists when the request was submitted through generate_many_observed (http.rs:330-331, chosen when continuous_usage). So the mechanism is coupled to that submission path; no new event, output_event_capacity unchanged — description is accurate here.
  5. pending_cached is seeded from (0..size).step_by(decoded.request.choices) and filtered by generations[i].is_some(), so max_tokens: 0 inputs (moved to zero, http.rs:311-315, 453-466) are never polled; their cached stays whatever finish(i, …, 0, 0, …) writes, i.e. 0 — consistent with docs/api.md:1059-1061.
  6. The PR does not touch docs: docs/api.md:1014-1017 (cached_tokens definition), 1030-1032 (Messages message_start/delta caveat), 1039-1045 (continuous_usage_stats cumulative promise) are unchanged. The issue offered "fix code OR amend docs"; the PR fixes code, so no documentation update accompanies the behavior change.
  7. Echo frames for Completions are emitted before the event loop (http.rs:437-452), so they necessarily carry cached=0; the description calls this out.
  8. Encoder::report_cached_tokens is a plain field write with no validation that index < usage.len(); the field is later overwritten by Encoder::finish (encode.rs:703-707) with the authoritative reused_prompt_tokens from GenerationEvent::Finished.
  9. Test-weight: of +868 lines, 634 are in runtime/phase_tests.rs, 108 in protocol/tests.rs → ~86% of added lines are tests.
  10. response_lifecycle_tests.rs change is mechanical (observe_token(1) → observe_token(1, 0)), as is ~100 lines of signature churn in runtime.rs's own test module.

#7 [high] Project fit: charter, AGENTS.md four-part PR rule, TODO.txt rule

Charter (read_charter) mapping:

#10 [high] Claims and evidence: what is backed, what is self-reported, what is missing

Each claim vs. what backs it (all evidence self-reported; nothing run by this review, no CI checks exist on ef45ca9):

CLAIMED: "cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server: 1821 unit tests passed (47 ignored), 62 integration tests passed (36 ignored), 0 failed."

CLAIMED: flare 246 tests, flare-cli 219 tests, and verification/helios-lifecycle/check.py all pass, including ResponseLifecycle 868,192 states / 117,991 distinct / 365,508 Rust transitions.

CLAIMED: "Every Chat streaming chunk … reports the finalized cached_tokens count" — backed by phase_tests.rs:8646-8666 (real Worker + RequestScheduler, 13-token prefix warm, asserts every chunk == 13) and protocol/tests.rs:1415-1466.

CLAIMED: "retains that initial count across post-token preemption and readmission" — backed by chat_continuous_usage_preserves_initial_cached_tokens_across_preemption (phase_tests.rs:8869-9074), which also covers the nastier variant where the readmitted request's live reused_prompt_tokens() changes to 13 while the streamed count must stay 0.

CLAIMED: "Multi-choice … without letting sibling choices overwrite a prompt's admission count" — backed by protocol/tests.rs:1471-1521 and phase_tests.rs:8756-8866 (sibling emits reused=9 before first choice's 5; sibling 7 after 3; cumulative 8).

CLAIMED (limitation, disclosed): "no GPU or exported-core live serving test was run." Consistent with the tests being CPU Fixture-based; tests/server/*.py live SDK tests (e.g. tests/server/test_protocols.py:196-259 test_cached_usage_buffered_and_streaming) were not run and do not cover continuous_usage_stats at all (search for continuous_usage_stats in tests/: no matches).

GAP: no evidence addresses latency/allocation cost of the added per-token pending_cached.retain scan while representative first choices are pending (http.rs:509-523). The list shrinks to empty, so the cost is bounded by the number of prompts, but no measurement is presented and the description only claims "eliminating scanning once all representative first choices have started."

#6 [medium] Project fit: the documented cumulative-usage contract and the admission invariant

Verified facts about the contract the PR relies on:

#8 [medium] People: author standing, area owners, no engagement yet

Author: jcartu (GitHub association CONTRIBUTOR), Discord jcartu. In the last 180 days: 3 merged, 3 closed, 10 open. Merged work in these areas: #418 "Add strict function-tool schemas for DSML, Qwen, GLM and TML parsers" (merged, helios/src/server/http.rs + protocol), #416 "Refresh host prefix-cache recency on request completion" (merged, runtime.rs), #505 "Bind core-declared FP32 parameters into text forward graphs" (merged). So they have landed changes in exactly the files this PR touches (items_touching for helios/src/server/http.rs and runtime.rs).

Who usually works in these areas: helios/src commits in the last 180 days by Luke Alonso (237), Martin Vit (52), yatesdr (49). Martin Vit authored the continuous_usage_stats feature (commit 6ad1582b, 2026-10-18). yatesdr confirmed the bug in #448 and is the author of many runtime.rs scheduler/cache PRs (#674, #663, #628, #459, #415, #176, #167, #333).

Engagement so far on #691: none. Zero comments, zero reviews, no CI checks on head ef45ca9, opened and last updated same timestamp 2026-12-02 20:54. Notably, the repo's flare-autobot reviewer (which auto-reviews other PRs, e.g. #560 within ~30 minutes of opening) has not yet posted on #691.

People who would care: #448 reporters (shieldstar, plus yatesdr who confirmed); users of gateways/early-cancel streams (context: #551/#552/#560 are about llama-swap reading usage fields); jcartu themselves.

#9 [medium] Recent activity: scheduler/cache churn on the same day, no rebase drift

Recent activity in helios/src (default branch, last 60 days per orientation packet, and verified commits):

#11 [medium] Reach: wire-visible change for streaming clients, zero config impact

Who/what is affected:

#12 [medium] Process: ready-for-review, no CI, no reviews, merge-order hazard