#1 [high] Main subtraction: defer_completion flag + direct-caller branches exist only for tests
PR #692 head 7f298698. helios/src/server/runtime.rs:126 defer_completion: bool on RequestOutcome::new(metrics, defer_completion).
Every false caller is a test:
runtime.rs:1040-1052generate/enqueue→enqueue_many(..., false)runtime.rs:1044-1047#[cfg(test)] generate_observed→enqueue(..., Some(timestamps))runtime.rs:1054-1056generate_many→enqueue_many(prompts, None, false)
Only true caller: runtime.rs:1058-1064 generate_for_output (true), used by http.rs:333 and protocol/decisions/mod.rs:840. Grep over whole repo: generate_many appears only at phase_tests.rs:3857,3864,3869 and response_lifecycle_tests.rs:122; generate only at phase_tests.rs:3784,3788, prompt_tests.rs:59; generate_observed only phase_tests.rs:3770,3824. flare/ and flare-cli/ contain no caller (grep for generate_many/generate_observed/model.generate → no matches).
Consequences the flag forces:
runtime.rs:158-168record_generatedhas 4 arms, two of which (OUTCOME_PENDING => COMPLETED,OUTCOME_READER_DROPPED => COMPLETED) exist only fordefer_completion == false. With deferral unconditional it becomesPENDING => GENERATED,READER_DROPPED => CANCELLED.runtime.rs:482-487comment justifying the dual settlement of theClosedarm.- Docs/HELP must carry a carve-out:
metrics.rs:1078"(including explicit token stops), plus direct in-process ModelRuntime::generate* requests whose model generation completed successfully",metrics.rs:1088"(or before model generation completes for direct in-process ModelRuntime::generate* callers)",metrics.rs:91,docs/api.md:330,docs/api.md:349-352. enqueue_many's third parameterdefer_completion(runtime.rs:1066-1071) becomes dead.
Simplification: make deferral the only behaviour, delete defer_completion, the enqueue/generate_observed/generate wrappers, and the two COMPLETED-from-worker arms; convert the ~7 test call sites to generate_for_output + explicit complete_output()/drop (the semantics the tests actually assert: phase_tests.rs:571 completed==1 after full consumption, response_lifecycle_tests.rs:122 group admission). Net: one state table instead of two behaviours, and the docs/HELP carve-out sentences disappear.
Caveat to state: generate/generate_many are pub (re-exported server.rs:34) so removal is an API change; within the repo nothing outside tests calls them, and the PR body already says "direct in-process callers retain generation semantics" only because the flag exists.
#2 [high] Duplicated Delivery::Failed settlement and test drain loops
helios/src/server/http.rs — the same three-line settlement is hand-repeated before every failure exit:
:404-409wait_for_first_token:decoders[0].abort(crate::output::Termination::ExecutionError); generation.fail_output(); let frame = encoder.failure(&error); yield Delivery::Failed(error, frame); return;:426-434echo application: same with indexi:445-450zero-token finish: same but nofail_output()(correct: zero-token choices hold noGeneration, per http.rs:305-316):582-589event-loopErr(e): same withindex
A helper taking the mutable slices would remove ~10 lines and, more importantly, make "every Delivery::Failed exit settles its Generation" checkable in one place — the invariant the PR is about. E.g. fn fail_choice(generations: &mut [Option<Generation>], decoders: &mut [Decoder<..>], index: usize, error: Error, encoder: &mut Encoder) -> Frame returning the frame. Note the borrow interplay with the async_stream generator needs the helper to take explicit &mut slices rather than a self.
helios/src/server/runtime/phase_tests.rs — identical 7-line terminal-drain loop repeated three times:
:8744-8750, :8828-8834, :8973-8979:
for _ in 0..16 {
if worker.active.iter().all(Option::is_none) {
break;
}
emit_worker_tokens(&mut worker, &mut seq, &[]);
worker.publish().unwrap();
}
Extract fn drain_to_retirement(worker: &mut Worker<'_>, sequence: &mut u64) next to the existing emit_worker_tokens (:8498) and wait_for_admitted (:8632) helpers the PR already added.
Also duplicated in the same file: the image-input strip loop
phase_tests.rs:59-67(insideFixture::reasoning):4784-4792:8443-8451(newtext_http_fixture) Suggested:fn strip_image_inputs(&mut self)onFixture, three call sites, ~18 lines removed.
#3 [high] Research summary
Subtraction/Simplicity review of PR #692 (head 7f298698). The core state machine is compact and does not need rework, but the PR carries a mode flag whose only non-production setting exists for test harnesses, plus several repeated blocks in http.rs and the new tests.
High-value findings (details in scratchpad entries 1 and 2):
-
RequestOutcome::defer_completion(helios/src/server/runtime.rs:126) is a test-only switch, and it doubles the state table. Everyfalsecaller is a test helper (generate:1040-1052,#[cfg(test)] generate_observed:1044-1047,generate_many:1054-1056); the only production caller isgenerate_for_output(:1058-1064, used byhttp.rs:333anddecisions/mod.rs:840), and grep shows noflare/orflare-cli/caller at all. The flag is what forces tworecord_generatedarms that finishCOMPLETEDfrom the worker (runtime.rs:158-168), the dual-settlement comment at:482-487,enqueue_many's third parameter (:1066-1071), and the operator-facing carve-out sentences inmetrics.rs:91,:1078,:1088anddocs/api.md:330,:349-352. Deleting the flag and the three wrappers leaves one state table; the ~7 test call sites becomegenerate_for_outputplus explicitcomplete_output()/drop. Caveat:generate/generate_manyarepuband re-exported atserver.rs:34(not opened), so removal is an API change even though nothing in the repo consumes them. -
http.rshand-repeats the same failure settlement at four exits —abort(ExecutionError)+fail_output()+encoder.failure()+yield Delivery::Failedat:404-409,:426-434,:445-450(correctly withoutfail_output(), since zero-token choices hold noGeneration),:582-589. A single small helper would remove ~10 lines and, more importantly, put the PR's central invariant ("everyDelivery::Failedexit settles itsGeneration") in one reviewable place. -
The new integration tests repeat a 7-line drain loop three times (
phase_tests.rs:8744-8750,:8828-8834,:8973-8979) and a 9-line image-input strip loop three times (:59-67,:4784-4792,:8443-8451, the last added by this PR). Both belong next to the helpers the PR already introduced (emit_worker_tokens:8498,wait_for_admitted:8632).
Everything else checked (metrics HELP strings, the emit_finished/event_budget_exceeded split, finish_cancelled, the transition() CAS helper, ResponseLifecycle harness edits) is lean and idiomatic for this codebase; I found no dead code, speculative generality, or AGENTS.md structural violation beyond the test-only production switch above.
#4 [high] Lens verdict + what to state plainly as lean
PR #692, Subtractions lens, head 7f298698. Verdict: not a lean diff overall — one genuine removable production switch (finding 1) and two real duplication clusters (findings 2, 3). Nothing approaching "rewrite"; no dead code, no speculative config beyond the flag, no AGENTS.md structural violation.
Findings to report (in priority order):
defer_completiontest-only mode switch — see scratchpad entry 1 (runtime.rs:126, :158-168, :482-487, :1040-1064, :1066-1071; callers; docs/HELP carve-out; pub-API caveat).http.rsrepeated failure settlement at :404-409, :426-434, :445-450, :582-589 — see entry 2.- Duplicated test helpers: drain loop phase_tests.rs:8744-8750 / :8828-8834 / :8973-8979; image-strip loop :59-67 / :4784-4792 / :8443-8451 — see entry 2.
Explicitly checked and found LEAN / should be stated as fine (so the report is not read as blanket criticism):
RequestOutcome::transitionCAS helperruntime.rs:138-156— single loop,AcqRel/Acquire, counterfetch_addonly on success; replaces five duplicated loops from the pre-fix head. No simplification available.Incoming::event_budget_exceededruntime.rs:493-501shared byemit_finished:488-490andemit:545-547— correct de-duplication the author already did in review follow-through.finish_cancelledfoldingrecord_cancelledbeforeFinished(:434-443); remaining directrecord_cancelled()at:462-464,:1563,:1652are genuinely different sites (noCarriedavailable, or noFinishedwanted) — not duplication to collapse.emit_finished:465-492three-armtry_reservematch is the minimal encoding of the Completed/Closed/Full trichotomy.metrics.rs:1076-1095HELP strings anddocs/api.md:330,:332,:349-354: prose only, no code cost. ThefailedHELP asymmetry (metrics.rs:1092-1094unchanged vsdocs/api.md:332expanded) is a doc nit, not this lens's finding.response_lifecycle_tests.rs:152-164,:372-379switching toemit_finishedis a 2-line change; nothing to subtract.
One more small note if useful: phase_tests.rs:8632-8645 wait_for_admitted polls worker.admit() in a 5 s loop with sleep(5ms); it is already the shared helper, so it is the right place — no action.