Simplicity (lens D) review of PR #457
Scope: every changed hunk read in context at head aacbca1 — helios/src/output/tml.rs (1-688), helios/src/grammar.rs (180-440, 1740-2046), helios/src/grammar/strict.rs (1480-1660, 4180-4260, 4520-4637), helios/src/server/request/tml_tests.rs (1-479) — plus the callers in helios/src/server/request.rs:246-294 and the fixture generator tests/frontend/generate_inkling2_fixtures.py:330-440.
Rules applied: charter ("Look for the smallest footprint in shared code, or a way to solve it without new code at all"; "Keep the runtime small and model-agnostic"), AGENTS.md:179-194 ("Reject unsupported abstractions and churn… Do not add frameworks, extension points, speculative compatibility, fallback layers, or configuration switches without a concrete requirement"; "Require focused, meaningful validation. Tests must exercise the affected behavior or contract; source-text checks and mocks that bypass the behavior cannot establish runtime correctness"), and docs/design-review.md principles 1 (keep Helios simple), 12 (validate the real path and report evidence honestly) and 16 (write without hidden context).
Key findings
The production change is small and in the right layer (~60 lines: the AnswerState field in tml.rs, one extra tool_unnamed rule and one ending string in each grammar compiler). The simplicity debt sits almost entirely in the tests: roughly 200 of the +431 lines are new test code, and two of the four new test groups prove the same thing twice:
- Two of the three new
#[ignore]snapshot tests feed the same captured token list through the sameDecoder/Encoderand assert the sameresponse.failedframe (tml_tests.rs:265-270vs418-424; assertions at:276-281vs:435-439). - One new unit test compares the parser to itself, so it cannot catch a regression in the path it is meant to pin (
tml.rs:626-639). - The new snapshot tests hard-code tokenizer IDs instead of extending the generated fixture, which is the file's documented pattern and the only place where tml-renderers' own parse is recorded. Yet the code comment claims the parser follows "as tml-renderers parses it" (
tml.rs:7-15) — the diff adds no evidence for that on the new path. - The wire-token encoder closure is copied for a fourth time inside this PR, and the two new grammar tests encode the same kinds of strings by two different mechanisms.
- A suspicion from my notes that the new custom-grammar test exercises a path no real request can reach is wrong — see "Checked and withdrawn" below.
- The description's central micro-optimisation claim ("avoiding N-way Earley ambiguity across large tool sets",
grammar.rs:381-391) is applied only on one side;strict.rs:1599-1604takes exactly that N-way alternation, and nothing in the diff uses more than two tools, so the 178-tool measurement is unverifiable from the code.
Nothing here blocks the correctness fix.
Findings
should fix — tml_tests.rs:393-439 and 246-282 are the same test twice
a_model_frame_without_a_content_kind_reports_a_failed_response (tml_tests.rs:246-282) and inkling_stress_untyped_closed_header_must_surface_failure (tml_tests.rs:393-439) both:
- build the same
Inklingfixture and aProtocol::Responsesrequest with onebashfunction tool (:253-256vs:400-404, differing only in"tool_choice":"auto"); - feed the identical token sequence —
[200001, 200008]+encode("Inspect the branch.")+END_MESSAGE+200001+ the same 15 captured ordinary IDs[33131,1,70469,1,25,1,3960,150309,12,68206,155417,152664,1,92,92]+END_MESSAGE, 200006(:265-270vs:418-424); - assert per-push reasoning-only events (
:271-274vs:426-429), thendecoder.finish(Eos)errors (:276vs:431) andencoder.failureyieldsresponse.failedwithstatus: "failed"(:277-280vs:436-438).
Why it matters: AGENTS.md:189-194 asks for focused, meaningful validation; a second ignored test that cannot fail unless the first also fails adds ~47 lines and a second snapshot-suite entry to maintain, and its error message ("malformed terminal header silently disposed of the action", :435) names a development symptom rather than an invariant. The earlier test is strictly stronger (it also asserts error.code == "server_error" and the per-push reasoning-only invariant).
Fix: delete tml_tests.rs:393-439; if the tool_choice: "auto" variant matters, make it one more request loop inside :246-282 (the request building is already local there). ~47 lines removed.
should fix — tml_tests.rs:265-270 and 418-424: inline token IDs bypass the fixture that also records tml-renderers' parse
Both tests hard-code 200001, 200008, 33131, 1, 70469, … and build their own Decoder/Encoder. The file's own header says the checkpoint tests compare Helios with tests/frontend/inkling2_tml.json, "generated by tests/frontend/generate_inkling2_fixtures.py" (tml_tests.rs:7-12), and outputs_match_reference_parses (:286-299) drives every outputs case through parse() (:200-244). The generator already records, per case, reference_parse and — crucially — {"error": …} when tml-renderers itself rejects the sequence (generate_inkling2_fixtures.py:399-406, :412-417).
Why it matters: tml.rs:7-15 states the Helios parser is written to match "as tml-renderers parses it". A hand-written token list inside Rust proves only that this sequence trips the new Helios check; it does not show that tml-renderers rejects the same suffix. If tml-renderers instead parses that suffix as a message, the new finish(Eos) error is a Helios-only interpretation imposed on a shared contract — which is exactly what a reviewer cannot tell from the diff.
Fix: add one output(...) case for the malformed terminal header in generate_inkling2_fixtures.py (the frame() helper at :420-422 plus a lookup(..., closed=False)-style variant already produce this shape), regenerate inkling2_tml.json, and let one test in tml_tests.rs assert both (a) Helios fails at EOS and (b) case["reference_parse"]["error"] is present. That is one test instead of two, and adds the cross-implementation evidence the PR currently lacks. If the fixture cannot be regenerated in this PR, say so under "Unrun Checks" rather than inlining IDs.
should fix — tml.rs:626-639: the test compares the parser with itself
for valid in [&answer[..], &call[..], &invalid_call[..]] {
let expected = run(frame, valid, Termination::Eos);
for order in [[&header[..], valid], [valid, &header[..]]] {
assert_eq!(run(frame, &order.concat(), Termination::Eos), expected);
}
}
expected comes from run(...) — the function under test — so the assertion can only detect an order-dependent difference. If the untyped header ever started contributing content, or stopped being tolerated, both sides move together and the test still passes.
Why it matters: this is the test that is supposed to pin "an untyped header is inert and does not suppress a following or preceding answer" — the behaviour the new HeaderWithoutContent bookkeeping must not break. AGENTS.md:189-194 requires tests to establish the contract, not merely be self-consistent.
Fix: assert literals, as the neighbouring tests do (tml.rs:543-561). With MODEL, "untyped", END:
for (valid, expected) in [
(&answer[..], ("".into(), "done".into(), vec![])),
(&call[..], ("".into(), String::new(), vec![("lookup".into(), "{}".into())])),
(&invalid_call[..], ("".into(), "invalid JSON".into(), vec![])),
] { … }
using the same Parsed tuple already produced at tml.rs:545, :550, :579-580. Same length, and it now states what the header must do.
should fix — strict.rs:4572-4588 copies the wire-token encoder for the fourth time
The new strict_tml_grammar_allows_unnamed_headers_and_preamble_before_tools re-implements, verbatim, the marker-splitting encode closure from strict_tool_wire_grammars_enforce_constraints (strict.rs:4205-4221). The same routine also exists at helios/src/server/protocol/tests.rs:466-470 and :2052-2058. Meanwhile the other new grammar test does it a third way, relying on a byte-level BPE: tokenizer.encode(text.as_str(), false) (grammar.rs:1987-1994, with the envelope built at :1943-1948 from byte_tokenizer_with).
Why it matters: one PR now contains two different ways to turn a TML wire string into tokens, and four copies of the third. strict.rs:4278-4286-style mismatches between "what the model emits" and "what the test feeds" would then be invisible, because each test defines its own wire encoding. The charter asks for the smallest footprint in shared code.
Fix: one test helper next to byte_tokenizer_with (grammar.rs:936, pub(crate) under #[cfg(test)]): wire_tokens(controls: &[(u32, String)], wire: &str) -> Vec<u32>. Use it at strict.rs:4205, strict.rs:4572, protocol/tests.rs:466, protocol/tests.rs:2052, and in content_headers_grammar_allows_preamble_before_tools (which can then use the marker-wise encoder instead of tokenizer.encode, or keep encode and say in one comment why a byte tokenizer is sufficient). ~35 lines removed, and the two new grammar tests then encode identically.
nit — tml.rs:644-647 duplicates existing role-frame coverage
empty_model_headers_other_roles_and_external_stops_keep_their_termination asserts USER/TOOL/SYSTEM-headed frames produce nothing (:644-646), which frames_without_headers_and_frames_of_other_authors already shows with a richer frame: [USER, TEXT, "echo", END, MODEL, "bob", TEXT, "hi", END, TOOL, "lookup", TEXT, "x", END] yields content "hi" only (tml.rs:548-551). Keep the [MODEL, END] case (genuinely new: empty model header must not error) and the four external Termination causes (:648-651), and drop the three role frames — or drop them from the older test. One of the two should go.
nit — strict.rs:1566/1586/1599-1604 vs grammar.rs:381-391: two shapes for one rule, one justified
The same fix (accept <|message_model|><|content_invoke_tool_json|> with no header name) is written two ways: a factored payload_any schema with a name enum (grammar.rs:381-391) and an N-way alternation over the per-tool payloads (strict.rs:1599-1604). The PR justifies the first as "avoiding N-way Earley ambiguity across large tool sets" — but the strict compiler, which is the "strict": true path taken with the measured 178 tools, now has exactly that alternation, and nothing in the diff uses more than two tools (strict.rs:4591-4599), so the claim is unmeasured either way.
The reason the strict side must alternate is real and not obvious: embed_schema_in_tml_wrapper (strict.rs:873) folds the tool name into each payload as a const, so name and args cannot be split the way grammar.rs splits them. Fix: one comment above strict.rs:1599 saying so, otherwise the next reader will either "unify" the two rules (breaking one) or wonder which shape is deliberate (docs/design-review.md:16). If the strict alternation is measurably slower on large tool sets, that belongs in the PR's limitations, not in code.
Also here: payload_refs (strict.rs:1566, pushed at :1586, consumed only by the join at :1602) is a staging vector for a single format! — the tool_unnamed rule can be built inside the same loop or from tool_rules.
nit — tml_tests.rs:443-478 partly restates grammar.rs:1932-1997
inkling_stress_custom_grammar_preamble_then_tool asserts accepts(&text), accepts(call), accepts(&format!("{call}{text}")) and accepts(&preamble_then_call) through the real tokenizer with grammar: "start: /(?s:.+)/" (:466-477), which is the same new ending exercised by content_headers_grammar_allows_preamble_before_tools (grammar.rs:1969-1983, cases format!("{answer}{named_call}") etc.). The snapshot test earns its place by also running the same frames through parse(), i.e. proving the parser agrees (:453-459); the grammar.rs test earns its place through the rejection cases (undeclared tool, header mismatch, thinking-only, duplicate @answer). Trim the four accept-only assertions on one side (keep them in the snapshot test, where they are end-to-end).
Checked and withdrawn
My notes flagged that tool_unnamed (grammar.rs:381-391) might be unreachable under grammar: "start: /(?s:.+)/", on the theory that a user-supplied start: replaces the envelope grammar. Reading compile_content_headers end to end shows the opposite: it renames grammar.grammars[0] to answer (grammar.rs:379) and inserts its own grammar with the generated start: … rule at index 0 (:407-415), so the user's Lark becomes the answer body only and the tool rules guide the whole frame sequence. request.rs:289-290 routes Constraint::Lark through exactly that call, and content_headers_grammar_allows_preamble_before_tools uses the same compile_lark_in("start: /(?s:.+)/", Some(&envelope)) (grammar.rs:1984-1986), i.e. it does exercise the path a real request takes (compare the same structure at grammar.rs:1910-1918). Not a finding — recording it so it is not re-raised.
Similarly withdrawn: my note that AnswerState::Emitted is unreachable as a distinct case. It is reachable and necessary — the guard at tml.rs:285 (self.answer == AnswerState::Empty) is what makes a header closed before any answer fatal while a header closed after visible content or a call is not (tml.rs:219, :338, :399). A pair of booleans would encode the same decision, but the enum is the clearer expression; not worth changing.
Claims in the description the diff does not support
- "avoiding N-way Earley ambiguity across large tool sets" (
grammar.rs:383): the strict compiler keeps the N-way alternation (strict.rs:1599-1604) and no test in the diff uses more than two tools (one ingrammar.rs:1953, two instrict.rs:4591-4599, one intml_tests.rs:463). The 178-tool measurement is not reproducible from the code. - The
TmlOutputcontract "as tml-renderers parses it" (tml.rs:7-15) is not exercised for the new malformed-header path, because the test token list never goes throughreference_parse(generate_inkling2_fixtures.py:399-417).
Open questions
- Does tml-renderers reject the captured malformed terminal header (raising
ValueErrorwith akind)? Only a regenerated fixture case (outputs[].reference_parse.error) answers it; if it does not, the newfinish(Eos)error is a Helios-specific interpretation and the PR description should say so. - Was the live 0/5 → 5/5 measurement attributable to
tool_unnamed, to the new(answer ({restart} thinking* tool)* | tools)ending, or to the fact that(?s:.+)as the answer body can itself swallow raw tool JSON? The tests separate schema rejection from framing, but not these two production changes from each other.
Verdict
No blocking issues. The four should-fix items are test-side only: delete one duplicate snapshot test, move the malformed-header case into the generated fixture, replace the self-referential assertion with literals, and factor the wire-token encoder. Production code is roughly the smallest thing that expresses the new rule; the only code-level trims are payload_refs and the role-frame cases.