[Bug]: gpt-oss streaming chat ends tool-call turns with finish_reason "stop" instead of "tool_calls"

Open
#22,962 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@BachNg311 is already working on this.

Since Nov 26, 2026.

  • #22963 by @BachNg311 — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python

Research direction

Start in tensorrt_llm/serve/harmony_adapter.py, reading handle_streaming_response and how HarmonyStreamState.tool_calls tracks filtered calls; compare with _determine_finish_reason and chat_stream_post_processor. Reproduce with the CPU-only snippet in the issue. Done when the final streamed chunk reports tool_calls for a tool-call turn, matching non-streaming behavior.

Written by the indexing model from the issue text.

Description

System Info

main at 6c18d93134, trtllm-serve with a gpt-oss model (Harmony chat path). The defect is in tensorrt_llm/serve/harmony_adapter.py and does not depend on the GPU.

Information
  • The official example scripts
Reproduction

A streamed chat request in which the model calls a tool:

POST /v1/chat/completions
{"model": "<gpt-oss model>", "stream": true,
 "messages": [{"role": "user", "content": "What is the weather in SF?"}],
 "tools": [{"type": "function", "function": {"name": "get_weather",
   "parameters": {"type": "object", "properties": {"city": {"type": "string"}}}}}]}

CPU-only reproduction of the streaming path with the real Harmony encoding:

from unittest.mock import Mock
from tensorrt_llm.serve.harmony_adapter import get_harmony_adapter, handle_streaming_response

tokens = get_harmony_adapter().encoding.encode(
    '<|channel|>commentary to=functions.get_weather <|constrain|>json'
    '<|message|>{"city":"SF"}<|call|>', allowed_special="all")

def response(token_ids_diff, done):
    output = Mock(token_ids_diff=token_ids_diff, token_ids=tokens, finish_reason="stop",
                  stop_reason=None, disaggregated_params=None)
    return Mock(outputs=[output], _done=done, cached_tokens=0)

chunks = handle_streaming_response(tools=[], tool_choice=None, result=response(tokens[:-1], False),
                                   model="m", request_id="r", done=False, num_prompt_tokens=5,
                                   first_iteration=True)
chunks += handle_streaming_response(tools=[], tool_choice=None, result=response(tokens[-1:], True),
                                    model="m", request_id="r", done=True, num_prompt_tokens=5,
                                    first_iteration=False)

The chunks stream the get_weather tool call, and the last choice chunk has "finish_reason": "stop".

Expected behavior

The stream ends with "finish_reason": "tool_calls", as the same request without streaming does (handle_non_streaming_response uses _determine_finish_reason), and as the chat stream of every other model does (chat_stream_post_processor turns "stop" into "tool_calls" when the turn had a tool call).

actual behavior

handle_streaming_response builds the final chunk with finish_reason=output.finish_reason. A gpt-oss tool call ends at the <|call|> stop token, so that is always "stop". The chunk that create_openai_streaming_response emits when it cuts a stream short (should_stop) is also hard-coded to "stop".

OpenAI-compatible agent clients decide whether to run the tool loop from finish_reason == "tool_calls", so with streaming they treat the tool call turn as a finished answer.

additional notes

The streaming state already tracks the tool calls a request has streamed (HarmonyStreamState.tool_calls, which holds only the calls that passed tool filtering), so the finish reason can be derived from it. Draft PR #21735 moves gpt-oss chat onto the shared chat handler but keeps chat_harmony_streaming_post_processor and this function, so the behavior is the same there. I have a fix and will open a PR.

Dominant language
Python
Stars
15.2k
Forks
3k
Avg merge
2d 21h
Merged PRs (30d)
477

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from NVIDIA/TensorRT-LLM

All issues in NVIDIA/TensorRT-LLM

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.