Repository navigation
Conversation
|
A case file has been opened for 692. Future reviews will auto-run 90 minutes after code updates are pushed.
|
Autobot ReviewFull Review · Value Proposition · Case File Recommendation: Changes RequestedThe core fix for #679 is technically sound — the shared
Walkthrough
Merge Risk: Medium · up to
|
348c06c to
7f29869
Compare
|
@flare-autobot Addressed every review item in
Re-verified on Linux CPU (non-gated templates via
|
Autobot ReviewFull Review · Value Proposition · Case File Recommendation: Ready To MergeCommit
Walkthrough
Merge Risk: Medium · up to
|
7f29869 to
2e9bfa5
Compare
|
Rebased onto |
2e9bfa5 to
1419fcf
Compare
|
Rebased onto Still overlaps #691/#705 at the Discord: jcartu |
When the Helios HTTP output layer rejects a streamed or buffered response—for example, when the ChatML tool parser rejects an empty or duplicate parameter name or rejects an incomplete tool call at end-of-sequence—`http::generate` encodes an error frame, returns `Delivery::Failed`, and drops its `Generation` receiver. Previously, only `Incoming::finish_error` on the model worker incremented `flare_requests_failed_total`, while worker completion eagerly incremented `flare_requests_completed_total` before trailing stop flushes, `GenerationEvent::Finished` channel delivery, or output decoding ran, and worker cancellation incremented `flare_requests_cancelled_total` whenever `cancelled` was set or the event channel closed. As a result, mid-stream output rejections were miscounted as cancellations while `flare_requests_failed_total` stayed zero, output rejections after worker completion or event-budget overflow on terminal events were miscounted as completed requests, and event-budget overflow could increment both failed and cancelled counters when `admit()` subsequently observed `cancelled`. This change introduces an atomic `RequestOutcome` state machine shared between each worker `Incoming` and consumer `Generation` in `helios/src/server/runtime.rs`: - Each request transitions through monotonic atomic states (`PENDING`, `GENERATED`, `READER_DROPPED`, `COMPLETED`, `CANCELLED`, `FAILED`) via a single CAS helper (`RequestOutcome::transition`) and increments at most one of `completed`, `cancelled`, or `failed` without ever decrementing a counter. - `Incoming::emit_finished` runs after scheduler lookup and trailing `stops.finish()` emission, suppresses `Finished` if a prior failure is already recorded, and uses `try_reserve()` to reserve the channel slot before calling `record_generated()` and sending `Finished`. Both `emit_finished` and `emit` share `Incoming::event_budget_exceeded()` on `TrySendError::Full` so terminal event-budget overflow records `FAILED` instead of `GENERATED`/`COMPLETED`. - `ModelRuntime::generate_for_output` enables deferred completion for consumers that run output decoding and validation (`helios/src/server/http.rs` and `helios/src/server/protocol/decisions/mod.rs`), parking worker completion in `GENERATED` until the consumer calls `Generation::complete_output()`, calls `Generation::fail_output()`, or drops `Generation` (`on_reader_drop()`). - When `defer_completion` is true, dropping `Generation` without confirming output validation settles `GENERATED -> CANCELLED` (in `on_reader_drop()`) or `READER_DROPPED -> CANCELLED` (in `record_generated()`), so unread client disconnects and aborted multi-choice sibling responses count as cancelled rather than completed. Direct `ModelRuntime::generate` and `generate_many` callers keep immediate worker completion (`defer_completion = false`, settling `PENDING | READER_DROPPED -> COMPLETED`) while still using `RequestOutcome` so event-budget overflow cannot double-count failure and cancellation. - On every `Delivery::Failed` exit in `helios/src/server/http.rs` (`wait_for_first_token`, echo application, zero-token finish, and the event loop's single error handler covering both mid-stream and `Finished` errors), the failing decoder is aborted once with `Termination::ExecutionError` and any associated `Generation` calls `fail_output()`, which transitions the outcome to `FAILED` before setting `cancelled` so the worker releases scheduler resources without counting the request as cancelled. - `Incoming::finish_cancelled` calls `record_cancelled()` before emitting `GenerationEvent::Finished`, pending-drop cancellation paths call `record_cancelled()` directly, and `Incoming::finish_error` calls `record_failed()` before notifying admission, first-token, and event channels. - Updated Prometheus `# HELP` descriptions and `Snapshot::completed` docs in `helios/src/server/metrics.rs` and the metrics documentation in `docs/api.md` to describe validated output completion and unread/unvalidated disconnects for served HTTP and Decisions traffic while noting that direct in-process `ModelRuntime::generate*` callers retain model-generation completion semantics. - Routed both terminal emission sites in `helios/src/server/runtime/response_lifecycle_tests.rs` through `Incoming::emit_finished` so the `ResponseLifecycle` conformance suite exercises the production terminal entry point. As a result, output-layer failures across streaming and non-streaming Chat, Completions, Messages, Responses, and Decisions endpoints increment `flare_requests_failed_total` exactly once without incrementing `flare_requests_cancelled_total` or `flare_requests_completed_total`, including when worker generation finishes before output decoding rejects buffered events or when terminal emission overflows the event budget. Genuine client disconnects (before or after worker generation completes when output validation has not run) increment `flare_requests_cancelled_total`, normal validated completions increment `flare_requests_completed_total`, and multi-choice (`n > 1`) failures count the failing choice as failed while cancelling undelivered sibling choices. Validation on Linux CPU (non-gated chat templates prepared by `tests/frontend/prepare_templates.py` via `FLARE_TEST_TEMPLATE_DIR`, 512 MiB locked-memory limit for parallel Engram staging tests): - `cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server`: 1,884 passed, 0 failed, 84 ignored (including unit, 2-thread barrier concurrency, and HTTP/Worker integration tests covering terminal event-budget overflow for direct and deferred streams, deferred vs direct reader-drop orderings, ChatML duplicate-parameter stream rejections across Chat/Messages/Responses, post-worker-completion and end-of-sequence output rejections, genuine client disconnects before and after worker completion, normal completions, and multi-choice `n = 2` output failures with both active and already-generated sibling choices). - `cargo test --locked --release --manifest-path flare/Cargo.toml`: 254 passed, 0 failed, 4 ignored. - `cargo test --locked --release --manifest-path flare-cli/Cargo.toml`: 245 passed, 0 failed, 3 ignored. - `python3 verification/helios-lifecycle/check.py --tlc-jar <tla2tools.jar> --mutations`: passed all 8 TLA+ models and Rust trace-conformance checks (including 365,508 observed Rust transitions against `ResponseLifecycle.tla` routed through `Incoming::emit_finished`), detected all 13 TLA+ mutations, 26 Rust guard mutations (including `unread response admission`, `unfinished producer admission`, `generation group admission`, and `undersized response queue`), and 1 observed-edge safety violation (`DispatchRing SlotReuseSafe`), restored sources, and re-verified all conformance suites cleanly. Material limitations: checkpoint- and GPU-gated integration tests (84 ignored in `helios`, 4 in `flare`, 3 in `flare-cli`), live GPU serving, and Kani harnesses (no completion-vector or state-view validators were modified) were not run. Signed-off-by: Joshua Cartu <jcartu@users.noreply.github.com> Design-Signed-Off-By: Antigravity (Gemini 4 Neon); design-review=2e5b
1419fcf to
a04bfee
Compare
Fixes #679
Why
In Helios,
flare_requests_failed_totalcounts model requests failed by admission, execution, grammar, or output processing (helios/src/server/metrics.rs). Previously, onlyIncoming::finish_errorinside the model worker (helios/src/server/runtime.rs) incrementedmetrics.failed, while the worker eagerly incrementedmetrics.completedbefore trailing stop flushes,GenerationEvent::Finishedchannel delivery, or output decoding ran, and incrementedmetrics.cancelledwhenevercancelledwas set or the event channel closed.When the HTTP output layer rejected a streamed or buffered response—for example, when the ChatML tool parser (
helios/src/output/chatml.rs) rejected an empty or duplicate parameter name or rejected an incomplete tool call at end-of-sequence—http::generate(helios/src/server/http.rs) encoded an error frame, returnedDelivery::Failed, and dropped itsGenerationreceiver. Three accounting defects followed:Generation::dropandIncoming::emit(TrySendError::Closed) to setcancelled, so the worker incrementedflare_requests_cancelled_totalwhileflare_requests_failed_totalremained zero.GenerationEvent::Finished(during end-of-sequence decoding inDecoder::finish/Encoder::finish, or when buffered tokens raced ahead of the HTTP task), as well as terminal event-budget overflow during stop flushing orFinishedemission, leftflare_requests_completed_totalincremented whileflare_requests_failed_totalstayed zero.TrySendError::Full) calledself.fail(...)and then setcancelled = true, allowing a subsequentWorker::admit()pass to incrementflare_requests_cancelled_totalon top offlare_requests_failed_total.A shared atomic outcome state machine between
IncomingandGenerationwith deferred completion for output-layer consumers resolves all three cases without decrementing monotonic Prometheus counters.What Changed
helios/src/server/runtime.rs:RequestOutcome, a monotonicAtomicU8state machine (PENDING,GENERATED,READER_DROPPED,COMPLETED,CANCELLED,FAILED) shared by each(Incoming, Generation)pair, driven by a single CAS helper (RequestOutcome::transition). Each metric counter (completed,cancelled,failed) increments only on a compare-exchange into its absorbing terminal state, so every request increments at most one counter at most once and never decrements a counter.metrics.completedincrements withIncoming::emit_finished, called after scheduler lookup and trailingstops.finish()emission.emit_finishedsuppressesFinishedif a prior worker failure is already recorded and usestry_reserve()to reserve the bounded channel slot before callingrecord_generated()and sendingFinished. Bothemit_finishedandemitshareIncoming::event_budget_exceeded()onTrySendError::Fullso terminal event-budget overflow fails the request instead of recording completion.ModelRuntime::generate_for_output, which setsdefer_completion = trueso normal worker completion parks inGENERATEDuntil the consumer validates output and callsGeneration::complete_output(), rejects output and callsGeneration::fail_output(), or dropsGeneration(on_reader_drop()).defer_completionis true, droppingGenerationwithout confirming output validation transitionsGENERATED -> CANCELLED(inon_reader_drop()) orREADER_DROPPED -> CANCELLED(inrecord_generated()), so unread client disconnects and aborted multi-choice sibling responses count as cancelled rather than completed. DirectModelRuntime::generate,generate_many, and test-onlygenerate_observedcallers retain immediate worker completion (defer_completion = false, settlingPENDING | READER_DROPPED -> COMPLETED) while still usingRequestOutcomeso event-budget overflow cannot double-count failure and cancellation.Incoming::finish_errorto recordFAILEDbefore notifying admission, first-token, and event channels, movedself.outcome.record_cancelled()intoIncoming::finish_cancelledbefore emittingGenerationEvent::Finished, and kept directrecord_cancelled()calls on pending-drop cancellation paths inWorker::admit.helios/src/server/http.rs:state.model.generate_for_output(removing the single-callergenerate_many_observedwrapper).GenerationEvent::Finished, settledgenerations[index].take()withcomplete_output()when decoding and encoding succeed orfail_output()when they return an error.Delivery::Failedexit (wait_for_first_token, echo application, zero-token finish, and the event loop's singleErr(e)arm covering both mid-stream andFinishederrors), aborted the failing decoder once withTermination::ExecutionErrorand calledgeneration.fail_output()on any activeGenerationbefore yieldingDelivery::Failed.helios/src/server/protocol/decisions/mod.rs:generate_for_outputand settled eachGenerationwithcomplete_output()on success orfail_output()on probability validation, event-count, or channel errors.helios/src/server/metrics.rsanddocs/api.md:# HELPdescriptions (flare_requests_completed_total,flare_requests_cancelled_total),Snapshot::completeddocs, and thedocs/api.mdmetrics documentation to reflect validated output completion and unread/unvalidated disconnects for served HTTP and Decisions traffic while noting that direct in-processModelRuntime::generate*callers retain model-generation completion semantics.helios/src/server/runtime/response_lifecycle_tests.rs:ResponseLifecycleharness and the HTTP terminal-frame retention test) from rawemit(GenerationEvent::Finished { ... })toemit_finished(GenerationEvent::Finished { ... })so theResponseLifecycleconformance suite exercises the production terminal entry point.helios/src/server/runtime.rsandhelios/src/server/runtime/phase_tests.rs:Finished), deferred vs direct reader-drop orderings, and a 2-threadBarrier-synchronized concurrency test across all worker/consumer outcome pairs.wait_for_admittedhelper) covering streaming ChatML duplicate-parameter rejections on/v1/chat/completions,/v1/messages, and/v1/responses; mid-stream and end-of-sequence output rejections after worker completion (streaming and non-streaming); genuine client disconnects before and after worker completion; normal streaming and non-streaming completions; and multi-choice (n = 2) output failures with both still-active and already-generated sibling choices.Claimed Result
flare_requests_failed_totalexactly once and leaveflare_requests_cancelled_totalandflare_requests_completed_totalunchanged, including when worker generation finishes before output decoding rejects buffered events or when terminal emission overflows the event budget.flare_requests_cancelled_totalwithout incrementingflare_requests_failed_totalorflare_requests_completed_total.flare_requests_completed_totalwithout double-counting, and multi-choice (n > 1) output failures record the failing choice underfailedwhile cancelling undelivered sibling choices (whether still active or already generated in the channel) undercancelled.ResponseLifecycle.tlaproducer/reader ownership invariants remain unchanged.Supporting Evidence and Limitations
All commands below ran on Linux CPU with non-gated chat templates prepared by
tests/frontend/prepare_templates.pyviaFLARE_TEST_TEMPLATE_DIRand a 512 MiB locked-memory limit (parallel Engram staging tests exceed 64 MiB when all unit tests run concurrently):cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server: 1,884 passed, 0 failed, 84 ignored acrosslib(1,822 passed, 47 ignored) and 14 integration test binaries (62 passed, 37 ignored), including the added unit, 2-thread concurrency, and HTTP/Worker integration tests.cargo test --locked --release --manifest-path flare/Cargo.toml: 254 passed, 0 failed, 4 ignored.cargo test --locked --release --manifest-path flare-cli/Cargo.toml: 245 passed, 0 failed, 3 ignored.python3 verification/helios-lifecycle/check.py --tlc-jar <path/to/tla2tools.jar> --mutations: exited 0; all 8 TLA+ models passed, Rust trace conformance checked 1,710 transitions againstLifecycle.tla, 1,291 againstRankProtocol.tla, 7,940 againstDispatchRing.tla, 8,490 againstOffloadTransfer.tla, 222,817 againstCacheOwnership.tla, 13,566 againstSpeculation.tla, 365,508 againstResponseLifecycle.tla(states=65989 edges=365508 depth=10, with terminal emission routed throughIncoming::emit_finished), and 68 againstCheckpointReservation.tla, all 13 TLA+ mutations, 26 Rust guard mutations (includingunread response admission,unfinished producer admission,generation group admission, andundersized response queue), and 1 observed-edge safety violation (DispatchRing SlotReuseSafe) were detected, and all conformance suites passed after source restoration.Limitations:
helios, 4 inflare, 3 inflare-cli) and live GPU serving throughflare runwere not run on this CPU-only verification pass.Discord: jcartu