Skip to content

fix(server): a reply gets the context its prompt leaves instead of a 400 - #842

Merged
davide221 merged 1 commit into
mainfrom
fix/reply-fits-context
Oct 13, 2026
Merged

davide221 merged 1 commit into
mainfrom
fix/reply-fits-context

Conversation

@davide221

@davide221 davide221 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Clients send their usual output cap whatever the prompt: Claude Code asks for 32000 tokens on every turn. Once prompt + max_tokens passed the context, the server refused the request with a 400. With a 131072-token context and the model cards' 32768 default, a session stopped working at about 99K tokens of prompt, long before the context was full.

What changes

  • Direct requests: max_tokens is trimmed to the context the prompt leaves (fit_reply_to_context in admission.h), as llama.cpp does with n_predict. The server logs the trim.
  • A prompt that fills the context is still refused with a 400.
  • Routed requests keep the old rule, so the router can still send the request whole to a model with room for it.
  • Thinking budgets follow the trimmed cap.

Measured

Qwen 3.8 27B on an R9700, launched with the model card's 32768 default instead of a fixed 4096:

Request Before After
108,802-token prompt, max_tokens 32000 400 200, cap trimmed to 22,270
reasoning_effort: medium no thinking under a 4096 cap 218 reasoning tokens
Messages API, thinking.budget_tokens 2048 no thinking under a 4096 cap thinking block, then the answer

The last two rows depend on the launcher dropping its fixed 4096 cap. This change is what makes dropping it safe for long prompts.

Tests

test_admission: a new case covers the trim and the refusal of a prompt that fills the context. test_server_unit passes on a HIP build.

🤖 Generated with Claude Code

View guided diff

Clients send their usual output cap whatever the prompt: Claude Code asks
for 32000 tokens on every turn. Once prompt + max_tokens passed the context,
the request was refused with 400, so with a 131072-token context and the
model cards' 32768 default a session stopped working at about 99K tokens of
prompt, long before the context was full.

A direct request's max_tokens is now trimmed to the context its prompt
leaves, as llama.cpp does with n_predict; a prompt that fills the context is
still refused. A routed request keeps the old rule, so the router can still
send it whole to a model with room for it. Thinking budgets follow the
trimmed cap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@davide221 davide221 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Code review

No issues found. Checked for bugs and logic errors in the changed code.

Reviewed 7b8d0f55 · 0 candidate issues checked, kept at ≥70% confidence · add the code-review label to review again

@davide221
davide221 merged commit 07c1783 into main Oct 13, 2026
10 of 11 checks passed
davide221 added a commit to Graffioh/lucebox-hub that referenced this pull request Oct 13, 2026
Resolve the conflict with Luce-Org#842. validate_request_context keeps main's
routed flag and its reply trim, and sends this branch's PFlash
maximum-context error when compression would run. test_admission keeps
both sets of tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant