Skip to content

[Fix] kimi_k3: Use uuid tool_call_id instead of history-count id - #45972

Merged
ispobock merged 5 commits into
sgl-project:mainfrom
yan-lgtm:remove-kimi-k3-tool-call-id
Nov 2, 2026
Merged

ispobock merged 5 commits into
sgl-project:mainfrom
yan-lgtm:remove-kimi-k3-tool-call-id

Conversation

@yan-lgtm

@yan-lgtm yan-lgtm commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Remove the kimi_k3 special case in OpenAIServingChat._process_tool_call_id so Kimi-K3 gets the default call_<uuid> tool call id.

if self.tool_call_parser == "kimi_k3":
    return f"{call_item.name}:{history_tool_calls_cnt + call_item.tool_index}"

Why

  • Kimi-K3's encoder treats tool call ids as opaque (the index comes from position), so it doesn't need the name:idx format. Only Kimi-K2's chat template requires functions.{name}:{idx}, and that path is unchanged.
  • An id built from the history count repeats whenever the client sends a shorter history. Clients that dedupe tool_use ids (e.g. Claude Code) then drop the call.

Test plan

  • Added test_kimi_k3_tool_call_id_unique_when_history_count_repeats: two _process_tool_call_id calls with the same history count return different call_ ids.
  • Existing test_kimi_k2_*_tool_call_id_with_history tests still pin K2's positional functions.{name}:{idx} ids.

🤖 Generated with Claude Code


CI States

Latest PR Test (Base): ❌ Run #40581259797
Latest PR Test (Extra): ❌ Run #40581259862
Latest PR Test (AMD ROCm 10): ❌ Run #40581259763

@yan-lgtm yan-lgtm changed the title [Kimi K3] Remove kimi_k3 special case in tool_call_id generation [Kimi K3] Use uuid tool_call_id instead of history-count id Oct 23, 2026
@github-actions

This comment has been minimized.

@JustinTong0323 JustinTong0323 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix is right: K3's encoder treats tool_call ids as opaque (index comes from position), so the uuid path is safe, and the history-count id genuinely repeats when a client sends a shorter history. Verified test_serving_chat.py green on this head (160 passed).

One request before merge: add a regression test pinning that two _process_tool_call_id calls with the same (call_item, history_tool_calls_cnt) return different ids for kimi_k3. Nothing currently guards the uniqueness contract, so a future diff re-adding a deterministic K3 id would silently reintroduce the duplicate-id bug. #33343 (same fix, stale) has usable test shapes — a frozen-history non-streaming case and a kimi_k2-stays-positional guard; close that PR as superseded when this lands.

Process: retitle to [Fix] kimi_k3: ... for the title check.

@JustinTong0323 JustinTong0323 added the run-ci CI: run the baseline test suite on this PR label Oct 23, 2026
@JustinTong0323

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@JustinTong0323 JustinTong0323 added the run-ci-extra CI: also run the extra suite (requires run-ci) label Oct 23, 2026
@JustinTong0323

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@JustinTong0323 JustinTong0323 changed the title [Kimi K3] Use uuid tool_call_id instead of history-count id [Fix] kimi_k3: Use uuid tool_call_id instead of history-count id Oct 23, 2026
JustinTong0323 and others added 3 commits October 23, 2026 05:20
Pin that repeated (call_item, history_cnt) inputs mint distinct ids, so a
future deterministic-id change cannot silently reintroduce the duplicate-id
bug. Trim the comment above the uuid branch to the load-bearing why.
@yan-lgtm

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@ispobock
ispobock merged commit b45a365 into sgl-project:main Nov 2, 2026
162 of 207 checks passed
ihciah added a commit to ihciah/sglang that referenced this pull request Nov 30, 2026
Port sgl-project#48775 to sglang-processor. SGLang now streams a Kimi-K3 call's name
and `{` once its header is complete, string values as they arrive and
typed values once they close; the port still sent each call whole once
`<|close|>call<|sep|>` arrived, so 28 of the 46 tool-parity cases had
drifted. `kimi_k3.rs` streams through a port of `_stream_calls`,
including skipping malformed XTML, and headers a call or tools close
cuts short, as the one-shot parse does.

A call the stream leaves open is incomplete, and a stop then does not
finish as `tool_calls`: `ToolDetector::has_incomplete_call` carries that
into `openai/chat.rs` and `parser/tools.rs`, as `serving_chat`'s
`_incomplete_tool_call_indices` does.

Regenerate `tool_parity/kimik3.json` and add malformed, cut-header and
split-value inputs. In `openai_parity/kimi-k3.json`, update the two streamed tool
cases and add `tools_stream_unclosed`, generated with Kimi-K3 on the
OpenAI wire and its pre-sgl-project#45972 ids, which this path still writes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-ci CI: run the baseline test suite on this PR run-ci-extra CI: also run the extra suite (requires run-ci)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants