Case file: PR #692 — helios: count output-layer stream failures under requests_failed_total
Key findings
- The defect is a real, operator-reported metric-attribution bug, and the issue that reports it explicitly says only the accounting is wrong, not the behaviour. Issue #679 (ktsaou, 2026-12-02 11:31, labels
area:api/bug/priority:P2/triage:investigate) shows twoserver_errorframes from the ChatML tool parser each tracked 1 s later by aflare_requests_cancelled_totalincrement, withcompleted9046 /cancelled2 /failed0 over the same window, on maina3c80e19. #679 says: "Failing the request is the right behaviour, and this issue does not ask to change it. The bug is only the outcome accounting." - The documented contract already promised the fixed behaviour.
docs/api.md:332and the metric HELP string athelios/src/server/metrics.rs:1092-1095definerequests_failed_totalas "Requests failed by admission, execution, grammar, or output processing". So no doc change is required — butdocs/api.md:700-702still states that aparallel_tool_calls: falsecancellation is counted "cancelled rather than completed, despite the successful API response", which the new deferral can interact with (see "Reach"). - The PR is much bigger than its title implies: a new concurrency state machine in the hot worker path, not a counter move. +1068/−32 across 4 files, but the substance is an
Arc<AtomicU8>RequestOutcomestate machine shared by worker and HTTP consumer (helios/src/server/runtime.rs:109-296), a new deferring entry pointgenerate_for_output(runtime.rs:1145-1151), and rewriting every completion, cancellation and failure site inruntime.rsandhttp.rs. Completion semantics change for all HTTP and Decisions traffic, not just the failing paths. - It silently changes who may call what:
generate_many_observedis deleted andgenerate_observedbecomes#[cfg(test)](runtime.rs:1131-1134), while the observation plumbing inhttp.rs:331-333is re-expressed inline via.then_some(...). The description does not mention either. - It overlaps two open PRs from another contributor that rewrite the same counters. #548 (open, WynnD) and #560 (open, WynnD, stacked on #548) change
metrics.completed/cancelledsites andGenerationEvent::Finishedin the same three files. Notably, #548's review thread (lukealonso, 2026-11-26/28) already flagged a "runtime says cancelled, HTTP returns success" divergence on the parallel-tool-limit path — #692 changes the machinery #548 builds on without touching that documented divergence. - No CI has run on the head commit (348c06c reports no checks), no reviews, no comments, no labels. All test evidence (1,884 helios tests, 254 flare, 245 flare-cli, the full
verification/helios-lifecycle/check.py (not opened) --mutationsrun) is self-reported and unverifiable from the repository, though the tests it points at do exist and are substantial. - The lifecycle-conformance gate in
docs/design-review.md:209-240applies to this change, and the PR reports the run but adds no new TLA+ action or conformance transition for the outcome state machine; theResponseLifecycleharness only exercises the non-deferred half (see "Claims and evidence").
The change
Size and shape (verified). 4 files, +1068/−32, head 348c06c, base main (branched at c513e46), "ready for review":
helios/src/server/runtime.rs+443/−15helios/src/server/runtime/phase_tests.rs+585/−0helios/src/server/http.rs+20/−9helios/src/server/protocol/decisions/mod.rs+20/−8
What it does, in plain terms. Before, the model worker decided the outcome of a request on its own: it bumped completed as soon as generation stopped, bumped cancelled whenever the HTTP reader dropped its channel, and only bumped failed from finish_error. But the HTTP output layer (parser, encoder, tool-call validation) runs after the worker and can still reject the response. Those rejections looked like drop-outs to the worker, so they were counted as cancellations. #692 makes worker and consumer share one atomic outcome word so that exactly one of the three counters increments, once, and only when the side that actually knows the answer says so.
Mechanics, verified in the diff and head files:
RequestOutcome(runtime.rs:109-296):Arc<AtomicU8>withPENDING/GENERATED/READER_DROPPED/COMPLETED/CANCELLED/FAILEDplus adefer_completionflag. Every transition CASes into an absorbing terminal state and performs exactly onemetrics.{completed,cancelled,failed}.fetch_add. No counter is ever decremented.Generationgainsoutcomepluscomplete_output()(runtime.rs:348-350) andfail_output()(:352-357, record FAILED then cancel).Dropcallson_reader_drop()then cancel (:378-383).Incominggainsrecord_cancelled()(:550-552) andemit_finished()(:553-582), which replaces twometrics.completed.fetch_add+emit(Finished)sites: it returns early if a failure is recorded, usesevents.try_reserve(), and onFullfails the request ("generation exceeded its output event budget") instead of completing it.finish_error(:583-595) records FAILED before notifying admission/first-token/event channels — deliberate ordering, since HTTP may drop the receiver as soon as admission errors.- All four worker cancellation sites now call
record_cancelled()instead of touching the counter (runtime.rs:1647-1653,1667-1671,1680-1690,1735-1740). ModelRuntime::generate_for_output(runtime.rs:1145-1151) setsdefer_completion = true;generate/generate_manykeepfalse; everything funnels throughenqueue_many(..., defer_completion)(:1153-1158).http.rssubmits throughgenerate_for_output(http.rs:328-334) and settles generations onFinished:complete_output()on Ok,fail_output()on Err (http.rs:561-566). EveryDelivery::Failedexit aborts the decoder withTermination::ExecutionErrorand callsfail_output(): first-token wait (:402-410), echo apply (:426-434), zero-token finish (:445-450), event-loopErr(e)arm (:582-590). The zero-token arm aborts the decoder only — nofail_output()— because those generations are alreadyNone.decisions/mod.rsscore()switches togenerate_for_output(vec![prompt], None)and settles complete/fail on every exit (:838-886); the previous mid-loopok_or_elsebecomes explicitfail_output()branches.- The
parallel_tool_calls: falsepath is left alone in kind:generation.cancel()still fires onencoder.tool_limit_reached(http.rs:571-575).
What the description does not say that the change does:
generate_observedis now#[cfg(test)](runtime.rs:1131-1134) andgenerate_many_observedis removed outright — an API-surface reduction the description glosses as "removing the single-callergenerate_many_observedwrapper".- The
http.rsobservation decision (continuous_usage || (token_ids && size == 1)) is now computed inline with.then_some(...)(http.rs:331-333), a readability change bundled in. - The decisions
score()path is converted too, beyond the "endpoint" framing.
What the description says that the change does not do: I found no claim in the description that the diff fails to support. The "fail-then-cancel cannot double count" claim does hold: emit_finished/emit's Full arms still set cancelled, but record_cancelled can no longer reach an absorbing FAILED.
The why
Issue #679 (ktsaou, opened 2026-12-02 11:31, zero comments) is the filed report, and #692 declares "Fixes #679" the same day. Its evidence is a journal timeline: Qwen3.8-Flash-Next gb202 TP2, streaming Chat Completions with ChatML tool calls, two server_error entries ("tool parameter names must be nonempty and unique", stage=stream) at 09:00:39 and 09:43:50; counters over the period completed 9046, cancelled 2, failed 0, each cancelled increment 1 s after a journal line. An earlier occurrence on 2bdc8472 was a Responses stream ending "tool function requires parameter or closing tag".
The issue's own code trace at a3c80e19 matches the call chain the PR edits: chatml.rs:136 (not opened) rejects empty/duplicate parameter names → server/output.rs:359-364 (not opened) aborts with Termination::ExecutionError → http.rs yields Delivery::Failed and drops its receiver → runtime.rs's emit() sees TrySendError::Closed and sets cancelled → counted at metrics.cancelled.fetch_add → failed only ever touched in finish_error.
Importance to operators: #541's shipped Prometheus/Grafana example plots only completed and failed, so these mis-attributed cancellations are invisible on the documented dashboard — the practical reason nobody had seen the trend.
Related work
- #548 (open, WynnD) "Add per-request histograms and vLLM-parity request metrics", +1383/−124, changes the same 3 files (
http.rs,runtime.rs,phase_tests.rs). Its review thread (lukealonso 2026-11-28; Autobot 2026-11-26) already identified this split: on the parallel-tool-limit path the terminal event reachesDelivery::Completewhile the runtime only bumpscancelled/finish_cancelled— anddocs/api.md:700-702documents that divergence as intended. #692 rewrites the accounting #548 builds on; neither can land without the other rebasing. - #560 (open, WynnD) "Emit vLLM-compatible per-request metrics from runtime instants", +2185/−163, explicitly stacked on #548 ("the branch stacks all of #548"). It adds
RequestTimestoGenerationEvent::Finished— the exact eventemit_finishednow constructs — so a textual conflict is near-certain; no supersede in either direction. - #691 (open, jcartu, same author, same day) changes the
first_tokenoneshot fromResult<()>toResult<u64>on the veryIncoming/Generationstructs #692 just extended withoutcome, and touches the samewait_for_first_tokencall site (http.rs:402-410). Direct textual conflict between two open PRs by the same author. - #689 (open, jcartu) typed error codes on HTTP preparation failures — same
http.rs/phase_tests.rsarea, no accounting overlap. - #562, #552 (closed, WynnD) earlier per-request-timing attempts superseded by #560/#548. #111 (closed) an older metrics PR on the same 4 files.
- #133 (closed) is not this defect, despite #679 linking it: #133's close-out (eduffd, 2026-10-28→2026-11-08) traced GLM argument-tag rejections to prepared-graph storage lowering, fixed by merged #129; original-el8's close-out says "Malformed tool calls from otherwise valid model output remain a separate parser/API concern." #679/#692 is the accounting defect for genuinely malformed output.
- #549 is a local patch mentioned in #679, unrelated.
Recent activity
helios/src has had heavy same-day churn from other authors (#681, #661, #665, #660, #670, #667, #663, #666 on 2026-12-01/02), none of it touching the four files this PR changes — the orientation packet confirms zero commits on main since the branch point (c513e46) touching these files. So the PR is not racing a conflicting change, only other open PRs.
Of the recent commits, #670 (Luke Alonso, "parameterize THINK_TAGS reasoning, add TAGGED_JSON tool parser") is the nearest neighbour semantically: it grows the set of output parsers whose rejections this accounting must attribute correctly.
People
- Author: jcartu (GitHub association CONTRIBUTOR; Discord
jcartuin the PR body). 3 merged, 3 closed, 10 open in 180 days; merged work is concentrated indocs,helios/src,heliopause/src. This is part of a same-day batch of seven open PRs (#686–#693), several of which touchhelios/src/serverand one of which (#691) textually conflicts with this one. - Area owners: commits to
helios/srcin the last 180 days are Luke Alonso (237), Martin Vit (52), yatesdr (49). Luke Alonso also reviewed #548 in this exact area, so he is the most likely reviewer with prior context on the divergence being fixed. - Reporter: ktsaou, who filed #679 with a precise timeline and code trace and labelled it
priority:P2. - Engagement on #692 so far: none. No comments, no reviews, no labels, no CI checks.
Community
Nothing. pr_comments returns "No comments." No reviews, no reactions, no labels, opened and last updated the same day. Issue #679 also has zero comments before the fix was proposed.
Project fit
- Charter "Solve the right problem in the right place" — fits: a metric-attribution defect with an operator-reproduced root cause, fixed where the counters live, with no new configuration, no new user-visible surface, no per-model branch.
- Charter "Bring real evidence … Bug fixes need to address the root cause" — the mechanism (single absorbing terminal state) does address the root cause rather than retrying or swallowing; #679's trace is the repro.
- Charter "PR descriptions: four parts" — the description has Why / What Changed / Claimed Result / Supporting Evidence and Limitations, so it complies.
docs/design-review.md:209-240(Layer 3) — mandatory: runpython3 verification/helios-lifecycle/check.py(not opened) and mutation testing "whenever changing admission, fences, generations, cancellation, … response buffering or ownership"; and "Modifying the Helios scheduler, admission, speculation, cancellation, cache ownership, completion validation, … without running — and updating when behavior, transitions, or supported bounds change — the applicable TLA+ models, Rust conformance fixtures, Kani harnesses … is a blocking design failure, regardless of whether CPU unit tests pass." This PR changes completion/cancellation transitions; it reports the run but adds no new model action, conformance fixture or mutation guard for the new state machine (see next section).- Kani is correctly skipped: no completion-vector or state-view validator was touched (
docs/design-review.md:221-225). - The runtime/model-agnostic rule is not engaged (no per-model branch added).
Claims and evidence
Claimed and self-reported (unverifiable from the repository; head 348c06c has no CI checks):
cargo test --release --features runtime-core,serveron helios: 1,884 passed / 0 failed / 84 ignored (lib 1,822/47; 14 integration binaries 62/37).- flare: 254 passed / 4 ignored; flare-cli: 245 passed / 3 ignored.
verification/helios-lifecycle/check.py (not opened) --tla-jar … --mutationsexit 0: 8 TLA+ models, 365,508 Rust transitions againstResponseLifecycle.tla(states=65989 edges=365508 depth=10), 13 TLA+ mutations, 26 Rust guard mutations, 1 observed-edge safety violation detected (DispatchRing SlotReuseSafe).- Environment caveat given: Linux CPU, chat templates via
FLARE_TEST_TEMPLATE_DIR, 512 MiB locked-memory limit because parallel Engram staging tests exceed 64 MiB.
What does back the claims: the test code exists and is substantial. Two unit tests in runtime.rs (terminal budget overflow and deferred drop orderings; a 2-thread Barrier test over 3×3 worker/consumer pairs × both defer modes × 128 iterations asserting exactly one counter increment) plus four tokio HTTP↔Worker integration tests at phase_tests.rs:8437-9020 (ChatML duplicate-parameter rejection on chat/messages/responses; mid-stream and at-EOS rejection after worker completion, streaming and buffered; genuine client disconnects on four routes; normal completion across four routes × stream and an n=2 fail/sibling-cancel case).
Gaps in the evidence:
- The lifecycle conformance harness
helios/src/server/runtime/response_lifecycle_tests.rs:100-195drivesgenerate_many/emit/cancel/faildirectly, i.e. only thedefer_completion = falsehalf of the new state machine. The deferred (HTTP/decisions) half — the half the PR exists for — has no conformance transition. Perdocs/design-review.md:241-245, added protocol states are supposed to extend the model. - Not run and not disclosed as such: the Python integration suites that encode the current counter expectations —
tests/server/test_protocols.py:676(cancelled rises on ann=4disconnect),tests/server/test_decisions.py:230-261(decision disconnects increment cancelled),tests/server/test_deepseek41.py:78-79(not opened) andtests/server/test_scheduler.py:176-177(not opened) (failed flat while completed rises). These are the closest existing coverage of exactly the counters whose semantics change. - Disclosed as not run: 84 ignored helios / 4 flare / 3 flare-cli checkpoint- and GPU-gated tests, live GPU serving via
flare run, Kani. - No performance or benchmark claims are made, so the charter's benchmark rule does not apply.
Reach
- Operators /
/metricsconsumers: the only user-visible effect. Mid-stream output failures now log underfailedinstead ofcancelled; deferred requests whose reader drops after the worker finished but before output validation now countcancelledwhere they previously countedcompleted; terminal event-budget overflow now countsfailedinstead ofcompleted. Any dashboard ratio or alert built oncancelled/completedshifts. #541's Grafana example does not plotcancelled, which hides both the bug and part of the fix. - No wire, config or default change: no request/response schema change, no new flag, no default moved.
docs/api.mdandmetrics.rsHELP strings are untouched — valid, because the documented meaning already matched;docs/api.md:700-702's parallel-tool-limit note remains true only where the drop lands inGENERATED, and #692 does not update it. - Internal API:
generate_observedbecomes test-only andgenerate_many_observedis deleted;generate_for_outputis the new required entry point for anything that produces user-visible output.generate/generate_manykeep immediate completion for SDK-style and test callers. - Capacity: the PR asserts response admission-capacity retention and
ResponseLifecycle.tlaproducer/reader ownership invariants are unchanged.emit_finished'stry_reserve()ordering (reserve, then record completion, then send) is the mechanism by which the budget can no longer hide a completion — worth a reviewer's eye, since it is the one place where a full channel now turns a completion into a failure. - Dependencies / deployment: none touched.
Process
- State: open, "ready for review" (not draft), opened and last updated 2026-12-02, head
348c06c, basemainatc513e46with no intervening touches to these files. - CI: no checks reported on the head commit.
- Review: none requested or given; no labels; no comments.
- Age: same-day; part of a seven-PR batch from the same author.
Open questions / not found
- Whether the
docs/design-review.md:234-240"blocking design failure" clause is satisfied by runningcheck.py(not opened) without extendingResponseLifecycle.tla/conformance fixtures for the newPENDING→GENERATED→COMPLETED/CANCELLED/FAILEDtransitions — the PR argues no bounds changed; the deferred half of the machine is unmodelled. - Whether the Python
tests/server/*.pycounter assertions (test_protocols.py:676,test_decisions.py:230-261) still hold under deferred completion; they were not run, and if any expectedcancelledon a path that now lands inGENERATED-then-completed/failed, they will need updating. - The merge order and rebase plan against #548, #560 and the author's own #691 — no comment on any of them references #692, and #692 references none of them.
- Whether
docs/api.md:700-702should be amended for the parallel-tool-limit path, which #692 changes the machinery for but not the documented outcome. - Whether the
emit_finishedtry_reserve()-before-record_generated()ordering can leave a request inGENERATEDif the reserved slot is later lost — the tests coverFullandClosed, but not a reservation dropped without send. - No maintainer has engaged; there is no signal yet on whether the PR is wanted in this batch, and its conflicts with the WynnD metrics series (#548/#560) are unresolved.