Skip to content

Studio: stop blaming Max Tokens when a connected model fills its context window - #12567

Merged
danielhanchen merged 3 commits into
unslothai:mainfrom
oobabooga:worktree-external-context-window-stop
Oct 3, 2026
Merged

danielhanchen merged 3 commits into
unslothai:mainfrom
oobabooga:worktree-external-context-window-stop

Conversation

@oobabooga

@oobabooga oobabooga commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

When a conversation with a connected model fills the model's context window, Studio tells the user to increase Max Tokens, which cannot help. If the reply already had answer text, Studio also auto-continues, and the server rejects the continuation because the window is still full. Reported on Reddit.

Fix

Studio cannot see a connected model's context window, so it now relies on what the server reports:

  • llama.cpp-based servers (llama.cpp, NInfer, Jan) report how many tokens they generated. If that is below Max Tokens, the window filled.
  • Anthropic reports a full window directly.

In those cases Studio suggests starting a new chat or shortening this one, and does not auto-continue. The explanation is kept after a reload.

Other providers' token counts are not used, because some leave out reasoning tokens or stop at their own lower output cap. When the cause is unclear, a thinking-only stop names both limits and everything else behaves as before. Local models and Google-hosted Gemini are unchanged.

Validation

Live A/B against main with Qwen3-1.7B on llama-server (4096-token window), added as a Custom connection:

Case main This PR
Thinking fills the window "Increase Max Tokens" "Start a new chat, or shorten this one", kept after reload
Answer fills the window Auto-continues, server rejects it One request, context-window label
Stop at Max Tokens Max Tokens message Same

Before (merge base) and after (this PR):

Thinking fills the window:

0_thinking_fills_window

Answer fills the window:

1_answer_fills_window

The thinking case after a reload:

2_thinking_after_reload

A server that reports no token count:

3_no_count

Mock servers checked the message that names both limits. The 137 affected tests, typecheck and build pass. The full suite has the same failures as main, apart from timing-dependent tests that pass when run alone.

Limitations

  • A llama.cpp-style server that stops early for another reason, such as builds before fix(studio): align settings sidebar rows with search field #16391 started with -n, is still reported as a full window.
  • NInfer, Anthropic and Gemini were checked against their source and documentation only. Hosted providers, Windows, macOS and the desktop app were not tested.

Maintainer verification

Before (merge base 11cc2ab) and after (this PR), each from its own install.sh --local build, driving a real llama-server (Qwen3-1.7B Q4_K_M, -c 1024 -np 1) added as a Custom connection, Max Tokens 8192, reasoning on. Facts were read out of the page, not only from the screenshots.

Case Before After
Thinking fills the window "Increase Max Tokens or disable thinking" "Start a new chat, or shorten this one"
Same thread after a reload no explanation shown explanation kept
Answer fills the window 2 requests, the continuation fails with exceed_context_size_error 1 request, "Response filled the model's context window"
Connection capped at 64 output tokens Max Tokens advice Max Tokens advice (unchanged)

Thinking fills the window:

thinking fills the window

The same thread after a reload:

thinking after reload

Answer fills the window:

answer fills the window

A real Max Tokens stop still names Max Tokens:

max tokens cap

@oobabooga

Copy link
Copy Markdown
Member Author

Reached Codex review convergence at oobabooga#330.

@danielhanchen danielhanchen self-assigned this Oct 3, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 3, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 3, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 3, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 3, 2026
@danielhanchen

Copy link
Copy Markdown
Member

Review record for #12567, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#337.

Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found.

Round 1: reviewed mirror 2f2b2280a6 (this PR's 4bd433944)

chatgpt-codex-connector[bot] (on the mirror)

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 2f2b2280a6

No triage reaction was recorded on the mirror

Verdict

The round converged at mirror 2f2b2280a6 (this PR's 4bd433944).

This is the review as it stood at that commit. Anything pushed to this PR afterwards was not part of it.

@danielhanchen
danielhanchen merged commit 6d3e91d into unslothai:main Oct 3, 2026
JoshuaL3000 pushed a commit to JoshuaL3000/unsloth that referenced this pull request Oct 4, 2026
…ext window (unslothai#12567)

* Studio: stop blaming Max Tokens when a connected model fills its context window

* Shorten the new length-stop messages to fit the two-line error box

* Format the length-stop message test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants