Skip to content

Preserve raw JSON tool arguments in TmlOutput for strict TMLv0 calls - #575

Merged
lukealonso merged 1 commit into
NVIDIA:mainfrom
fordbmorris:pr/tml-output-raw-json-args
Dec 4, 2026
Merged

lukealonso merged 1 commit into
NVIDIA:mainfrom
fordbmorris:pr/tml-output-raw-json-args

Conversation

@fordbmorris

@fordbmorris fordbmorris commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Why

For ToolParserKind::TmlJson (Inkling 2) with strict: true schemas containing unbounded "type": "integer" fields, TmlOutput::call (helios/src/output/tml.rs) previously round-tripped args through serde_json::Value (args.to_string()). Without arbitrary_precision, integers above u64::MAX (e.g., 30-digit IDs) silently rounded to binary64 scientific notation, failing OutputEncoder's strict TextGrammar validation with HTTP 500 (tracked in docs/TODO.txt).

What Changed

  • helios/src/output/tml.rs: deserialize {"name", "args"} into a #[serde(deny_unknown_fields)] struct carrying #[serde(borrow)] args: &'a RawValue, check args.trim().starts_with('{'), and emit the raw JSON object text verbatim (matching Qwen, GLM, and DeepSeek DSML raw-token preservation). Note: this also passes non-strict TMLv0 args verbatim without serde re-serialization and rejects duplicate wrapper keys as visible text.
  • helios/src/output/tml.rs, helios/src/grammar/strict.rs, tests/server/test_inkling2.py: add Rust unit tests for 30-digit integers and duplicate wrapper keys, plus a live strict-tool/truncation server test.

Benefit & Evidence

  • Eliminates HTTP 500 failures on >64-bit integers in strict TMLv0 tool calls without re-exporting cores.
  • Verified on ARM64 GB10: cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server (output::tml::, grammar::strict::, server::protocol::tests::strict, server::request::tml_tests:: all passing) and live 4-Spark TP4 Inkling 2 Small strict tool-calling qualification.

Caveats: Qualified live on Inkling 2 Small NVFP4 (4× GB10 ARM64 TP4). Non-strict TMLv0 calls now also forward raw args text verbatim, and duplicate wrapper keys fall back to visible text. Non-TML tool parsers are untouched.

Discord: woooflet

@flare-autobot

Copy link
Copy Markdown
Collaborator

A case file has been opened for 575.
Case File Intake Report

Future reviews will auto-run 90 minutes after code updates are pushed.

  • Re-review sooner: Call @flare-autobot after push.
  • Opt-out: Include #autobot:ignore in the PR or any comment.

@fordbmorris
fordbmorris force-pushed the pr/tml-output-raw-json-args branch from 07955d7 to c7fae93 Compare November 28, 2026 19:42
@flare-autobot

Copy link
Copy Markdown
Collaborator

Autobot Review

Full Review · Value Proposition · Case File

Recommendation: Ready To Merge

The production fix in helios/src/output/tml.rs is minimal and correct: borrowed RawValue parsing preserves >64-bit integers and exact argument JSON for strict TMLv0 calls without new dependencies or format changes. Only minor non-blocking nits remain around docs/TODO.txt bookkeeping, test fixture reuse, and PR command disclosure.

  • Blockers: 0
  • Should fix: 0
  • Subtractive suggestions: 0
  • Nits: 4

Have your agent review the Full Review for complete verified findings, file:line citations, and suggested changes.

To opt out, include #autobot:ignore in your post or comment.

@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. priority:P2 Normal bug priority: workflow failure or diagnosis with narrower impact or an available workaround. labels Nov 29, 2026
When a TMLv0 core serves a `strict: true` function tool whose JSON Schema
declares an unbounded integer property, constrained generation can emit an
integer exceeding 64 bits (for example, a 30-digit identifier). Previously,
`TmlOutput::call` in `helios/src/output/tml.rs` deserialized the invocation
payload through `serde_json::Value` (which lacks `arbitrary_precision`) and
re-serialized `args` via `Value::to_string()`, silently rounding integers
above `u64::MAX` into scientific-notation binary64 floats. `OutputEncoder`
then rejected the re-serialized string against the compiled strict
`TextGrammar`, failing the live request with HTTP 500.

