Skip to content

Studio: honor stream=false on the GGUF agentic tool path (#6570) - #6618

Merged
Imagineer99 merged 7 commits into
unslothai:mainfrom
oobabooga:worktree-fix-tool-stream-6570
Jun 24, 2026
Merged

Imagineer99 merged 7 commits into
unslothai:mainfrom
oobabooga:worktree-fix-tool-stream-6570

Conversation

@oobabooga

Copy link
Copy Markdown
Member

Closes #6570

Problem

With server-side tools enabled, the GGUF /v1/chat/completions path returned an SSE stream even when the request set "stream": false. Non-streaming clients (and health checks like LiteLLM) got text/event-stream instead of a JSON object and choked.

It hit hardest via unsloth studio run --model ..., which forces the tool policy on process-wide (#5277). With tools always on, every plain request hit the tool loop, whose return was an unconditional _SameTaskStreamingResponse(...) with no if payload.stream guard (unlike the standard GGUF and safetensors tool paths). Loading the same model from the GUI left the policy unset, so it only reproduced on the CLI-preload path.

Fix

Gate the tool path's streaming return on payload.stream. When stream:false, drain the same agentic generator and build a single ChatCompletion, mirroring the safetensors tool path and the standard GGUF non-streaming branch. stream:true is unchanged.

Two adjacent items cleared here:

  • The drain closes the generator on early break/cancel, so the llama-server stream socket is released like the SSE path does.
  • _build_metadata_event now preserves prompt_tokens_details, so the tool path reports real cached_tokens instead of always 0 (fixes both the streaming and non-streaming tool paths).

The confirm_tool_calls-requires-stream 400 guard still fires first, so confirmation-gated requests can't reach the drain.

Verification

  • New test_gguf_tool_non_streaming.py covers stream:false+tools (JSON), stream:true (SSE), absent-usage, finish_reason=length, and cached_tokens round-trip. Updated two TestGgufVisionToolRouting tests that assumed the old always-stream behavior.
  • 270 pass across the tool, stream, and usage suites.
  • Live on two GGUF models (gemma-4-12b-it, Qwen3-1.7B): stream:false+tools returns application/json, stream:true still streams.

@oobabooga
oobabooga requested a review from danielhanchen as a code owner June 23, 2026 18:31
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@oobabooga

Copy link
Copy Markdown
Member Author

@codex review

@oobabooga

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.

@oobabooga

Copy link
Copy Markdown
Member Author

@codex review

@oobabooga

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.

@Imagineer99

Copy link
Copy Markdown
Member
image

CI passes on fork, looks valid,stream:false now returns JSON on the GGUF tool path, while stream:true still streams.

Only note: the drain keeps the final assistant turn, matching safetensors. Merging.

@Imagineer99
Imagineer99 merged commit ab6c9ec into unslothai:main Jun 24, 2026
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] OpenAI-compatible /v1/chat/completions ignores "stream": false and returns an SSE stream

2 participants