Skip to content

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

Done

Description

@shieldstar

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:

  1. Add helios/src/server/protocol/qc_tool_id.rs with the module source below.
  2. Register it at the end of helios/src/server/protocol/mod.rs with:
#[cfg(test)]
#[path = "qc_tool_id.rs"]
mod qc_tool_id;
  1. 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

  1. yatesdr commented on Nov 21, 2026

    @yatesdr
    Collaborator

    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.

  2. added
    area:api
    on Nov 21, 2026
  3. flare-autobot commented on Nov 30, 2026

    @flare-autobot
    Collaborator

    Confirmed on origin/main at c146d7be:

    • HttpState (helios/src/server.rs:165-167, 324-325) generates a random 64-bit per-server-start run value and increments a monotonic AtomicU64 request counter starting at 1.
    • helios/src/server/http.rs:317-327 formats request IDs as {prefix}-{run:016x}-{seq} (chatcmpl, resp, msg), and Encoder::new (helios/src/server/protocol/encode.rs:130-133) appends _{choice} for each Chat Completions Accumulator.
    • Every native tool-call parser in helios/src/output/ emits Event::ToolBegin with id: None, so all served models receive Helios-synthesized IDs.
    • In helios/src/server/output.rs, Accumulator::apply (line 66) formats missing IDs as call_{self.id}_{index} (35 + digits(seq) characters for choice 0 and call index 0 on Chat Completions: 40 characters at seq = 99999, 41 characters at seq = 100000, or 41 characters at seq = 10000 with call index 10), and ResponseOutput::apply (line 1357) formats missing IDs as call_{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 (commit d1508112):

    • helios/src/server/output.rs:
      • Adds a shared 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-endian u64 length of scope_id, scope_id bytes, little-endian u64 index) and encodes the first 16 digest bytes as call_ followed by 32 lowercase hexadecimal characters (fixed length 37, strictly <= 40 and within [a-zA-Z0-9_-]+).
      • Replaces raw string concatenation in both Accumulator::apply (Chat Completions) and ResponseOutput::apply (Responses function_call/custom_tool_call and Messages tool_use).
      • Preserves explicit model-supplied 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-level id, failure logs), Responses item_id, and full model core compatibility (no re-export required).
      • Reorders ResponseOutput::apply and ResponseOutput::close so rejected empty/duplicate tool-call IDs and unclosed tool blocks return an error without mutating self.open, self.blocks, or self.calls.
    • docs/api.md: Documents the deterministic 37-character synthesized tool-call ID format, hash inputs, and cross-protocol character-set and length guarantees.
    • Tests (helios/src/server/output.rs, helios/src/server/protocol/tests.rs): Adds unit and protocol tests covering seq values 0, 99_999, 100_000, and u64::MAX, multi-choice Chat Completions, up 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, multi-turn decode and template_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, with FLARE_TEST_TEMPLATE_DIR prepared via tests/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-server builds 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:

    • 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 run because it requires an exported model core served by flare run on SM103/SM120/SM121 hardware.
    • Ignored checkpoint, core, and GPU tests (-- --ignored: 84 in helios, 4 in flare, 3 in flare-cli), Linux x86_64, and Windows x86_64-pc-windows-msvc builds were not run locally.

    A pull request containing this fix is open at #637.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:api

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions