Repository navigation
Bound synthesized tool-call IDs to 37 characters across HTTP protocols - #637
Conversation
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
|
A case file has been opened for 637. Future reviews will auto-run 90 minutes after code updates are pushed.
|
Autobot ReviewFull Review · Value Proposition · Case File Recommendation: Changes RequestedThe core
Walkthrough
Merge Risk: Low · up to
|
Fixes #447
Why
When a model output parser emits
Event::ToolBeginwithid: None—which all nine native tool-call parsers inhelios/src/output/do—Helios synthesizes a tool-call identifier for HTTP responses onPOST /v1/chat/completions,POST /v1/responses, andPOST /v1/messages. Each generation request receives a request identifier formatted inhelios/src/server/http.rsas{prefix}-{run:016x}-{seq}, combining a protocol prefix, a random 64-bit per-server-startrunvalue fromHttpState(helios/src/server.rs), and a monotonicAtomicU64request counter.On Chat Completions,
Encoder::new(helios/src/server/protocol/encode.rs) appends_{choice}per choice, andAccumulator::apply(helios/src/server/output.rs) previously concatenatedcall_{self.id}_{index}. For choice0and call index0, the fixed characters total 35 (call_chatcmpl-<16 hex>-_0_0), sotool_calls[].idreaches 41 characters onceseqhits100000(or atseq = 10000when a response contains 10 or more tool calls). OpenAI and Azure OpenAI Chat Completions rejecttool_calls[].idvalues longer than 40 characters with HTTP 400string_above_max_length, causing multi-provider conversation replay from long-running Flare servers to fail validation.ResponseOutput::apply(helios/src/server/output.rs) similarly concatenatedcall_{request_id}_{index}without a length bound for Responses and Messages, and bothResponseOutput::applyandResponseOutput::closemutatedself.openbefore 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-startrunentropy across calls, choices, requests, restarts, and hosts.What Changed
helios/src/server/output.rs):Accumulator::applyformatted missing IDs asformat!("call_{}_{}", self.id, index)andResponseOutput::applyformatted them asformat!("call_{request_id}_{index}").use sha2::{Digest, Sha256};was imported only inside the#[cfg(test)]module.sha2::{Digest, Sha256}at module scope (gated behind#[cfg(feature = "server")]inhelios/src/lib.rs, whereserverenablesimages->frontend->dep:sha2inhelios/Cargo.toml) and removed the duplicate test-module import. AddedMAX_SYNTHESIZED_TOOL_CALL_ID_LEN = 40,SYNTHESIZED_TOOL_CALL_ID_LEN = 37, a compile-timeassert!(SYNTHESIZED_TOOL_CALL_ID_LEN <= MAX_SYNTHESIZED_TOOL_CALL_ID_LEN), andsynthesize_tool_call_id(scope_id: &str, index: usize) -> String. The helper hashesb"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 ascall_followed by 32 lowercase hexadecimal characters. BothAccumulator::applyandResponseOutput::applycallsynthesize_tool_call_idwhenEvent::ToolBeginhasid: None; explicitEvent::ToolBegin { id: Some(...) }values still pass through existing nonempty and per-response uniqueness validation unchanged.helios/src/server/output.rs):ResponseOutput::applycalledself.close(&mut changes)?before validating that the tool-call ID was nonempty and unique, andResponseOutput::closeclearedself.openviaself.open.take()before rejecting an unclosedBlock::Tool { ended: false, .. }.ResponseOutput::applysynthesizes and validates nonempty, unique tool-call IDs before callingself.close(&mut changes)?, andResponseOutput::closechecks for an unclosedBlock::Toolbefore settingself.open = None.docs/api.md): Documented the deterministic 37-charactercall_<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.helios/src/server/output.rs,helios/src/server/protocol/tests.rs): Added unit and protocol tests coveringseqvalues0,99_999,100_000, andu64::MAX, multi-choice Chat Completions, 12 to 128 parallel calls, Responses (function_call,custom_tool_call, andstrict: truefunction tools), Messages (tool_use), streaming-versus-buffered parity, simulated restarts with distinct 64-bitrunvalues, suffix-concatenation disambiguation, explicit ID passthrough, multi-turndecodeandtemplate_messages(order_tool_result_batch) round-tripping with reversed tool results, and rejection without partial state mutation.x-request-id, response top-levelid, and failure logs), Responsesitem_idvalues (<= 54characters up toseq = u64::MAX, within the 64-character Responsesitem.idlimit), explicit model-supplied tool-call IDs, incoming historical tool-call ID decoding inhelios/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
Accumulator(Chat Completions) andResponseOutput(Responses and Messages, including custom tools andstrict: truefunction 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 from0throughu64::MAX(including99_999and100_000), multiple choices, and up to 128 parallel calls, with identical IDs across streaming and buffered output and clean round-trip tool-result matching throughdecodeandtemplate_messages.Event::ToolBeginIDs andResponseOutput::finish/applycalls on an unclosed tool block return errors without mutatingself.open,self.blocks, orself.calls.tool_calls[].idvalues 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) withFLARE_TEST_TEMPLATE_DIRprepared bytests/frontend/prepare_templates.pyforgemma4,glm53,mimo_v2,minimax_m3,nemotron_h,qwen38, andstep5: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_distinctserver::output::tests::response_output_rejects_invalid_tool_begin_and_unclosed_close_without_partial_mutationserver::protocol::tests::synthesized_tool_call_ids_stay_bounded_across_protocols_modes_and_restartsserver::protocol::tests::synthesized_high_counter_tool_call_ids_round_trip_through_decode_and_template_messagesZero compiler warnings in modified files (two pre-existing
rustc 1.99Atomic::fetch_updatedeprecation 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 theserverfeature 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:
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 byflare runon SM103/SM120/SM121 hardware.-- --ignored: 84 inhelios, 4 inflare, 3 inflare-cli) were not executed.x86_64and Windowsx86_64-pc-windows-msvcbuilds were not executed locally.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