Before this change, `TmlOutput::call` parsed `{"name", "args"}` into
`serde_json::Value` and emitted `args.to_string()`. After this change,
`TmlOutput::call` deserializes the wrapper into a `#[serde(deny_unknown_fields)]`
struct carrying `name: String` and `args: &'a serde_json::value::RawValue`,
verifies that the raw slice starts with `{`, and emits the exact JSON object
text verbatim. Duplicate wrapper keys and unknown wrapper keys are rejected
and surfaced as visible text, matching prior TMLv0 recovery semantics. Added
`call_preserves_raw_json_arguments_including_arbitrary_precision_integers` in
`helios/src/output/tml.rs`, `tml_strict_parser_preserves_30_digit_integers` in
`helios/src/grammar/strict.rs`, and `test_strict_tml_tool_calls_and_truncation`
in `tests/server/test_inkling2.py`.

Strict TMLv0 function calls now preserve arbitrary-precision integers and exact
JSON argument text from constrained decoding through `TmlOutput` and
`OutputEncoder` validation, matching the raw-token preservation already used by
the Qwen, GLM, and DeepSeek DSML parsers. No model core re-export or wire
format change is required.

Evidence: on `dgx2` (NVIDIA GB10 ARM64), `cargo test --locked --release
--manifest-path helios/Cargo.toml --features runtime-core,server` passed all
7 `output::tml::` tests, all 28 active `grammar::strict::` tests (1 ignored
DeepSeek checkpoint fixture), both `server::protocol::tests::strict` tests, and
all 5 `server::request::tml_tests::` tests against the Inkling 2 checkpoint
tokenizer. Live 4-Spark TP4 serving verification on Inkling 2 Small NVFP4
follows in deployment.

Discord: woooflet

Design-Signed-Off-By: Antigravity (Gemini-4-Neon); design-review=2e5b
Signed-off-by: woooflet <ford@fordmorris.com>
@fordbmorris

Copy link
Copy Markdown
Contributor Author

Rebased onto latest main (571a4471), refreshed Design-Signed-Off-By: Antigravity (Gemini-4-Neon); design-review=2e5b and Signed-off-by: woooflet <ford@fordmorris.com> (verified via .githooks/commit-msg), and re-verified on rebased main:

  • cargo test --locked --manifest-path helios/Cargo.toml --features runtime-core,server --lib output::tml::: 7/7 passed (including call_preserves_raw_json_arguments_including_arbitrary_precision_integers).
  • cargo test --locked --manifest-path helios/Cargo.toml --features runtime-core,server --lib grammar::strict::: 28/28 passed (1 ignored DeepSeek checkpoint fixture), including tml_strict_parser_preserves_30_digit_integers.
  • Also re-verified 35/35 strict TMLv0 live serving tests (including 30-digit integer Chat & Responses buffered and streamed) on 4× DGX Spark GB10 TP4.

Discord: woooflet

@fordbmorris
fordbmorris force-pushed the pr/tml-output-raw-json-args branch from c7fae93 to a0d9065 Compare December 2, 2026 04:47
@flare-autobot

Copy link
Copy Markdown
Collaborator

Autobot Review

Full Review · Value Proposition · Case File

Recommendation: Ready To Merge

Fixes a real, reproducible HTTP 500 still live on main (helios/src/output/tml.rs:365) with a minimal, zero-dependency change in the correct layer (TmlOutput::call), bringing TMLv0 to parity with the RawValue preservation Qwen/GLM already uses. The rebase onto 571a4471 (head a0d9065) introduces no correctness, concurrency, memory, or CI regressions; only optional test simplifications and minor bookkeeping nits remain.

  • Blockers: 0 · Should fix: 0 · Subtract/Simplify: 2 · Nits: 4
