Skip to content

Bound synthesized tool-call IDs to 37 characters across HTTP protocols - #637

Merged
yatesdr merged 1 commit into
NVIDIA:mainfrom
flare-autobot:fix/issue-447-bound-synthesized-tool-call-ids
Nov 30, 2026
Merged

yatesdr merged 1 commit into
NVIDIA:mainfrom
flare-autobot:fix/issue-447-bound-synthesized-tool-call-ids

Conversation

@flare-autobot

Copy link
Copy Markdown
Collaborator

Fixes #447

Why

When a model output parser emits Event::ToolBegin with id: None—which all nine native tool-call parsers in helios/src/output/ do—Helios synthesizes a tool-call identifier for HTTP responses on POST /v1/chat/completions, POST /v1/responses, and POST /v1/messages. Each generation request receives a request identifier formatted in helios/src/server/http.rs as {prefix}-{run:016x}-{seq}, combining a protocol prefix, a random 64-bit per-server-start run value from HttpState (helios/src/server.rs), and a monotonic AtomicU64 request counter.

On Chat Completions, Encoder::new (helios/src/server/protocol/encode.rs) appends _{choice} per choice, and Accumulator::apply (helios/src/server/output.rs) previously concatenated call_{self.id}_{index}. For choice 0 and call index 0, the fixed characters total 35 (call_chatcmpl-<16 hex>-_0_0), so tool_calls[].id reaches 41 characters once seq hits 100000 (or at seq = 10000 when a response contains 10 or more tool calls). OpenAI and Azure OpenAI Chat Completions reject tool_calls[].id values longer than 40 characters with HTTP 400 string_above_max_length, causing multi-provider conversation replay from long-running Flare servers to fail validation. ResponseOutput::apply (helios/src/server/output.rs) similarly concatenated call_{request_id}_{index} without a length bound for Responses and Messages, and both ResponseOutput::apply and ResponseOutput::close mutated self.open before finishing tool-call ID and unclosed-tool validation.

Hashing the scope identifier and call index with a domain-separated, length-delimited SHA-256 input and encoding 128 bits of the digest as call_ plus 32 lowercase hexadecimal digits decouples tool-call identifier length from request identifier length. Every synthesized identifier stays fixed at 37 ASCII characters—within OpenAI Chat Completions' 40-character limit and the [a-zA-Z0-9_-]+ character set accepted across Chat Completions, Responses, and Messages—while remaining deterministic for streaming-versus-buffered parity, injective over (scope_id, index), and retaining full 64-bit per-start run entropy across calls, choices, requests, restarts, and hosts.

