mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #24] [MERGED] serve: optional --fit-max-tokens clamps the output cap to remaining context instead of rejecting #2422
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#2422
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/24
Author: @pjgmobile
Created: 9/27/2026
Status: ✅ Merged
Merged: 9/27/2026
Merged by: @Niko1221
Base:
main← Head:pr-fit-max-tokens📝 Commits (1)
3ec41f5serve: optional --fit-max-tokens clamps the output cap to remaining context instead of rejecting📊 Changes
1 file changed (+11 additions, -4 deletions)
View changed files
📝
serve/server.py(+11 -4)📄 Description
PR draft — Niko1221/Strata
REBASED 2026-09-27 onto current main (
89ba2dc, engine 0.1.8). Branchpr-fit-max-tokenslives in the worktree
/home/pete/strata-pr; ready-to-send patch:/home/pete/pr-drafts/strata-fit-max-tokens.patch(git am strata-fit-max-tokens.patch).Your local working setup (main @
9ef55a4+ local clamp patch) is untouched.Rebase notes: all four previously-local upstream PRs (#7 zero-token, #8 conversation cache,
#9 cpu-pool sleep, #14 phantom-cores/dangling-else) are ALREADY in upstream main — the PR now
carries ONLY the clamp (11+/4- lines). Upstream's server.py evolved since the draft (CTX_SLACK
constant, 0/-1 = rest-of-context call semantics, progress lines): the resolution keeps all of
that and adds the flag. Conflicts were resolved in the worktree; mock-engine tests: strict
default = byte-identical 400, --fit-max-tokens = 200 with clamped generation.
Title:
serve: optional --fit-max-tokens clamps the output cap to remaining context instead of rejectingFiles:
serve/server.py(arg parsing +Service.prepare()+ both call sites)Body
Problem
Today the server rejects with 400 any request where
prompt_tokens + max_tokensexceedsmax_context("requests are never truncated"). That strictness mirrors llama.cpp and is theright default for predictable single-purpose clients — but it breaks agentic clients that
legitimately ask for the model's full output cap with a long prompt
(e.g. prompt 131,888 + max_tokens 130,298 = 262,186 on a 262,144 window: rejected over a
42-token overshoot).
Proposed change
Keep the current strict behaviour as the default, and add an opt-in flag:
In
Service.prepare():(plus: thread the new flag from
main()through config toService, and update the twocall sites to use the returned clamped value — full working diff available, running in
production since 2026-09-26.)
Verification
Prompt of 251,455 tokens +
max_tokens: 131072on a 262,144 window, flag on:HTTP 200,
completion_tokens: 10,681(= 262,144 − 251,455 − 8),finish_reason: length,total_tokens: 262,136. Flag off: the current 400, byte-identical. Small requests unaffected.Disclosure
This PR was authored end-to-end by GLM-5.3-Flash (Z.ai): root-cause investigation, patch
authoring, and verification. Submitted after human review by the opener.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.