Walkthrough
  • helios/src/output/tml.rs:22-23,342-376: Replaces serde_json::Value deserialization + args.to_string() re-serialization in TmlOutput::call with a local #[serde(deny_unknown_fields)] RawCall<'a> borrowing args: &'a RawValue (via the already-enabled raw_value feature, helios/Cargo.toml:52); trims outer whitespace, checks args.starts_with('{'), emits args.to_owned() verbatim.
  • helios/src/output/tml.rs:620-642: Adds call_preserves_raw_json_arguments_including_arbitrary_precision_integers covering 30-digit positive/negative/nested integers, reversed wrapper key order, and duplicate wrapper key fallback to visible text.
  • helios/src/grammar/strict.rs:3819-3922: Adds tml_strict_parser_preserves_30_digit_integers, exercising GrammarCompiler, compile_presented_strict_tools, OutputPipeline, validate_strict_tool_schema, and TextGrammar::validate end-to-end across top-level, anyOf, $ref, nested object, and nested array cases.
  • tests/server/test_inkling2.py:121-209: Adds live TP4 test_strict_tml_tool_calls_and_truncation (buffered/streamed Chat, Chat max_tokens=10, buffered Responses, max_output_tokens=10); module-skipped without FLARE_RUN_CUDA_TESTS=1 and FLARE_INKLING2_TEST_URL.
Merge Risk: Low · up to a0d9065
  • Isolated per-request parser change: Only TmlOutput::call (helios/src/output/tml.rs:342-376) alters production behavior — per-request parser state, no locks, shared buffers, CUDA graph/op-contract changes, or cross-request blast radius.
  • Net reduction in hot-path allocation: Borrowed &'a RawValue removes an intermediate heap AST allocation per TMLv0 tool call while preserving the 1 MiB parser bound (helios/src/output/tml.rs:279,303) and 8 MiB response bound (helios/src/server/output.rs:1803).
  • Well-bounded behavioral delta: Non-strict TMLv0 forwards trimmed raw args verbatim and rejects duplicate wrapper keys as visible text via #[serde(deny_unknown_fields)]; both disclosed in the PR description and covered by unit tests.