What Changed

  • Synthesized tool-call ID generation (helios/src/server/output.rs):
    • Before: Accumulator::apply formatted missing IDs as format!("call_{}_{}", self.id, index) and ResponseOutput::apply formatted them as format!("call_{request_id}_{index}"). use sha2::{Digest, Sha256}; was imported only inside the #[cfg(test)] module.
    • After: Imported sha2::{Digest, Sha256} at module scope (gated behind #[cfg(feature = "server")] in helios/src/lib.rs, where server enables images -> frontend -> dep:sha2 in helios/Cargo.toml) and removed the duplicate test-module import. Added MAX_SYNTHESIZED_TOOL_CALL_ID_LEN = 40, SYNTHESIZED_TOOL_CALL_ID_LEN = 37, a compile-time assert!(SYNTHESIZED_TOOL_CALL_ID_LEN <= MAX_SYNTHESIZED_TOOL_CALL_ID_LEN), and synthesize_tool_call_id(scope_id: &str, index: usize) -> String. The helper hashes b"flare-tool-call-id-v1\0", (scope_id.len() as u64).to_le_bytes(), scope_id.as_bytes(), and (index as u64).to_le_bytes() with SHA-256 and encodes the first 16 digest bytes as call_ followed by 32 lowercase hexadecimal characters. Both Accumulator::apply and ResponseOutput::apply call synthesize_tool_call_id when Event::ToolBegin has id: None; explicit Event::ToolBegin { id: Some(...) } values still pass through existing nonempty and per-response uniqueness validation unchanged.
  • No partial state mutation on rejected tool events (helios/src/server/output.rs):
    • Before: ResponseOutput::apply called self.close(&mut changes)? before validating that the tool-call ID was nonempty and unique, and ResponseOutput::close cleared self.open via self.open.take() before rejecting an unclosed Block::Tool { ended: false, .. }.
    • After: ResponseOutput::apply synthesizes and validates nonempty, unique tool-call IDs before calling self.close(&mut changes)?, and ResponseOutput::close checks for an unclosed Block::Tool before setting self.open = None.
  • API documentation (docs/api.md): Documented the deterministic 37-character call_<32 lowercase hex> format, its hash inputs (request identifier embedding the random per-server-start run ID and monotonic counter, Chat Completions choice index, and call index), the 40-character Chat Completions maximum, and the [a-zA-Z0-9_-]+ character set.
  • Tests (helios/src/server/output.rs, helios/src/server/protocol/tests.rs): Added unit and protocol tests covering seq values 0, 99_999, 100_000, and u64::MAX, multi-choice Chat Completions, 12 to 128 parallel calls, Responses (function_call, custom_tool_call, and strict: true function tools), Messages (tool_use), streaming-versus-buffered parity, simulated restarts with distinct 64-bit run values, suffix-concatenation disambiguation, explicit ID passthrough, multi-turn decode and template_messages (order_tool_result_batch) round-tripping with reversed tool results, and rejection without partial state mutation.
  • Compatibility and resource lifetimes: HTTP request IDs (x-request-id, response top-level id, and failure logs), Responses item_id values (<= 54 characters up to seq = u64::MAX, within the 64-character Responses item.id limit), explicit model-supplied tool-call IDs, incoming historical tool-call ID decoding in helios/src/server/protocol/decode.rs, and all Protobuf / ModelContract / model core formats are unchanged. Previously exported cores load and serve without re-export, and no GPU buffers, CUDA graphs, or asynchronous lifetimes change.

Claimed Benefit / Result

  • Verified in CPU unit and protocol tests: Every synthesized tool-call ID produced by Accumulator (Chat Completions) and ResponseOutput (Responses and Messages, including custom tools and strict: true function tools) is fixed at 37 ASCII characters matching ^call_[0-9a-f]{32}$—within OpenAI Chat Completions' 40-character limit and the [a-zA-Z0-9_-]+ alphabet—across request counters from 0 through u64::MAX (including 99_999 and 100_000), multiple choices, and up to 128 parallel calls, with identical IDs across streaming and buffered output and clean round-trip tool-result matching through decode and template_messages.
  • Verified in unit tests: Rejected empty or duplicate Event::ToolBegin IDs and ResponseOutput::finish/apply calls on an unclosed tool block return errors without mutating self.open, self.blocks, or self.calls.
  • Expected serving behavior (not exercised against a live GPU HTTP service): Long-running Flare servers past 100,000 requests emit Chat Completions tool_calls[].id values accepted by OpenAI and Azure OpenAI conversation replay validation while preserving cross-restart and cross-host uniqueness.

Supporting Evidence & Material Limitations

All Rust checks ran on Linux aarch64 (Ubuntu 24.04, rustc 1.99.1, ulimit -l unlimited) with FLARE_TEST_TEMPLATE_DIR prepared by tests/frontend/prepare_templates.py for gemma4, glm53, mimo_v2, minimax_m3, nemotron_h, qwen38, and step5:

  • cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --target-dir flare-cli/target: 1803 passed, 0 failed, 84 ignored (unit tests: 1741 passed, 46 ignored; integration and doc-tests: 62 passed, 38 ignored). Passing coverage includes:
    • server::output::tests::synthesized_tool_call_ids_are_bounded_deterministic_and_distinct
    • server::output::tests::response_output_rejects_invalid_tool_begin_and_unclosed_close_without_partial_mutation
    • server::protocol::tests::synthesized_tool_call_ids_stay_bounded_across_protocols_modes_and_restarts
    • server::protocol::tests::synthesized_high_counter_tool_call_ids_round_trip_through_decode_and_template_messages
      Zero compiler warnings in modified files (two pre-existing rustc 1.99 Atomic::fetch_update deprecation warnings in unrelated files).
  • cargo check --locked --release --manifest-path helios/Cargo.toml --tests --features runtime-core --target-dir flare-cli/target: passed, confirming builds omitting the server feature compile cleanly.
  • cargo test --locked --release --manifest-path flare/Cargo.toml --target-dir flare-cli/target: 245 passed, 0 failed, 4 ignored; zero warnings.
  • cargo test --locked --release --manifest-path flare-cli/Cargo.toml: 227 passed, 0 failed, 3 ignored; zero warnings.

Material limitations and unrun checks:

  • Live HTTP SDK verification (FLARE_API_TEST_URL=http://127.0.0.1:8000 .venv/bin/python -m pytest tests/server/test_protocols.py -q) was not executed because it requires an exported model core served by flare run on SM103/SM120/SM121 hardware.
  • Ignored tests requiring local checkpoints, exported cores, or GPU hardware (-- --ignored: 84 in helios, 4 in flare, 3 in flare-cli) were not executed.
  • Linux x86_64 and Windows x86_64-pc-windows-msvc builds were not executed locally.
  • Scheduling simulator (scripts/scheduling_sim/), TLA+ lifecycle conformance (verification/helios-lifecycle/check.py), and Kani proofs (cargo kani) were not run because scheduling, lifecycle, cache, and transport code did not change.

Discord: flare-autobot

When a model output parser emits a tool call without a provider-supplied
identifier, Helios synthesizes one from the request identifier and call index.
Because HTTP request identifiers include a protocol prefix, a 16-hex-digit
random per-server-start run identifier, and a monotonic decimal counter
(for example `chatcmpl-<16hex>-<seq>`), concatenating that identifier with the
choice and call indices reaches 41 characters on Chat Completions at request
counter 100000—or earlier when 10 or more tool calls appear in one response—and
exceeds OpenAI Chat Completions' 40-character maximum on `tool_calls[].id`,
which causes downstream clients and validators enforcing that limit to reject
responses from long-running servers. Hashing the scope identifier and call
index with a domain-separated, length-delimited SHA-256 input and encoding 128
bits of the digest as `call_` plus 32 lowercase hexadecimal digits keeps every
synthesized identifier fixed at 37 ASCII characters (within the 40-character
Chat Completions maximum and the `[a-zA-Z0-9_-]+` alphabet accepted by Chat
Completions, Responses, and Messages) while preserving determinism for
streaming-versus-buffered parity and retaining full per-start entropy across
calls, choices, requests, restarts, and hosts. In addition, `ResponseOutput`
previously mutated open-block state before rejecting invalid tool-begin events
or unclosed tool blocks; reordering those checks preserves clean state on
rejection without partial mutation.

Before this change, `Accumulator::apply` in `helios/src/server/output.rs`
formatted missing tool-call IDs as `call_{self.id}_{index}` (where `self.id`
is `{request_id}_{choice}` for Chat Completions) and `ResponseOutput::apply`
formatted them as `call_{request_id}_{index}` (for Responses and Messages);
`ResponseOutput::apply` closed any open block before validating that the
incoming tool-call ID was nonempty and unique, and `ResponseOutput::close`
cleared `self.open` before checking whether the open block was an unclosed
`Block::Tool`. After this change:
- `helios/src/server/output.rs` adds `synthesize_tool_call_id(scope_id, index)`,
  which hashes `b"flare-tool-call-id-v1\0"`, the little-endian `u64` byte length
  of `scope_id`, the `scope_id` bytes, and the little-endian `u64` `index` with
  SHA-256 and encodes the first 16 digest bytes as `call_` plus 32 lowercase
  hexadecimal characters (37 characters total, checked at compile time against
  the 40-character limit). Both `Accumulator::apply` and `ResponseOutput::apply`
  call `synthesize_tool_call_id` when `Event::ToolBegin` carries `id: None` and
  continue passing explicit model-supplied IDs through unchanged.
- `ResponseOutput::close` checks for an unclosed `Block::Tool` before clearing
  `self.open`, and `ResponseOutput::apply` synthesizes and validates nonempty,
  unique tool-call IDs before calling `self.close`.
- `docs/api.md` specifies the synthesized 37-character `call_<32 lowercase hex>`
  identifier format and its hash inputs (request identifier with random
  per-server-start run ID and monotonic counter, Chat Completions choice index,
  and call index).
- Unit and protocol tests in `helios/src/server/output.rs` and
  `helios/src/server/protocol/tests.rs` cover high request counters (`100000`
  and `u64::MAX`), multi-choice Chat Completions, 12 to 128 parallel calls,
  Chat Completions / Responses (`function_call` and `custom_tool_call`) /
  Messages (`tool_use`) and strict-tool streaming-versus-buffered parity,
  distinct IDs across simulated restarts and suffix-concatenation inputs,
  explicit ID passthrough, multi-turn `decode` and `template_messages`
  round-tripping with reversed tool results, and rejection without partial
  mutation on invalid `Event::ToolBegin` and unclosed `ResponseOutput::close`.
- Compatibility: request IDs (`x-request-id` and top-level response IDs),
  Responses `item_id` values, explicit model-supplied tool-call IDs, incoming
  historical tool-call ID decoding, and all model core / Protobuf formats are
  unchanged; existing exported cores work without re-export.

Claimed result: synthesized tool-call IDs remain fixed at 37 characters
(`call_` plus 32 lowercase hex digits) regardless of server uptime, request
counter magnitude, choice index, or call index across Chat Completions,
Responses, and Messages, and rejected `ResponseOutput` tool-begin or close
calls leave block state intact. Verified on CPU against the production
`Accumulator`, `ResponseOutput`, `Encoder`, `decode`, and `template_messages`
entry points; expected to prevent 40-character Chat Completions ID rejections
on live long-running Flare HTTP servers (live GPU HTTP serving was not run).

Evidence and limitations (run on Linux aarch64 Ubuntu 24.04 with rustc 1.99.1
and `FLARE_TEST_TEMPLATE_DIR` populated for gemma4, glm53, mimo_v2, minimax_m3,
nemotron_h, qwen38, and step5):
- `cargo test --locked --release --manifest-path helios/Cargo.toml --features
  runtime-core,server`: 1,803 passed, 0 failed, 84 ignored (1,741 unit passed,
  46 ignored; 62 integration/doc passed, 38 ignored), including all four added
  tool-call ID and partial-mutation tests; zero compiler warnings in changed
  files.
- `cargo check --locked --release --manifest-path helios/Cargo.toml --tests
  --features runtime-core`: passed, confirming the `sha2` import in
  `helios/src/server/output.rs` remains gated behind the `server` feature.
- `cargo test --locked --release --manifest-path flare/Cargo.toml`: 245 passed,
  0 failed, 4 ignored.
- `cargo test --locked --release --manifest-path flare-cli/Cargo.toml`: 227
  passed, 0 failed, 3 ignored.
- Unrun / not applicable: live HTTP SDK protocol tests
  (`tests/server/test_protocols.py`, which require an exported model core served
  by a live Flare HTTP server on SM103/SM120/SM121 hardware), checkpoint- and
  GPU-gated ignored Rust tests (84 in `helios`, 4 in `flare`, 3 in `flare-cli`),
  `heliopause` crate tests, and Linux x86_64 / Windows builds were not run.
  The scheduling simulator (`scripts/scheduling_sim/`), TLA+ lifecycle suite
  (`verification/helios-lifecycle/check.py`), and Kani proofs were skipped
  because no scheduling, lifecycle ownership, completion validation, or cache
  code changed.

Design-Signed-Off-By: Antigravity (Gemini); design-review=2e5b
@flare-autobot

Copy link
Copy Markdown
Collaborator Author

A case file has been opened for 637.
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.

@flare-autobot flare-autobot added area:api Serving API, protocol encoding, tool parsing, and client-visible behavior. bug Something isn't working triage:review Proposed change needs code review; this does not imply merge readiness. labels Nov 30, 2026
@flare-autobot

Copy link
Copy Markdown
Collaborator Author

Autobot Review

Full Review · Value Proposition · Case File

Recommendation: Changes Requested

The core helios/src/server/output.rs change is clean and low-risk — SHA-256 over (scope_id, index) yields fixed 37-char call_<32 hex> IDs with no hot-path or concurrency impact, and the apply/close reorder fixes a real partial-mutation bug — but CI is red on head d150811 with x86_64 Linux and windows-2022 unverified, and unverified provider length limits / internal hash inputs are being published as API contract while yatesdr's #447 question stays open.

  • Blockers: 1 · Should fix: 1 · Subtract/Simplify: 3 · Nits: 1
Walkthrough
  • helios/src/server/output.rs:15-49: Hoists use sha2::{Digest, Sha256}; to module scope (server → images → frontend → dep:sha2, helios/Cargo.toml:22-25, 53), adds MAX_SYNTHESIZED_TOOL_CALL_ID_LEN = 40 / SYNTHESIZED_TOOL_CALL_ID_LEN = 37, and adds synthesize_tool_call_id(scope_id, index) hashing b"flare-tool-call-id-v1\0", scope_id.len() (u64 LE), scope_id, and index (u64 LE) into call_ + first 16 digest bytes as 32 lowercase hex chars.
  • helios/src/server/output.rs:101, 1768: Replaces format!("call_{}_{}", self.id, index) and format!("call_{request_id}_{index}") with synthesize_tool_call_id, leaving explicit Event::ToolBegin { id: Some(...) } passthrough and nonempty/unique validation intact.
  • helios/src/server/output.rs:1714-1723, 1764-1789: Reorders ResponseOutput::close to reject Block::Tool { ended: false, .. } before clearing self.open = None, and apply to validate IDs before self.close(&mut changes)?.
  • docs/api.md:443-451: Documents the 37-char call_<32 lowercase hex> format, its hash inputs, a 40-char Chat Completions maximum, and the [a-zA-Z0-9_-]+ charset.
  • helios/src/server/output.rs:1296-1671, helios/src/server/protocol/tests.rs:2666-3118: Adds isolated tests over counter magnitudes through u64::MAX, multi-choice, parallel calls, Responses (function_call, custom_tool_call, strict: true), Messages (tool_use), stream/buffer parity, multi-turn round-tripping, and no-partial-mutation rejection.
Merge Risk: Low · up to d150811
  • Narrow blast radius: Production edits limited to synthesize_tool_call_id, two Event::ToolBegin call sites, and 4 lines in ResponseOutput::apply/close, gated behind #[cfg(feature = "server")] (helios/src/lib.rs:29-30); no Cargo.toml, scheduler, cache, protobuf, or CUDA-graph changes.
  • No hot-path or concurrency regression: One call per synthesized tool call off the token loop, no locks or shared state, one pre-sized 37-byte String; streaming and buffered paths emit identical IDs.
  • Residual risk is verification and contract surface: Red CI on d150811 leaves x86_64 Linux and windows-2022 unverified, and docs/api.md:443-451 promotes provider length claims and internal derivation details into the public API contract.
Pre-merge checks: ✅ 1 passed · ⚠️ 3 warnings
  • ✅ Security / malicious screen: Pure deterministic SHA-256 derivation over local request/call scope strings; no new dependencies, network/file access, or unsafe code.
  • ⚠️ Charter & value fit: Right layer (shared, model-agnostic Helios protocol code), but docs/api.md:443-451 and helios/src/server/output.rs:17-19 publish unverified third-party provider length limits as fact without answering yatesdr's #447 contract question.
  • ⚠️ Related / duplicate / conflict check: No duplicate fix for #447; preserves #176 uniqueness intent (uncited); appends to the same tail of helios/src/server/protocol/tests.rs as open PR #638 (trivial rebase conflict).
  • ⚠️ Tests & verification evidence: Local Linux aarch64 CPU release tests reported passing (helios, flare, flare-cli) and new tests are clean/isolated, but CI (.github/workflows/native-serving.yml) is failing on head d150811 with no explanation.

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.

@yatesdr
yatesdr merged commit 4ed5d87 into NVIDIA:main Nov 30, 2026
2 of 3 checks passed
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 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.

Synthesized tool-call ids pass 40 characters once the request counter reaches 100000

2 participants