Conventions & duplication review — PR #575 "Preserve raw JSON tool arguments in TmlOutput for strict TMLv0 calls"
Repository: NVIDIA/hyperflare-inference, PR head c7fae93, base main, 3 files, +237/−10
(helios/src/output/tml.rs, helios/src/grammar/strict.rs, tests/server/test_inkling2.py).
Lens: conventions and duplication. Rules read and applied: charter (read_charter), AGENTS.md
(155–207 contribution scope, esp. 188–193 "Reject unsupported abstractions and churn" and 194–199
"Require focused, meaningful validation"; 509–517 task tracking), docs/design-review.md,
docs/api.md, docs/TODO.txt.
Key findings
Three should fix findings, all duplication / convention departures, no blocking issue and no parser defect:
- Duplicated test fixture — the new
tml_strict_parser_preserves_30_digit_integers(helios/src/grammar/strict.rs:3819-3922) re-creates the schema, validator, compiler, config, plan andcount == 5assertions of the already dialect-parameterizedqwen_and_glm_strict_parsers_preserve_30_digit_integers(strict.rs:3723-3817) instead of adding aTmlJsonrow to that loop; it also hand-writes control-token encoding thatstrict_wire_grammars_reject_schema_violations_during_generation(strict.rs:4167-4333) already provides, and it drops the negative case the sibling has. - Server test bypasses its own module fixture —
test_strict_tml_tool_calls_and_truncation(tests/server/test_inkling2.py:121-209) hand-rollsurllib.requestcalls for four of six requests instead of the module's effort-parametrized, error-wrappingservicefixture (:29-68), so the strict path never runs at default effort and an HTTP 500 would surface without its body. - The tracking item the PR claims to close is untouched —
docs/TODO.txt:5-8is exactly this qualification, andAGENTS.md:514-516requires completed entries to be updated or removed.
What I verified as following precedent (no finding): the new RawCall<'a>/&RawValue wrapper
matches the repository's only other such struct (helios/src/frontend/mod.rs:250-259,
RawSegment), and no existing helper (tagged.rs RawArguments/strict_nonstring_raw/
container_parameter) is duplicated, because those serve tag dialects that must synthesize the
argument object. The unchanged tool-name lookup matches helios/src/output/recipient.rs:152/:257.
Should fix
1. helios/src/grammar/strict.rs:3819-3922 — new TML 30-digit test duplicates an existing parameterized test instead of joining it
qwen_and_glm_strict_parsers_preserve_30_digit_integers (strict.rs:3723-3817) is already
parameterized over the tool syntax: one schema fixture (big_schema, :3727-3746), one
validate_strict_tool_schema (:3747), one syn/cfg/env/plan setup (:3762-3795), and one
assert_eq!(raw_args.matches(big).count(), 5, …) (:3811-3815), looped over
for (kind, wire) in [(ToolParserKind::QwenCoder, …), (ToolParserKind::GlmArgumentTags, …)]
(:3748-3761).
The new test re-creates the same big/big_schema verbatim (:3827-3847), the same validator
(:3848), the same syn/cfg/env/plan block (:3849-3879), and the same
raw_args.matches(big).count() == 5 assertion (:3917-3921) — roughly 90 added lines that differ
from the existing test only in the wire text, the control-token ids and OutputStart::RecipientHeader.
Two existing mechanisms already carry exactly that wire-specific variation:
strict_wire_grammars_reject_schema_violations_during_generation(strict.rs:4167-4333) is aCasetable (struct Case { name, kind, separator, start, controls: &'static [&'static str], valid, invalid, constraint },:4176-4186) that already contains aTMLrow (kind: ToolParserKind::TmlJson, start: OutputStart::RecipientHeader, controls: &CONTROL_MARKERS,:4219-4228) and anencode()closure (:4290-4306) that performs precisely the marker-text→control-token substitution the new test hand-codes at:3883-3897.accepts_bytes(strict.rs:2471) is the module's assertion helper; the new test bypasses it and drivesgrammar.advancedirectly (:3895-3898), whereas the sibling dialect test asserts throughaccepts_bytes(:3796).
Why it matters: AGENTS.md:188-193 — "Refactoring must directly support the requested behavior";
duplicating a 90-line fixture rather than extending an existing dialect table is the churn the
repository explicitly rejects, and the duplication is why the new test silently lost the negative
assertion (the sibling's assert!(!accepts_bytes(... invalid ...)) counterpart): the new test only
ever proves that a valid 30-digit payload survives (:3916), never that a schema-violating TML
payload is rejected during generation. Today only tests/server/protocol/tests.rs:2163 (not opened) covers
TML rejection, so a regression in the TML strict grammar's rejection path would not be caught by this
test file.
Fix: extend the for (kind, wire) table at :3748 with a third row
(ToolParserKind::TmlJson, format!("audit<|content_invoke_tool_json|>{{\"name\":\"audit\",\"args\":{…}}}<|end_message|>")),
selecting the TML control markers and OutputStart::RecipientHeader for that row (the Case struct
at :4176-4186 already shows the shape: controls + start), and assert through accepts_bytes so
the new negative case comes for free.
2. tests/server/test_inkling2.py:121-209 — the new server test bypasses the module's own request fixture and its effort parametrization
The module's service fixture (tests/server/test_inkling2.py:29-68) is the file's established
convention and encodes several invariants:
- parametrized
@pytest.fixture(scope="module", params=[None, "none"], ids=["default-effort", "zero-effort"])(:29), applied throughask()at:43-44; - every request wrapped in
try/except urllib.error.HTTPError→pytest.fail(f"HTTP {code}: …")(:48-61), so failures arrive with the response body; seed=1234,max_tokens=1024,return_token_ids=True(:41-42) and theusage.completion_tokens == len(token_ids)invariant (:64);/v1/modelsdiscovery and model assertions (:31-38).
Every other test in the file goes through it, e.g. test_tml_tool_call_and_result (:106-118) and
test_text_and_eight_concurrent_requests (:71-77).
test_strict_tml_tool_calls_and_truncation departs from that precedent: it re-reads /v1/models
itself (:122-123), and issues four of its six requests through raw
urllib.request.Request + urlopen (:155-169, :176-192, :194-209) with no HTTPError
handling and hardcoded reasoning_effort="none" (:162) / reasoning=dict(effort="none")
(:183, :201). The Chat-Completions strict cases that do use service (:136, :144) are the
right template but cover only half the paths.
Why it matters: two behaviours the PR body claims are not actually exercised or diagnosable.
(a) Because the new requests hardcode zero effort, the fixture's default-effort parameter never
reaches the strict TML path, so "default effort and zero effort" coverage is only half real.
(b) Because the raw calls bypass the HTTPError wrapper, the exact failure this PR fixes — a live
HTTP 500 strict tool arguments does not match its grammar — would surface as an unhandled
HTTPError with no response body, losing the diagnostic the fixture exists to provide. It also
duplicates /v1/models discovery that the fixture already performs, and repeats the same JSON
request boilerplate six times.
Fix: add a small /v1/responses helper beside ask() inside the service fixture (the sibling
module tests/server/test_muse_spark.py:55-68 shows the pattern: one open(path, body) and one
request(path, body) used by every protocol test, e.g. :244-246), then route all six requests —
including the two truncation cases — through the fixture so effort stays parametrized and errors
carry the body. The existing buffered/streamed assertions at :136-152 should stay as-is as the
template.
3. docs/TODO.txt:5-8 — the tracking item this PR claims to close is left open
docs/TODO.txt:5-8 holds the open item:
[ ] Qualify "strict: true" function tools on a TMLv0 core (ToolParserKind::TmlJson, e.g. Inkling 2) served by flare run. Check Chat Completions and Responses, buffered and streamed, including max_tokens and max_output_tokens truncation. Close when a served TMLv0 core passes those checks and the result is recorded.
The PR body claims exactly that qualification ("35/35 … Chat Completions and Responses APIs, buffered
and streamed … max_tokens / max_output_tokens truncation (8/8)"), and the PR's own test file adds
those checks, yet the file list (pr_files) is only the three code/test files — docs/TODO.txt is
not touched.
Why it matters: AGENTS.md:514-516 — "Use docs/TODO.txt for miscellaneous follow-up items. …
Update or remove entries as work is completed." Leaving a finished qualification item open
misleads the next contributor into re-running the same four-Spark sweep, and contradicts the PR's own
claim that this closes the item.
Fix: remove the entry in this PR (or narrow it to whatever genuinely remains, e.g. non-Inkling TMLv0 cores). If the live qualification is not part of what merges, the entry must stay and the PR body should not imply it is closed.
Verified clean — new code that does follow the repository's precedent
RawCall<'a>(helios/src/output/tml.rs:329-363) follows the existing idiom. The#[derive(Deserialize)] #[serde(deny_unknown_fields)] struct RawCall<'a> { name: String, #[serde(borrow)] args: &'a RawValue }wrapper (:330-336) mirrorshelios/src/frontend/mod.rs:250-259RawSegment<'a>(#[serde(deny_unknown_fields)]plus#[serde(borrow)] text: &'a serde_json::value::RawValue), which is the repository's established "validate the wrapper keys, keep one field's bytes exactly" pattern. A repository-wide search forserde(borrow)inhelios/srcreturns exactly these two sites, so this is a precedent reused, not an invention.- No existing helper is duplicated.
RawArguments/strict_nonstring_raw/container_parameterinhelios/src/output/tagged.rs:806-904exist because tag dialects must synthesize the argument object from<arg_key>/<parameter>tags; TMLv0 receives the whole object as JSON text, so routing it through those helpers would force it through tag parsing. Thedeny_unknown_fields+ fallback-to-visible-text recovery (tml.rs:318-327) is unchanged in contract. - The tool-name lookup is untouched.
self.tools.iter().any(|tool| tool["function"]["name"] == parsed.name)(tml.rs:341-345) is identical to the pre-PR code and matcheshelios/src/output/recipient.rs:152/:257verbatim. The sibling dialects usefilter_map(|t| t.get("function")).find(...)(chatml.rs:100-103,argument_tags.rs:41-44,gemma_call.rs:128-132,minimax_xml.rs:166(not opened));tml.rswas already the outlier and this PR does not add a new divergence — not a finding against this PR. - The textual object check is not a duplicate of an existing mechanism.
parsed.args.get().trim().starts_with('{')(tml.rs:339-340) replacesobject.get("args")?.is_object(); it is the only way to keep the bytes raw. Behavioural note, not a defect: leading/trailing whitespace inside the raw value is now trimmed before emission, and interior order/spacing is preserved. Downstream both re-parse and re-check the object (helios/src/server/output.rs:113-121,helios/src/server/protocol/encode.rs:294-300(not opened)), so no documented contract (docs/api.md:588-605,:624-628) is contradicted.
Nits
docs/api.md:588-605documents the strict TMLv0 acceptance contract and:624-628the buffering/truncation behaviour, but neither states the user-visible outcome this PR delivers:tool_calls[].function.argumentspreserves argument text verbatim (key order, integers beyond 64 bits) rather than re-serializing it. One sentence there would match the file's existing level of detail. Optional — no documented statement is contradicted.helios/src/grammar/strict.rs:3821-3825reproduces thebyte_tokenizer_with(&CONTROL_MARKERS)controlscollection idiom a third time (:2804-2808and:4247-4251already do it). Folding the new test into the existing table (finding 1) removes the third copy without adding an abstraction, which is whatAGENTS.md:188-193prefers over a new helper.
Open questions / what I could not settle from the code
- Whether the live 4-Spark TP4 qualification described in the PR body is reproducible by a reviewer
here. It is asserted, not artefacted (
AGENTS.md:194-199requires the unrun checks to be identified, which the PR does); this is a validation question for another lens, not a duplication finding. - Whether removing the
docs/TODO.txtentry (finding 3) is acceptable given the qualification was run only on Inkling 2 Small NVFP4 — if "a TMLv0 core" is intended to cover more cores, the entry should be narrowed rather than deleted. Only the author can settle which reading is intended.