#1 [high] PR #626 subtraction-lens findings (verified quotes)
PR #626, head f7907a2. All lines from head.
- 5 verbatim copies of grammar-failure handling in
Worker::complete/publish: runtime.rs:1909-1919, 1930-1939, 1986-1996, 2098-2108, 2220-2233 (~10 lines each, ~50 lines total):
Ok(allowed) => allowed,
Err(error) => {
request.incoming.fail(
ExecutionError::Completion(Failure::caused_by(
format!("grammar advancement failed: {error}"),
error,
))
.into(),
);
stopped.push(token.request);
continue;
}
Same shape as existing helper pattern at runtime.rs:499-503 (close_reasoning error text). Fix: one helper fn fail_grammar(incoming: &Incoming, context: &str, error: Error) used by all five.
- The burst-accounting idiom is copied 3x and has already drifted:
- runtime.rs:1940-1944:
let skipped = burst_counts[slot].saturating_sub(position as u32); - runtime.rs:2067-2070 and 2132-2136:
let skipped = burst_counts[slot].saturating_sub(positions[slot] as u32);positions[slot]was already incremented at :1888, sopositions[slot] == position + 1; the first copy therefore computes skipped one larger than the other two. Extract one helper (and let correctness decide the right value); the duplication is the defect source, not worth three inline copies.
-
Oversized/collapsible decoder construction, runtime.rs:1639-1660 (22 lines,
.map(...)then.or_else(...)buildingDecoder::newtwice). Equivalent in ~8 lines by computing the output once then(from_cut || output.is_some()).then(|| Decoder::new(...)). Note the always-on cost (dossier finding 1) also disappears from the shape being abool. -
grammar_reasoning_mode: Option<bool>tri-state (runtime.rs:211-218, 253-260) whereNone= "derive from prompt". Eagerly initialise at Incoming construction (grammar_reasoning_mode: prompt.grammar_reasoning.as_ref().is_some_and(|o| o.content.start == Reasoning)) → field becomes plainboolandunwrap_or_elseclosure at :255-259 disappears. -
Dead guard:
allow_reasoning_reentryat runtime.rs:262-263 starts withself.prompt.grammar.is_some() &&butgrammar_reasoningis only everSomewhen a grammar exists (request.rs:408-426.then), so the conjunct can never be false. Delete it. -
admission.rs:122-125double-Option from a bool flag:
grammar_mask: grammar_constrained
.then(|| prompt.grammar.as_ref().map(|grammar| grammar.mask().to_vec()))
.flatten(),
→ prompt.grammar.as_ref().filter(|_| grammar_constrained).map(|g| g.mask().to_vec()). Also the new 4th positional bool sits directly after ignore_eos; call site runtime.rs:1613-1619 reads incoming.prompt.ignore_eos, grammar_constrained.
-
request.rs:408-426: 19 lines of.is_some().then(|| ...filter...).flatten()forgrammar.is_some() && (start==Reasoning || (recipient && start in {RecipientHeader,RecipientFrame})). Plainif/else Nonewith two named booleans reads in 6. -
Docs: the same ~8-line mechanism paragraph is now written three times with variations — docs/api.md:645-655, docs/core-design.md:1692-1707, docs/mtp-design.md:410-432 — while the sibling statements docs/core-design.md:1242-1248, docs/scheduling-runtime-design.md:548-552, helios/model-contract.md:236-238, docs/mtp-design.md:597-599 still say the old rule (dossier finding 6). One canonical paragraph + links is the repo's usual pattern (api.md keeps a 3-line statement and links to core-design).
-
mask_dirtyinvalidation is reset at 5 sites (grammar.rs:603 initial, 741, 803, 827refresh_mask_available, 865fail) plus a 3rd state enforced bydebug_assert!at grammar.rs:677-692. The twosync_mask()calls that only protect a later read via re-admission (runtime.rs:1922-1939, 2091-2108) could be folded into the single park/admission boundary (park_with_tokenswhengrammar_reasoning_mode == Some(false)), leaving one unavoidable sync beforegrammar.allows(cut.close[0])(runtime.rs:2217-2237). -
GrammarTransition.speculative_reasoning: bool(runtime.rs:1873-1881) isfalseat 2 of 3 construction sites and is passed straight through toOption<bool>; the struct +park_grammar_transition(6 params) +park_with_tokens(7 params,#[allow(clippy::too_many_arguments)], runtime.rs:2430-2439) is 3 layers for 2 callers.
#3 [high] PR #626 simplicity verdict and convention citations
Convention citations for the simplicity review:
- AGENTS.md:188-193 "Reject unsupported abstractions and churn… do not add frameworks, extension points, speculative compatibility, fallback layers, or configuration switches without a concrete requirement."
- AGENTS.md:338 "Keep Helios as simple as possible."
- AGENTS.md:52-60 (prose): a repository document states architecture once; defects/unrun checks go to docs/TODO.txt. Three near-identical restatements of one rule (api.md:645-655, core-design.md:1692-1707, mtp-design.md:410-432) plus four stale copies elsewhere violate the "one statement" spirit and force a 4-file edit next time the rule changes.
- AGENTS.md:309-320: CI runs release builds only, so the new
debug_assert!at grammar.rs:677-692 is never exercised by any configured check (release compiles it out). Either make the invariant real (aResult) or delete the field/assert. - AGENTS.md:491-495 (verification guidance): add only the checks the affected behaviour needs — relevant to the 5 near-identical grammar-error blocks which have no dedicated test distinguishing them.
Overall verdict for the lens: the mechanism (grammar_constrained=false during reasoning, host validation, cancel+park+Restore) is architecturally lean and reuses #615/#619 idioms rather than inventing new ones; nothing in the diff is dead code or speculative generality at the feature level. The cost is in the inline implementation: ~50 lines of copy-pasted error handling, three copies of one burst-arithmetic expression that already disagree, a tri-state Option mode flag, a double-Option from a bool, a 19-line combinator chain for a two-line predicate, a dead grammar.is_some() conjunct, and a third statement of the same docs paragraph. None requires a design change; all are local.
#4 [high] Research summary
I completed the Subtraction, Simplicity & Conventions lens for PR #626 and saved the findings with exact file:line citations and verbatim quotes to the scratchpad (entries 1–3: code duplication/removable code, test/docs duplication, and the convention citations plus overall verdict).
Headline: the feature-level design is lean — grammar_constrained = false during open reasoning, host validation via try_advance_unmasked, and cancel+park+Restore reuse the #615/#619 idioms instead of inventing new machinery, and there is no dead code or speculative generality at the mechanism level. The cost is entirely local and removable:
- ~50 lines of copy-pasted grammar-error handling — five near-identical
Failure::caused_by(format!("grammar advancement failed: {error}"), error)+incoming.fail+stopped.pushblocks atruntime.rs:1909-1919,1930-1939,1986-1996,2098-2108,2220-2233; one helper replaces all five (the existingActive::close_reasoningatruntime.rs:499-506shows the shape). - One burst-arithmetic expression copied three times, already drifted —
burst_counts[slot].saturating_sub(position as u32)atruntime.rs:1941versus...positions[slot] as u32at:2068and:2133, wherepositions[slot] == position + 1because:1888already incremented. Extract one helper; correctness decides which value is right. - Tri-state
grammar_reasoning_mode: Option<bool>(runtime.rs:211-218,253-260) whereNonejust means "derive from prompt" — initialise eagerly and theunwrap_or_elseclosure disappears. - Dead conjunct —
self.prompt.grammar.is_some() &&at the head ofallow_reasoning_reentry(runtime.rs:262-263) can never be false, sincegrammar_reasoningis onlySomewhen a grammar exists (request.rs:408-426). - Combinator bloat for two conditions —
request.rs:408-426(19 lines of.then(...).filter(...).cloned().flatten()) andadmission.rs:122-125(bool.then(...).flatten()double-Option) both collapse to plainif/Option::filterforms. - Decoder construction written twice at
runtime.rs:1639-1660(22 lines) — oneOptionplus oneDecoder::newcall covers both branches. - Docs: the same mechanism paragraph stated three times (
docs/api.md:645-655,docs/core-design.md:1692-1707,docs/mtp-design.md:410-432) while four sibling statements still give the superseded rule — one canonical paragraph in core-design with links from the others is the repo's existing pattern and would have avoided the contradiction.
Two structural convention points: the new debug_assert! invariant (grammar.rs:677-692) is unreachable by any configured check because every workflow and every cited suite is --release, so it should become a real Result or be dropped (AGENTS.md:309-320, 491-495); and the seven-argument park_with_tokens behind two thin wrappers carrying a speculative_reasoning: bool that is false in two of three construction sites is over-layered for two callers. I also noted the one consolidation the PR got right (enable_speculative_worker in phase_tests.rs:7290-7298) so the report is fair. No blocking issue was found in this lens; all seven items are local edits, not design changes.
#5 [high] Report skeleton and prioritisation for PR #626 simplicity lens
Final report for the Subtraction/Simplicity/Conventions lens (entries 1-3 hold the evidence; this note fixes the ordering and framing).
Verdict to state plainly up front: the mechanism is lean and idiomatic; nothing is dead code or speculative generality at the feature level. All findings are local edits inside the new inline code, no design change required, nothing blocking from this lens. Keep the list to 7 short items, not 20.
Order (highest value first):
- Five copy-pasted grammar-error blocks (runtime.rs:1909-1919, 1930-1939, 1986-1996, 2098-2108, 2220-2233) -> one helper; cite Active::close_reasoning (runtime.rs:499-506) as the existing shape.
- Burst arithmetic copied 3x and already inconsistent: runtime.rs:1941
position as u32vs :2068/:2133positions[slot] as u32, where positions[slot] == position+1 (increment at :1888). Note this is duplication-created divergence, leave the correct value to the correctness lens. - Docs paragraph written 3x (api.md:645-655, core-design.md:1692-1707, mtp-design.md:410-432) while 4 sibling statements stay stale; one canonical paragraph + links is the repo pattern.
- Tri-state grammar_reasoning_mode: Option (runtime.rs:211-218, 253-260) -> eager bool.
- Dead conjunct
self.prompt.grammar.is_some() &&in allow_reasoning_reentry (runtime.rs:262-273). - Combinator bloat: request.rs:408-426 (19 lines) and admission.rs:122-125 (bool.then(...).flatten()).
- Decoder::new written twice at runtime.rs:1639-1660; plus the 7-arg park_with_tokens (#[allow(clippy::too_many_arguments)] at :2430) behind park_grammar_transition (:2407-2428) with a GrammarTransition bool that is false in 2 of 3 sites (:1952, :2116, :2148).
Convention point to raise once, not per item: debug_assert! at grammar.rs:677-692 is unreachable (all workflows and the PR's own cited suites are --release; AGENTS.md:309-320), so make it a Result or delete it (AGENTS.md:491-495).
Fairness note to include: the PR does consolidate test boilerplate correctly with enable_speculative_worker (phase_tests.rs:7290-7298) and its new speculative_burst_frame helper (:7257-7288); the three added tests share scaffold but that is acceptable.
#2 [medium] Test/docs duplication in PR #626
Test-side duplication (lower value, noted for completeness):
- New helper
speculative_burst_frame(phase_tests.rs:7257-7288, added by this PR) reimplements, in a reusable form, the inline frame construction that existing tests already hand-roll at phase_tests.rs:7015-7040 and 7140-7175. Reasonable to keep, but the older inline copies could use it. - Three tests added in the PR share ~200 lines of scaffold; acceptable.
- Positive:
enable_speculative_worker(phase_tests.rs:7290-7298) correctly collapses the 4-line speculation-enable boilerplate; the PR does consolidate here.
Docs duplication verbatim-ish: api.md:645-655, core-design.md:1692-1707, mtp-design.md:410-432 all restate the same host-validation/transition mechanism; core-design.md:1242-1248 and mtp-design.md:597-599 still state the superseded rule → contradiction created by the copy, not the code.