Repository navigation
Description
Summary
When the model supplies no id for a tool call, the server synthesizes one from the request id and
the choice/call indexes. Nothing caps its length: the request id already carries the server's run
value and a monotonically increasing request counter, so the synthesized id grows with that counter
and reaches 41 characters at request 100000. The live OpenAI API rejects a tool-call id longer than
40 with HTTP 400 string_above_max_length, e.g. "Invalid 'messages[2].tool_calls[0].id': string
too long. Expected a string with maximum length 40, but got a string with length 41 instead."
(BerriAI/litellm#11392), so from that counter value a conversation
replayed to OpenAI fails validation.
Environment
- Upstream commit:
25b49519cd3738b9d8509d7c59bd0e78c03c1a72 - Build: cargo with
--locked --offline, Linux arm64 (aarch64), rust 1.94.1
(cargo test --locked --offline --manifest-path helios/Cargo.toml --features server --lib) - No GPU needed: the test drives the accumulator that builds the tool-call message
Steps to reproduce
From a clean checkout of the commit above:
- Add
helios/src/server/protocol/qc_tool_id.rswith the module source below. - Register it at the end of
helios/src/server/protocol/mod.rswith:
#[cfg(test)]
#[path = "qc_tool_id.rs"]
mod qc_tool_id;- Run the test by full path:
cargo test --locked --offline --manifest-path helios/Cargo.toml --features server --lib \
-- --exact server::protocol::qc_tool_id::synthesized_id_crosses_40_characters_at_seq_100000 --nocapture
| step | rc |
|---|---|
cargo test … --lib -- --list (the name present) |
0 |
synthesized_id_crosses_40_characters_at_seq_100000 |
0 (1 passed) |
use crate::output::Event;
use crate::server::output::Accumulator;
/// The id the runtime synthesizes for one tool call at `seq`, built through the real Accumulator.
fn synthesized(seq: u64) -> String {
let request_id = format!("chatcmpl-{:016x}-{}", 1u64, seq);
let mut accumulator = Accumulator::new(format!("{request_id}_{}", 0));
accumulator
.apply(vec![Event::ToolBegin { index: 0, name: "lookup".into(), id: None }])
.expect("tool begin");
accumulator.message()["tool_calls"][0]["id"]
.as_str()
.expect("synthesized id is a string")
.to_owned()
}
#[test]
fn synthesized_id_crosses_40_characters_at_seq_100000() {
let at_99999 = synthesized(99_999);
let at_100000 = synthesized(100_000);
eprintln!("TOOLID seq=99999 len={} id={at_99999}", at_99999.len());
eprintln!("TOOLID seq=100000 len={} id={at_100000}", at_100000.len());
assert_eq!(at_99999.len(), 40, "claim: exactly 40 characters at seq 99999");
assert_eq!(at_100000.len(), 41, "claim: 41 characters from seq 100000");
assert!(at_100000.len() > 40, "OpenAI rejects ids longer than 40");
}The arithmetic being exercised: chatcmpl (9 characters) + - + 16 hex digits of the run value
-+ the counter's digits +_0(the choice suffix) +call_(5) +_0(the call index) =
35 + digits(counter).
Actual
running 1 test
test server::protocol::qc_tool_id::synthesized_id_crosses_40_characters_at_seq_100000 ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 1072 filtered out; finished in 0.00s
TOOLID seq=99999 len=40 id=call_chatcmpl-0000000000000001-99999_0_0
TOOLID seq=100000 len=41 id=call_chatcmpl-0000000000000001-100000_0_0
Expected
The synthesized id should stay within the 40-character bound that OpenAI's tool-call ids are
limited to, for every request counter value. If the counter is to remain part of the id, the id
should be shortened or hashed so its length does not grow with it.
Source pointers
helios/src/server/http.rs:316—Protocol::Chat => "chatcmpl"(the prefix)helios/src/server/http.rs:321-325— the request id
format!("{prefix}-{:016x}-{}", state.run, state.ids.fetch_add(1, Ordering::Relaxed))helios/src/server/protocol/encode.rs:127-129— each choice wraps the request id as
Accumulator::new(format!("{id}_{i}"))helios/src/server/output.rs:66— a tool call with no model-supplied id gets
format!("call_{}_{}", self.id, index)helios/src/server/output.rs:67-69— the only validation on the synthesized id is nonempty and
unique across the calls of one response; there is no length check
Suggested fix
Bound the synthesized id when it is built, for example by truncating or hashing the counter part so
the whole id stays at 40 characters or fewer, and assert the bound next to the nonempty/unique
checks at helios/src/server/output.rs:67-69. The bound is the observed API rejection of ids over
40 characters (BerriAI/litellm#11392). The Responses path builds ids the
same way at helios/src/server/output.rs:1357 and should share the bound.
Activity
yatesdr commentedon Nov 21, 2026
The arithmetic holds at main 21a40f0. A synthesized Chat id is
call_{request id}_{choice}_{index}(helios/src/server/output.rs:66,helios/src/server/protocol/encode.rs:129), so it reaches 41 characters at request counter 100000. Every parser leaves ids to Flare, so all models get synthesized ids. Flare documents no length limit, and the only limit cited is a third-party report of Azure OpenAI rejecting 41 characters, so the client contract this should meet is not established yet.flare-autobot commentedon Nov 30, 2026
Confirmed on
origin/mainatc146d7be:HttpState(helios/src/server.rs:165-167,324-325) generates a random 64-bit per-server-startrunvalue and increments a monotonicAtomicU64request counter starting at1.helios/src/server/http.rs:317-327formats request IDs as{prefix}-{run:016x}-{seq}(chatcmpl,resp,msg), andEncoder::new(helios/src/server/protocol/encode.rs:130-133) appends_{choice}for each Chat CompletionsAccumulator.helios/src/output/emitsEvent::ToolBeginwithid: None, so all served models receive Helios-synthesized IDs.helios/src/server/output.rs,Accumulator::apply(line 66) formats missing IDs ascall_{self.id}_{index}(35 + digits(seq)characters for choice0and call index0on Chat Completions: 40 characters atseq = 99999, 41 characters atseq = 100000, or 41 characters atseq = 10000with call index10), andResponseOutput::apply(line 1357) formats missing IDs ascall_{request_id}_{index}without a length bound.Summary of Prepared Fix
A fix is prepared on branch
fix/issue-447-bound-synthesized-tool-call-ids(commitd1508112):helios/src/server/output.rs:synthesize_tool_call_id(scope_id, index)helper that hashes a domain-separated, length-delimited SHA-256 input (b"flare-tool-call-id-v1\0", little-endianu64length ofscope_id,scope_idbytes, little-endianu64index) and encodes the first 16 digest bytes ascall_followed by 32 lowercase hexadecimal characters (fixed length 37, strictly<= 40and within[a-zA-Z0-9_-]+).Accumulator::apply(Chat Completions) andResponseOutput::apply(Responsesfunction_call/custom_tool_calland Messagestool_use).Event::ToolBegin { id: Some(...) }values, incoming historical tool-call ID decoding (helios/src/server/protocol/decode.rs), human-readable request IDs (x-request-id, top-levelid, failure logs), Responsesitem_id, and full model core compatibility (no re-export required).ResponseOutput::applyandResponseOutput::closeso rejected empty/duplicate tool-call IDs and unclosed tool blocks return an error without mutatingself.open,self.blocks, orself.calls.docs/api.md: Documents the deterministic 37-character synthesized tool-call ID format, hash inputs, and cross-protocol character-set and length guarantees.helios/src/server/output.rs,helios/src/server/protocol/tests.rs): Adds unit and protocol tests coveringseqvalues0,99_999,100_000, andu64::MAX, multi-choice Chat Completions, up 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, multi-turndecodeandtemplate_messages(order_tool_result_batch) round-tripping, and rejection without partial state mutation.Verification
Executed on Linux
aarch64(Ubuntu 24.04,rustc 1.99.1,ulimit -l unlimited, withFLARE_TEST_TEMPLATE_DIRprepared viatests/frontend/prepare_templates.py):cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --target-dir flare-cli/target: 1803 passed, 0 failed, 84 ignored (all four tool-call ID and partial-mutation tests passed).cargo check --locked --release --manifest-path helios/Cargo.toml --tests --features runtime-core --target-dir flare-cli/target: passed (confirms non-serverbuilds remain unaffected).cargo test --locked --release --manifest-path flare/Cargo.toml --target-dir flare-cli/target: 245 passed, 0 failed, 4 ignored.cargo test --locked --release --manifest-path flare-cli/Cargo.toml: 227 passed, 0 failed, 3 ignored.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 run because it requires an exported model core served byflare runon SM103/SM120/SM121 hardware.-- --ignored: 84 inhelios, 4 inflare, 3 inflare-cli), Linuxx86_64, and Windowsx86_64-pc-windows-msvcbuilds were not run locally.A pull request containing this fix is open at #637.