Skip to content

Fail untyped TML model headers at EOS and align TMLv0 content-header and strict-tool grammars with TmlOutput - #457

Closed
brandonmmusic-max wants to merge 4 commits into
NVIDIA:mainfrom
brandonmmusic-max:tml-untyped-headers-and-content-grammar
Closed

brandonmmusic-max wants to merge 4 commits into
NVIDIA:mainfrom
brandonmmusic-max:tml-untyped-headers-and-content-grammar

Conversation

@brandonmmusic-max

@brandonmmusic-max brandonmmusic-max commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Why

Two Helios TMLv0 handling defects affect Responses and Chat Completions serving with Inkling 2 models (introduced in #304 and hardened in #405, with strict function tools added in #418 and Inkling 2 Mini merged in #433):

  1. Silent reasoning-only completion on malformed TML model headers. When a model emits a reasoning frame followed by <|message_model|> and non-empty header text (for example a tool name and partial JSON arguments where <|content_invoke_tool_json|> was dropped) and then closes with <|end_message|> or <|content_model_end_sampling|>, TmlOutput (helios/src/output/tml.rs) discarded the header text and returned Ok on Termination::Eos. Before this change, /v1/responses emitted response.output_item.done(reasoning) followed by response.completed(output=[reasoning]) with status: "completed" and no error, causing agent clients to treat a broken tool turn as a finished reply.
  2. TMLv0 content-header and strict-tool grammar mismatches against TmlOutput. Both GrammarCompiler::compile_content_headers (helios/src/grammar.rs) and GrammarCompiler::compile_strict_tml (helios/src/grammar/strict.rs, added in Add strict function-tool schemas for DSML, Qwen, GLM and TML parsers #418) enforced two rules stricter than TmlOutput:
    • Every tool rule required self.marker(name) before <|content_invoke_tool_json|>, even though TmlOutput treats the header name as optional and Inkling 2 natively emits <|message_model|><|content_invoke_tool_json|> without a header name. Before this change, activating a custom grammar (such as start: /(?s:.+)/ alongside declared tools) or "strict": true on a function tool masked out <|content_invoke_tool_json|> right after <|message_model|>, causing models either to print raw tool JSON inside <|content_text|> or to loop in thinking frames.
    • Non-required tool envelopes compiled as (answer | tools), allowing text alone, tools alone, or tools followed by text, while rejecting a visible text preamble followed by tool calls even though TmlOutput parses that frame sequence directly.

What Changed

  1. helios/src/output/tml.rs and helios/src/server/request/tml_tests.rs:
    • Added AnswerState (Empty, HeaderWithoutContent, Emitted) to TmlOutput.
    • Recorded HeaderWithoutContent when a non-empty model header (model && at > 0) closes on <|end_message|> or <|content_model_end_sampling|> while answer == Empty.
    • Marked answer = Emitted whenever non-thinking visible content or a non-empty tool invocation body is emitted.
    • Returned an error from TmlOutput::finish() on Termination::Eos when answer == HeaderWithoutContent, preserving existing behavior for empty model headers, non-model role frames, external terminations (OutputLimit, UserStop, Cancelled, ExecutionError), and turns that emit visible text or a tool call before or after an untyped header.
    • Added unit tests for both <|end_message|> and <|content_model_end_sampling|> closure and real Inkling 2 tokenizer snapshot regression tests replaying captured malformed header tokens through Decoder and Encoder.
  2. helios/src/grammar.rs and helios/src/server/request/tml_tests.rs:
    • Added a factored tool_unnamed rule (<|content_invoke_tool_json|> @payload_any <|end_message|>) backed by a single JSON schema enum over registered tool names, avoiding N-way Earley ambiguity across large tool sets while keeping named headers (tool_{index}) paired with per-tool const schemas.
    • Changed the tool-enabled ending from (answer | tools) to (answer ({restart} thinking* tool)* | tools), matching XTML's wrapped_answer (ws tool)* framing while keeping at most one @answer frame.
    • Added content_headers_grammar_allows_preamble_before_tools in helios/src/grammar.rs and inkling_stress_untyped_closed_header_must_surface_failure and inkling_stress_custom_grammar_preamble_then_tool in helios/src/server/request/tml_tests.rs.
  3. helios/src/grammar/strict.rs (after merging main b9cac839 including Add strict function-tool schemas for DSML, Qwen, GLM and TML parsers #418):
    • Added a factored tool_unnamed rule (<|content_invoke_tool_json|> (@payload_0 | ... | @payload_k) <|end_message|>) in compile_strict_tml so unnamed tool headers validate against each active tool's strict or default wrapper schema while named headers retain per-tool pairing.
    • Updated the non-required ending in compile_strict_tml from (answer | tools) to (answer ({restart} thinking* tool)? | tools) when single_call is set and (answer ({restart} thinking* tool)* | tools) otherwise.
    • Added a TML_unnamed case to strict_tool_wire_grammars_enforce_constraints and added strict_tml_grammar_allows_unnamed_headers_and_preamble_before_tools covering multi-tool unnamed headers, schema and undeclared-tool rejection, named header mismatch rejection, and preamble-then-tool framing with both parallel and single_call limits.

Claimed Result

  • Malformed TMLv0 turns whose non-empty model header closes without a content-kind token and without any visible text or tool call fail at EOS and surface response.failed (server_error) on /v1/responses instead of completing with output=[reasoning].
  • TMLv0 grammar-constrained requests (both compile_content_headers and compile_strict_tml for "strict": true function tools) accept both unnamed and named tool headers as well as a visible text preamble followed by tool calls, while continuing to reject unregistered tools, mismatched header names, schema-violating or non-object tool arguments, duplicate @answer frames, and reasoning-only terminations.

Supporting Evidence

  • Merged cleanly with NVIDIA/hyperflare-inference main at b9cac839.
  • Unit tests (cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server):
    • output::tml::tests::, frontend::tml::tests::, grammar::tests::, grammar::strict::tests::, server::protocol::tests::, and server::output::tests::: 124 passed, 0 failed (including content_headers_grammar_allows_preamble_before_tools, strict_tool_wire_grammars_enforce_constraints with TML_unnamed, strict_tml_grammar_allows_unnamed_headers_and_preamble_before_tools, and both untyped-header EOS unit tests).
    • Real tokenizer snapshot suite (FLARE_INKLING2_TEST_SNAPSHOT=... --ignored --test-threads=1 server::request::tml_tests::): 8 passed, 0 failed (including a_model_frame_without_a_content_kind_reports_a_failed_response, inkling_stress_untyped_closed_header_must_surface_failure, inkling_stress_custom_grammar_preamble_then_tool, structured_output_grammars_constrain_frames, and outputs_match_reference_parses).
  • Live SM120 GPU verification (TML-d24-varloop-research on RTX PRO 6000 Blackwell):
    • Before tool_unnamed in compile_content_headers, /v1/chat/completions and /v1/responses with 178 declared tools and grammar: "start: /(?s:.+)/" returned 0/5 tool calls (printing raw tool JSON as text or looping in thinking frames).
    • After adding tool_unnamed and preamble-then-tool support across compile_content_headers and compile_strict_tml, /v1/responses with grammar: "start: /(?s:.+)/" returns 5/5 tool calls on the 178-tool prompt and 5/5 tool calls (4/5 ['reasoning', 'message', 'function_call']) on preamble-plus-tool prompts, /v1/responses with "strict": true on get_weather returns HTTP 200 with a schema-conforming function_call, and multi-turn Chat/Responses tool round-trip suites (agentic_suite.py) pass SUITE: PASS (3/3 tool calls on every tool case, 0 failed trials, 0 server errors).

Unrun Checks and Limitations

Attribution

  • Credit to @madarkadonk (madar on Local Inference Lab Discord) for the initial untyped TML model-header patch, the captured malformed terminal-header token sequence, and both TMLv0 stress regression tests (inkling_stress_untyped_closed_header_must_surface_failure and inkling_stress_custom_grammar_preamble_then_tool).

Discord: no username provided

…out a content kind

Why:
When a TMLv0 model emits a reasoning frame followed by <|message_model|> and
non-empty header text (such as a tool name and partial arguments where
<|content_invoke_tool_json|> was dropped) and then closes the frame on
<|end_message|> or <|content_model_end_sampling|>, TmlOutput discarded the
header text and returned Ok on Termination::Eos. Before this change,
/v1/responses emitted response.output_item.done(reasoning) followed by
response.completed(output=[reasoning]) with status completed and no error.

What changed:
- Add AnswerState (Empty, HeaderWithoutContent, Emitted) to TmlOutput in
  helios/src/output/tml.rs.
- Record HeaderWithoutContent when a non-empty model header closes on
  <|end_message|> or <|content_model_end_sampling|> before any visible
  content or tool call has been emitted.
- Mark answer as Emitted whenever non-thinking visible content or a
  non-empty tool invocation body is emitted.
- Return an error from TmlOutput::finish() on Termination::Eos when
  answer is HeaderWithoutContent while preserving existing behavior for
  empty model headers, non-model role frames, external terminations, and
  turns that emit visible text or a tool call.
- Add unit tests in helios/src/output/tml.rs and a real tokenizer snapshot
  regression test in helios/src/server/request/tml_tests.rs.

Claimed result:
Malformed TMLv0 turns whose non-empty model header closes without a content
kind and without any visible output or tool call fail at EOS and surface
response.failed on /v1/responses instead of completing with reasoning only.

Supporting evidence:
- output::tml::tests and server::request::tml_tests (with
  FLARE_INKLING2_TEST_SNAPSHOT) pass on upstream main ee49d85.
- Limitation: non-model role frames (<|message_tool|>, <|message_user|>,
  <|message_system|>) remain ignored per tml-renderers semantics.

Design-Signed-Off-By: Brandon M. Music; design-review=1af4
Signed-off-by: Brandon M. Music <266531604+brandonmmusic-max@users.noreply.github.com>
…Lv0 grammars

Why:
Two mismatches existed between TmlOutput (helios/src/output/tml.rs) and
GrammarCompiler::compile_content_headers (helios/src/grammar.rs):
1. TmlOutput treats the tool name in a <|message_model|> header before
   <|content_invoke_tool_json|> as optional, and Inkling 2 models natively
   emit <|message_model|><|content_invoke_tool_json|> with no header name.
   Before this change, compile_content_headers required self.marker(name)
   before <|content_invoke_tool_json|>, masking out
   <|content_invoke_tool_json|> after <|message_model|> and preventing
   grammar-constrained runs from invoking tools natively.
2. Before this change, compile_content_headers compiled tool-enabled
   envelopes as (answer | tools), rejecting a visible text preamble
   followed by tool calls even though TmlOutput parses that sequence.

What changed:
- Add a factored tool_unnamed rule (<|content_invoke_tool_json|>
  @payload_any <|end_message|>) using a single JSON schema enum over
  registered tool names, avoiding N-way Earley ambiguity across large tool
  sets while keeping named headers paired with matching @payload_i schemas.
- Change the tool-enabled ending from (answer | tools) to
  (answer ({restart} thinking* tool)* | tools), matching XTML's
  wrapped_answer (ws tool)* framing while keeping at most one @answer frame.
- Add content_headers_grammar_allows_preamble_before_tools in
  helios/src/grammar.rs and inkling_stress_* snapshot regression tests in
  helios/src/server/request/tml_tests.rs.

Claimed result:
TMLv0 grammar-constrained requests with declared tools accept unnamed and
named tool headers as well as a visible preamble frame followed by tool
calls, while still rejecting unregistered tools, mismatched header names,
invalid tool arguments, duplicate @answer frames, and reasoning-only
terminations.

Supporting evidence:
- grammar::tests, output::tml::tests, frontend::tml::tests, and all 8
  FLARE_INKLING2_TEST_SNAPSHOT tests in server::request::tml_tests pass on
  upstream main ee49d85.
- Live SM120 GPU verification against TML-d24-varloop-research with
  grammar start: /(?s:.+)/ and 178 tools moved from 0/5 to 5/5 tool calls
  and 6/6 preamble-plus-tool responses.
- Limitation: non-TMLv0 model families were verified through unit tests
  only, not live GPU serving.

Design-Signed-Off-By: Brandon M. Music; design-review=1af4
Signed-off-by: Brandon M. Music <266531604+brandonmmusic-max@users.noreply.github.com>
Why:
PR NVIDIA#418 (0b09434) merged into main after NVIDIA#457 opened, adding strict
function-tool wire grammars in helios/src/grammar/strict.rs including
compile_strict_tml for TMLv0 models.

What changed:
- Merged NVIDIA/hyperflare-inference main (b9cac83) into
  tml-untyped-headers-and-content-grammar with no conflicts.

Claimed result:
The branch incorporates main (b9cac83) cleanly so compile_strict_tml can
receive the same unnamed-header and preamble-before-tool alignment as
compile_content_headers.

Supporting evidence:
- Clean automatic merge with zero conflicts; full Helios unit and Inkling 2
  tokenizer snapshot suites run on the follow-up commit.
- Limitation: non-TMLv0 model families are covered by unit tests only.

Design-Signed-Off-By: Brandon M. Music; design-review=1af4
Signed-off-by: Brandon M. Music <266531604+brandonmmusic-max@users.noreply.github.com>
…strict TMLv0 grammars

Why:
PR NVIDIA#418 (0b09434) added GrammarCompiler::compile_strict_tml in
helios/src/grammar/strict.rs with the same two constraints stricter than
TmlOutput that compile_content_headers had before this branch:
1. Each tool rule required self.marker(&tool.name) before
   <|content_invoke_tool_json|>, even though Inkling 2 natively emits
   unnamed <|message_model|><|content_invoke_tool_json|> tool headers and
   TmlOutput treats the header name as optional.
2. Non-required tool envelopes compiled as (answer | tools), rejecting a
   visible text preamble followed by tool calls even though TmlOutput
   parses that frame sequence directly.

What changed:
- Added a factored tool_unnamed rule (<|content_invoke_tool_json|>
  (@payload_0 | ... | @payload_k) <|end_message|>) in compile_strict_tml so
  unnamed tool headers validate against each active tool's strict or
  default wrapper schema while named headers keep per-tool pairing.
- Updated the non-required ending in compile_strict_tml from (answer | tools)
  to (answer ({restart} thinking* tool)? | tools) when single_call is set
  and (answer ({restart} thinking* tool)* | tools) otherwise.
- Added a TML_unnamed case to strict_tool_wire_grammars_enforce_constraints
  and a new strict_tml_grammar_allows_unnamed_headers_and_preamble_before_tools
  unit test covering multi-tool unnamed headers, schema and undeclared-tool
  rejection, named header mismatch rejection, and preamble-then-tool framing
  with both parallel and single_call limits.

Claimed result:
Strict function-tool requests ("strict": true) on TMLv0 models accept both
unnamed and named tool headers as well as a visible text preamble followed
by tool calls while enforcing each tool's strict JSON schema.

Supporting evidence:
- output::tml::tests, frontend::tml::tests, grammar::tests,
  grammar::strict::tests, server::protocol::tests, and server::output::tests
  pass (124 passed, 0 failed) and all 8 real Inkling 2 tokenizer snapshot
  tests in server::request::tml_tests pass on NVIDIA/hyperflare-inference
  main (b9cac83).
- Live SM120 GPU verification on RTX PRO 6000 Blackwell with a strict
  get_weather function tool ("strict": true) returned HTTP 200 and a valid
  schema-conforming function_call on /v1/responses.
- Limitation: non-TMLv0 strict tool families (Qwen, GLM, DSML) were verified
  through existing grammar::strict::tests only, not live GPU serving.

Design-Signed-Off-By: Brandon M. Music; design-review=1af4
Signed-off-by: Brandon M. Music <266531604+brandonmmusic-max@users.noreply.github.com>
@brandonmmusic-max brandonmmusic-max changed the title Fail untyped TML model headers at EOS and align TMLv0 content-header grammars with TmlOutput Fail untyped TML model headers at EOS and align TMLv0 content-header and strict-tool grammars with TmlOutput Nov 22, 2026
@flare-autobot

Copy link
Copy Markdown
Collaborator

A case file has been opened for 457
Case File Intake Report

To opt out, include #autobot:ignore in the PR or any comment.

@flare-autobot

Copy link
Copy Markdown
Collaborator

Full Review

Changes Requested

Blockers:

  • None. The production change (parser state + two grammar rules) is ~60 lines, in the right layer, adds no per-model branch or flag, and each grammar change is a superset of the old language for tool-enabled TMLv0.

Should fix:

  • docs/api.md states none of the three user-visible TMLv0 changes (unnamed tool headers, preamble-then-tools, the new EOS failure) — docs/api.md:585-602, :443-444; AGENTS.md:225. → Add one paragraph.
  • The EOS guard keys on header shape, not on "no answer was produced". [MODEL,"bash",TEXT,END] and [MODEL,JSON_CALL,END] still complete silently with output=[reasoning] (tml.rs:282-288, :207-209, :335-337). → Widen, or pin the boundary with tests plus a doc sentence.
  • The strict grammar re-creates the N-way alternation the description says it avoids. strict.rs:1599-1603 alternates every per-tool wrapper schema while grammar.rs:381-391 factors one enum; largest coverage is two tools, live evidence one. → Comment why the const-named wrappers force this (strict.rs:873-892) and test at realistic tool counts.
  • Two new ignored snapshot tests are one test, and neither uses the reference fixture. tml_tests.rs:393-439 replays the identical token stream as :246-282 with weaker assertions; the new tml.rs:626-639 unit test compares run() with run(). → Delete the duplicate, assert literals, add a case to generate_inkling2_fixtures.py:399-417.
  • Grammar and parser still disagree in the other direction: both endings require a <|message_model|> restart before a call after text (grammar.rs:405, strict.rs:1616-1618); TmlOutput accepts it without one (tml.rs:250-258). → Accept it, or say the restart is required under a grammar.
  • 1 more: the evidence is not reproducible here — TML-d24-varloop-research is rejected on this branch (ignition/recipes/inkling2/config.py:88-92, closed Add TML-d24-varloop-research checkpoint and SM120 qualification to Inkling 2 Mini #468), FLARE_INKLING2_TEST_SNAPSHOT=... is a placeholder, agentic_suite.py (not opened) has no path.

Nits:

  • 6 nits: fourth copy of the test wire-token splitter (strict.rs:4572-4588); inkling_stress_* names and "an/the Inkling 2 tokenizer"; the client-visible error narrates cause (tml.rs:400); duplicated role-frame cases and single-use payload_refs; title/commit-body prose; the strict-TMLv0 truncation checks from docs/TODO.txt:25-28 neither run nor listed.

To opt out of future reviews, put #autobot:ignore in your response.

@flare-autobot flare-autobot added area:api Serving API, protocol encoding, tool parsing, and client-visible behavior. bug Something isn't working model:inkling-small Affected recipe or documented reproducer: inkling-small. Impact may be broader. triage:review Proposed change needs code review; this does not imply merge readiness. labels Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:api Serving API, protocol encoding, tool parsing, and client-visible behavior. bug Something isn't working model:inkling-small Affected recipe or documented reproducer: inkling-small. Impact may be broader. triage:review Proposed change needs code review; this does not imply merge readiness.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants