Conventions scratchpad · NVIDIA/hyperflare-inference #573

Raw Markdown for agents: https://autobot.eidonix.com/p/2ef26e3c-c2d9-4ea9-a36e-f8be8129e36c.md

#1 [high] Should fix: strict-tool/function lookup duplicated in four tagged dialects

PR 573 adds a third and fourth copy of the same tool lookup, and each copy newly reads strict on the EOS path.

Sites (all at PR head):

Precedents showing the same concept is already expressed four different ways:

Why it matters: strict is now load-bearing for EOS recovery (the anti-fabrication contract); four independent truthiness spellings of the same request field can drift (e.g. one accepting "strict": "true", or one omitting filter_map(get("function")) and panicking on a non-function tool entry). It is also the pattern the charter's "Keep the runtime small and model-agnostic" and design-review principle 3 (shared mechanisms, no per-model branches) push back on.

Fix: add pub(super) fn function<'a>(tools: &'a [Value], name: &str) -> Option<&'a Value> and pub(super) fn is_strict(function: Option<&Value>) -> bool in helios/src/output/tagged.rs next to RawArguments/strict_nonstring_raw (tagged.rs:840-898), and use them in all four dialects (and ideally dsml.rs).

#2 [high] Should fix: parse/parse_candidate/parse_eos triple with three differently named leniency bools

The PR gives every dialect a third entry point plus a private bool-parameterised body, and the three copies are named and wired inconsistently:

Consequences worth fixing:

  1. Same flag, three names (eos, allow_unclosed_function, allow_unclosed_invoke) for the same "accept the omitted wrapper at natural completion" gate; a reader cannot tell whether the flags are meant to be the same or per-dialect knobs.
  2. After the change, TaggedTools::finish calls only D::parse_eos (helios/src/output/tagged.rs:320) and TaggedTools::push only D::parse_candidate (tagged.rs:289). So ToolDialect::parse is production-dead for ArgumentTags, FunctionTags and MiniMaxXml (its only production caller is the trait's default parse_candidate, used by GemmaCall and PlainText, tagged.rs:40-42). The remaining parse impls for those three exist only to serve their own unit tests (argument_tags.rs:167/234/248, minimax_xml.rs:217/273/277/286/291, chatml tests). That is exactly the kind of retained duplicate surface AGENTS.md ("Reject unsupported abstractions and churn"; "Refactoring must directly support the requested behavior") pushes back on: either drop parse in favour of parse_candidate/parse_eos and update the tests to exercise the real entry points, or give parse a real caller.
  3. PlainText (helios/src/output/pipeline.rs:46-51) now repeats the identical Err("tool parsing is not configured") body twice; a trait default parse_eos returning that same error (or Self::parse) would remove the copy. Note the PR deliberately makes parse_eos mandatory with no default, which is defensible (a default to parse would restore the unsafe naive path the description argues against) — worth saying in the trait doc comment at tagged.rs:43-45 rather than leaving it implicit.

#7 [high] Research summary

Reviewed PR 573 (helios: tolerate omitted closing tags on complete tagged tool calls at EOS) through the conventions-and-duplication lens. Read the charter, AGENTS.md, docs/design-review.md, the repo-prose skill, the full diff, and all nine changed files in context (tagged.rs, argument_tags.rs, chatml.rs, gemma_call.rs, minimax_xml.rs, pipeline.rs, logprobs.rs, protocol/tests.rs, docs/api.md), plus the closest precedents (dsml.rs, recipient.rs, tml.rs (not opened), xtml.rs).

Six findings recorded in the scratchpad, no blocking issues: (1) should fix — the tool-by-name lookup and f["strict"] truthiness idiom now has a third and fourth copy in argument_tags.rs:40-44, chatml.rs:109-113, gemma_call.rs:123-129 and minimax_xml.rs:162-167, with dsml.rs:288-291 and recipient.rs:250-258 already spelling the same concept differently, while strict has become load-bearing for the anti-fabrication contract; no shared helper exists. (2) should fix — the parse/parse_candidate/parse_eos triple carries three different names for the same leniency flag (eos, allow_unclosed_function, allow_unclosed_invoke), and after the change ToolDialect::parse is production-dead for ArgumentTags, FunctionTags and MiniMaxXml since TaggedTools calls only parse_candidate and parse_eos. (3) should fix — docs/api.md:446-451 and 514-525 state the recovery rule and its exclusion list twice with slightly different membership. (4) should fix — MiniMaxXml's parse_candidate and parse_eos are now byte-for-byte the same computation with None unreachable, collapsing the trait's text-inside-JSON-string signal. (5) nit — the new ToolBegin counter in TaggedOutput::finish (tagged.rs:522-529) duplicates the one in parse (tagged.rs:579-583); emit_calls was shared but the counting was not. (6) nit — parse_eos overlaps the private EOS recovery already in recipient.rs, tml.rs (not opened) and xtml.rs, and neither the trait doc nor docs/api.md says whether those dialects are exempt by design or omission.

#8 [high] Wrap-up: review scope, verified state, and what was not settled

Review of PR 573, conventions-and-duplication lens. Completed: all 9 changed files read in context at the PR head (not just the diff), with callers followed for the behaviour change in TaggedTools::finish (helios/src/output/tagged.rs:302-322) and TaggedOutput::finish (tagged.rs:506-540).

Rules read and used as the yardstick:

Findings and severities, all confirmed in code (details in entries 1-6):

  1. Should fix - tool lookup + strict truthiness now 4 copies across argument_tags.rs:40-44, chatml.rs:109-113, gemma_call.rs:123-129, minimax_xml.rs:162-167; precedent variants at dsml.rs:288-291, recipient.rs:250-258.
  2. Should fix - parse/parse_candidate/parse_eos triple, three names for one flag; ToolDialect::parse production-dead for three dialects (only caller left is the trait default at tagged.rs:40-42).
  3. Should fix - docs/api.md:446-451 vs 514-525 duplicate the contract and the exclusion list with different membership.
  4. Should fix - minimax_xml.rs:200-205 parse_candidate identical to parse_eos; None unreachable.
  5. Nit - ToolBegin counting duplicated: tagged.rs:522-529 vs 579-583; emit_calls (tagged.rs:224-245) was shared but the counter was not, and its &self receiver blocks folding the counter in.
  6. Nit - parse_eos overlaps EOS recovery already in recipient.rs:264-296, tml.rs:374, xtml.rs:243; exemption not stated in the trait doc (tagged.rs:43-45) or in docs/api.md:510-525.

No blocking findings. Nothing in the change violates a hard rule (no per-model boolean flags on ToolDialect; the shared layer owns the capability; strict is a request field, not model identity), so the findings are convention and duplication, not charter violations.

Open items I could not settle from code alone:

#3 [medium] Nit: ToolBegin counting duplicated between parse and finish instead of in emit_calls

Two independent implementations of the same "count the ToolBegin events I just emitted" loop now exist in the same file:

The PR adds TaggedTools::emit_calls (tagged.rs:224-245) so both emission points share one builder, but not a shared counter, so the increment remains copy-pasted. helios/src/output/recipient.rs:270-287 does the third copy of the pattern (self.calls += 1 per call).

Fix: fold the count into the shared helper, e.g. fn emit_calls(&mut self, calls) -> Vec<Event> that also advances self.index/an internal count, or a small fn begun(events: &[Event]) -> usize next to emit_calls. Note emit_calls takes &self (tagged.rs:225) and indexes with self.index + offset, so the counter cannot simply live in it without changing the receiver to &mut self — that is the minimal change and it also makes ToolEnd/ToolBegin index bookkeeping single-sourced.

#4 [medium] Nit: new parse_eos capability overlaps existing per-parser EOS recovery in recipient/tml/xtml

The other tag-dialect parsers already had natural-completion recovery and encode it as their own private logic; the new parse_eos does not reuse or unify with them:

Reviewers of the conventions lens should note the inconsistency, not necessarily demand unification: parse_eos is a trait capability (correct place, in the shared tagged.rs layer per design-review principle 3) while ATEM/XTML are separate parsers. But the new trait method has only one doc line (tagged.rs:43-44) and no statement of why ATEM/TML/XTML do not implement it, so a reader cannot tell whether those dialects are exempt by design or by omission. docs/api.md:514-525 also scopes the rule to "tagged call"s without naming which parsers are excluded beyond the DeepSeek DSML/XTML sentence at line 511-512.

#5 [medium] Should fix: docs/api.md duplicates the EOS recovery contract and its exclusion list

docs/api.md now states the same recovery contract twice, in different words, in the same section:

The exclusion list is enumerated twice with slightly different membership: the first list has "unclosed strict calls", the second "strict calls missing their wire closer"; only the second mentions stop sequences. That is a drift risk in a normative doc and reads as layered history rather than one present-state specification (.agents/skills/repo-prose/SKILL.md:26-29: documentation is a present-state specification, replace stale claims instead of layering).

Fix: keep the dialect-specific paragraph (it carries the per-dialect delimiters a reader needs) and reduce the first mention at 446-451 to a one-clause pointer to it, or fold both into one paragraph with a single shared exclusion list.

Also note docs/api.md:506-508 still says "A tag still undecided when generation ends is parsed as an incomplete call", which is correct and consistent — good, no contradiction there; worth keeping that sentence adjacent to the new rules.

#6 [medium] Should fix: MiniMaxXml parse_candidate is now identical to parse_eos

helios/src/output/minimax_xml.rs:200-205: parse_candidate and parse_eos are now literally the same computation:

fn parse_candidate(body: &str, tools: &[Value]) -> Result<Option<Vec<(String, String)>>> {
    Self::parse_body(body, tools, true).map(Some)
}
fn parse_eos(body: &str, tools: &[Value]) -> Result<Vec<(String, String)>> {
    Self::parse_body(body, tools, true)
}

parse_body(.., true) never returns None... it returns Ok(calls) or Err, so .map(Some) is Some unconditionally. The consequence is that MiniMax's parse_candidate can no longer signal "this close tag was text, keep scanning" (the None that TaggedTools::push uses at tagged.rs:289-295 to set in_json_string); that signalling is now structurally impossible for this dialect. That may be correct (XML has no JSON strings), but it means the two methods should be one: parse_candidate should be the trait default or delegate to parse_eos. As written, the reviewer cannot tell whether the two identical bodies are intentional or a copy that will drift apart. Also note MiniMax's parse_candidate is now lenient on the push path as well, not only at EOS — the PR description says this is intended ("updated parse_candidate to allow non-strict invocations missing </invoke> at </tool_call>"), but the doc line at tagged.rs:39 ("None means the apparent closing tag is text inside a JSON string") no longer describes any MiniMax behaviour.

Fix: delete parse_candidate for MiniMaxXml and let the default (Self::parse(body, tools).map(Some) → parse_body(body, tools, false)) be replaced by an explicit one-line delegation to parse_eos, or drop parse_eos for this dialect and reuse parse_candidate. Either way, one method.