Pre-merge checks: ✅ 4 passed · ⚠️ 1 warning
Subtract / Simplify (non-blocking)
  1. Deduplicate the 30-digit schema fixture (helios/src/grammar/strict.rs:3827-3848). tml_strict_parser_preserves_30_digit_integers copies big and the 20-line big_schema verbatim from qwen_and_glm_strict_parsers_preserve_30_digit_integers just above (:3726-3746). Extract a shared fn big_integer_case() -> (&'static str, Value) helper in mod tests (~20 net lines removed, zero coverage loss).
  2. Reuse the service fixture and collapse urllib POST boilerplate (tests/server/test_inkling2.py:121-209). The test re-fetches /v1/models (:122-123) though service already resolves url and model["id"] (:31-33), and repeats identical Request + urlopen + json.load plumbing three times (:155-169, :176-189, :194-207). Exposing url/model (or a post(path, body) helper) alongside ask.chunk (:67) removes the redundant call and ~25–30 lines.
Nits
  1. docs/TODO.txt bookkeeping (docs/TODO.txt:5-8; :12-15 on main): The strict TMLv0 qualification item remains [ ] while tests/server/test_inkling2.py:121-209 covers Chat buffered/streamed and Responses buffered/truncated (Responses streamed only in the external 35/35 run). Close/update with recorded results once streamed Responses is covered, or note why it stays open.
  2. Optional API doc note (docs/api.md:614-631): Consider one sentence noting TMLv0 forwards raw args verbatim (outer whitespace trimmed) and surfaces duplicate wrapper keys as visible text.
  3. Out-of-scope follow-up (multi-turn precision): Multi-turn tool arguments still round-trip through serde_json::Value at next-turn ingress (helios/src/server/protocol/decode.rs:91-101), TMLv0 prompt rendering (helios/src/frontend/tml.rs:75-88,149-174), and Anthropic non-streaming tool_use.input (helios/src/server/protocol/encode.rs:334) — worth tracking separately if >64-bit integer round-trips matter.
  4. Evidence provenance: Note the core/command behind the "35/35 strict TMLv0 live serving tests" claim and confirm --release on a0d9065 to match .github/workflows/native-serving.yml:63 (not opened),68.
Dropped on verification
  • Missing DCO Signed-off-by: + stale Design-Signed-Off-By digest: Stale against pre-rebase commits (07955d702c / c7fae93). On head a0d9065 the author rebased onto 571a4471 and added Signed-off-by: woooflet <ford@fordmorris.com> plus a refreshed Design-Signed-Off-By (verified via .githooks/commit-msg).
  • PR description misstating duplicate-key behavior: Stale — the current description discloses both non-strict verbatim forwarding and duplicate-key fallback to visible text.
  • "No JSON-object guard before hand-off" / proposed from_str::<&RawValue> fix: Factually incorrect — serde_json::from_str::<RawCall<'_>>(body) already validates parsed.args as a complete JSON value, so args.starts_with('{') guarantees a valid JSON object. Only remaining delta is > f64::MAX numbers like 1e500 (helios/src/server/output.rs:148,1823), matching existing Qwen/GLM behavior (helios/src/output/tagged.rs:927).
  • "Not tested for non-strict" / Major severity on docs/api.md: Downgraded — helios/src/output/tml.rs:620-642 exercises non-strict TmlOutput (parser() at :415 has no strict: true) for raw 30-digit integers and duplicate wrapper keys; the doc sentence stays a Nit.
  • "Delete unprovable key-order assertion" (tests/server/test_inkling2.py:141): Over-flagged — the live test also qualifies strict schema property emission order; removing a valid 1-line assertion adds churn.
  • Parametrized service fixture duplicating effort="none" calls: Low signal — test_streamed_reasoning_and_answer (tests/server/test_inkling2.py:80-82) already follows the same pattern.
  • Inflated reduction estimates: Corrected "~44 duplicated lines" to ~20 net lines in helios/src/grammar/strict.rs, and "four" urllib POST blocks to 3 POSTs plus 1 /v1/models GET.

Have your agent review the Full Review for complete verified findings, file:line citations, and suggested changes.

To opt out, include #autobot:ignore in your post or comment.

@lukealonso
lukealonso merged commit 905aa6e into NVIDIA:main Dec 4, 2026
lukealonso added a commit that referenced this pull request Dec 5, 2026
… ToolParser

Why:
Commit 905aa6e (#575) added the unit test
`tml_strict_parser_preserves_30_digit_integers` in
`helios/src/grammar/strict.rs` constructing `contract::ToolParser` without
the `open` and `close` fields added by 2acc3f3 (#670). As a result,
compiling `flare-helios` unit tests failed with `error[E0063]: missing
fields close and open in initializer of contract::ToolParser`.

What changed:
Added `open: String::new()` and `close: String::new()` to the `ToolParser`
initializer in `tml_strict_parser_preserves_30_digit_integers` in
`helios/src/grammar/strict.rs`, matching the other `ToolParser` test
literals in the module. No production code changed.

Claimed result:
Restores `flare-helios` unit-test compilation and exercises
`tml_strict_parser_preserves_30_digit_integers` without altering runtime
behavior.

Supporting evidence (Linux x86_64 CPU):
- `cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --lib -- grammar::strict::`:
  28 passed, 0 failed, 1 ignored (`ds41_checkpoint_strict_dsml_fixture_replays_complete_masks`,
  requires `FLARE_DEEPSEEK_TEST_SNAPSHOT`).

Design-Signed-Off-By: Antigravity (Gemini 4 Neon); design-review=2e5b
Signed-off-by: Luke Alonso <lalonso@gmail.com>
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. priority:P2 Normal bug priority: workflow failure or diagnosis with narrower impact or an available workaround. 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.

3 participants