Repository navigation
Conversation
…d gpt-oss tool call turns A streamed gpt-oss (Harmony) chat turn that made a tool call ended with finish_reason "stop": the final chunk passed on the engine's finish reason, which is "stop" because a tool call ends at the <|call|> stop token, and the chunk sent when a stream is cut short was hard-coded to "stop". The same request without streaming, and the chat stream of other models, report "tool_calls". Turn "stop" into "tool_calls" in both streaming finish chunks when the stream state has streamed a tool call. Signed-off-by: BachNg311 <nguyentatbach605@gmail.com>
|
No actionable comments were generated in the recent review. WalkthroughStreaming Harmony responses now return ChangesHarmony streaming finish reasons
Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix · Severity of issue fixed: Medium Suggested reviewers: Merge Risk:
|
Dev Engineer Review
tensorrt_llm/serve/harmony_adapter.py(+19/-2): Adds_determine_stream_finish_reason. It changes"stop"to"tool_calls"only when the stream state holds a tool call that passed filtering. It applies to both streaming finish chunks.HarmonyStreamState.tool_callsholding only filtered calls. Suppressed calls must keep"stop". The tests cover this case."length"behavior and the non-streaming path are unchanged.QA Engineer Review
tests/unittest/llmapi/apps/test_harmony_parsing.py(+106): AddsTestStreamingToolCallFinishReason.test_final_chunk_finish_reason[tool_call]andtest_stream_stopped_on_repeated_channel_after_tool_callassert"tool_calls".[answer]and[suppressed_tool_call]assert"stop"."tool_calls"tests fail onmain. This is not independently verified.test_harmony_parsing.pyandtest_harmony_channel_validation.pyon CPU with real Harmony encoding. The full suite has not run.test-db/orqa/: not available from the supplied evidence.Per-File QA Perspective
tensorrt_llm/serve/harmony_adapter.py: Streamed responses that include a tool call now reportfinish_reason: "tool_calls". Verify the final chunk and the cut-short (should_stop) chunk. Verify that suppressed calls still report"stop".tests/unittest/llmapi/apps/test_harmony_parsing.py: Covers the streaming finish-reason cases listed above. Confirm it is listed in the appropriate CI list. Placement is not available.Description
Fixes #22962.
A streamed gpt-oss (Harmony) chat turn that makes a tool call ended with
finish_reason: "stop": the final chunk ofhandle_streaming_responsepassed on the engine's finish reason, which is "stop" because a tool call ends at the<|call|>stop token, and the chunkcreate_openai_streaming_responseemits when it cuts a stream short was hard-coded to "stop". The same request without streaming, and the chat stream of every other model, report "tool_calls", which is what OpenAI-compatible clients run the tool loop on.This PR adds
_determine_stream_finish_reason, the streaming counterpart of_determine_finish_reason: a "stop" becomes "tool_calls" when the stream state has streamed a tool call. Both streaming finish chunks use it.HarmonyStreamState.tool_callsonly holds calls that passed tool filtering, so a call suppressed bytool_choice="none"or by the tool list still ends with "stop".Like the chat stream of other models, only "stop" is changed. The non-streaming Harmony path also turns "length" into "tool_calls"; this PR leaves that as it is.
Draft PR #21735 keeps
chat_harmony_streaming_post_processorandhandle_streaming_responsefor gpt-oss, so the fix also applies after it.Test Coverage
tests/unittest/llmapi/apps/test_harmony_parsing.py(cpu_only, already inl0_cpu.yml),TestStreamingToolCallFinishReason. The tests encode Harmony text with the real encoding and stream it throughhandle_streaming_response:test_final_chunk_finish_reason[tool_call]: a tool call turn streams the call and ends with "tool_calls".test_final_chunk_finish_reason[answer]and[suppressed_tool_call]: an answer turn, and a tool call suppressed bytool_choice="none", still end with "stop".test_stream_stopped_on_repeated_channel_after_tool_call: a stream cut short by the channel validation after a streamed tool call ends with "tool_calls".The
tool_callandrepeated_channelcases fail onmain('stop' != 'tool_calls') and pass with this change. They are fast CPU checks in a file that already runs in the pre-merge CPU stage.Local validation was CPU-only:
test_harmony_parsing.pyandtest_harmony_channel_validation.pyran against the repository'sharmony_adapter.pywith the realopenai-harmonyencoding and copies of the protocol models it builds (no test was skipped); the full suite has not run yet.PR Checklist
Please review the following before submitting your PR:
PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.
PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.
Test cases are provided for new code paths (see test instructions)
If PR introduces API changes, an appropriate PR label is added - either
api-compatibleorapi-breaking. Forapi-breaking, includeBREAKINGin the PR title.Any new dependencies have been scanned for license and vulnerabilities
CODEOWNERS updated if ownership changes
Documentation updated as needed
Update tava architecture diagram if there is a significant design change in PR.
The reviewers assigned automatically/manually are appropriate for the PR.
Please check this after reviewing the above items as appropriate for this PR.
GitHub Bot Help
To see a list of available CI bot commands, please comment
/bot help.