mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #6129] World generation spends a paid call on a reply it has no room to write, just below the size where it refuses for free #3406
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#3406
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?
Originally created by @kolacheee on GitHub (Sep 13, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6129
Originally assigned to: @SpicyMarinara on GitHub.
When you select a lot of lorebook content for world generation, there is a stretch just under the "too big" line where the request is sent to the model anyway, with almost no room left for the answer. You get billed for a call that comes back cut off - and if you add one more entry, the same request is refused instantly for free, which is what should have happened in the first place.
How to reproduce (try it yourself)
4096and save. (Any window size reproduces this; 4096 just keeps the numbers small.)What you'll see: one real completion is billed (visible on your provider dashboard) and it goes out with a reply budget of 191 tokens. A world brief cannot be written in 191 tokens, so it comes back cut off: either the error "The model's JSON was cut off before it finished. Increase the connection's max output tokens and try again.", or - because Pixelforge answers a cut-off reply by rolling once more - a second billed call and then a sealed but incomplete world carrying a repair note.
What should happen: step 4 should refuse for free too, with the same message and the numbers behind it, instead of paying for an answer that cannot fit. At Context Size 4096 the wasteful stretch is roughly 7,450 to 9,150 characters of selected lore; at 16384 it is roughly 56,650 to 58,300 - the same ~1,700-character-wide band, just moved.
Where it is
At staging
52799569c:packages/server/src/services/llm/base-provider.ts:308-MIN_OUTPUT_BUDGET_TOKENS = 128.packages/server/src/services/llm/base-provider.ts:545-563and:598-606- when a prompt has no droppable history, the fit makes it fit by handing the output budget back, down to that 128 floor.packages/server/src/services/llm/base-provider.ts:688-trimmed: estimatedTokensAfter < estimatedTokensBefore, i.e.trimmedreports lost input only; a collapsed reply budget leaves itfalse.packages/server/src/routes/game.routes.ts:11042-11061- the experience-generation attempt loop gates onfit.trimmedalone, then doesoptions.maxTokens = fit.maxTokens ?? options.maxTokenswith no floor.packages/server/src/routes/game.routes.ts:10986-10991- the debug line logs the pre-fit budget (the route's 2,048), so the value actually sent is in no log.What's happening
The "refuse before spending the call" check only asks whether the input fits. For this route's two-message, history-free prompt, the fitter makes the input fit by shrinking the reply budget instead of cutting the prompt - from the requested 2,048 all the way to the 128-token floor - and because nothing was cut from the input, the "it did not fit" flag stays false. The route sees a clean fit and dispatches a real, billed completion with 128-191 tokens of room for a document that needs thousands. Two smaller things ride along: the truncation message tells you to raise the connection's max output tokens, which cannot help here because the context window is what bound; and the reduced budget never appears in any log.
Suggested fix
Give this route a declared minimum reply size and check it after the fit: if the fitted budget falls below what a world brief plausibly needs, refuse for free with the 422
context_limitresponse the route already sends, including the numbers so the player is told "your selection leaves only N tokens for the answer; this needs at least M". Keep it scoped to this route rather than changing the shared fitter, whose budget-handback behaviour many other callers rely on. Two guards worth building in: a package or connection that deliberately asked for a small output budget must not be refused by this check (the route documents that a caller asking for less gets less), and the floor should be a route-owned constant in the spirit ofGAME_SETUP_MIN_OUTPUT_TOKENS, not an assumption about caller-supplied schemas. While in there, log the budget actually sent after the fit assignment, and reword the truncation message so it does not advise raising a cap that is not what bound.Context
The gate this gap sits in was added by PR #5977 (closing #5952 and #5953), merged to staging on 2026-09-08 - after the v2.4.4 release - so it is unreleased on staging. #5952's stated goal was to check before spending the call rather than burning a paid generation to discover the selection does not fit; this band is the corner where that still happens. Worth flagging: the regression shipped with that PR,
scripts/regressions/experience-lore-entries.regression.ts:665-684, asserts this exact one-paid-call-then-context_limitchain as the expected outcome and passes at HEAD, so this may have been a deliberate scoping decision - if it was, the only parts worth changing are the misleading truncation wording and the missing log line.Found by an AI-assisted sweep of merged PR #5977 against issue #5952, then re-verified against staging
52799569con 2026-09-13. Please verify before fixing.@SpicyMarinara commented on GitHub (Sep 13, 2026):
@SpicyMarinara is taking this report through the issue sweep in draft PR #6137, with Codex assisting. The affected current-code path has been checked; implementation and focused regression verification are in progress.
@SpicyMarinara commented on GitHub (Sep 13, 2026):
Fixed in #6137, now merged to staging (
e044997a2). World generation rejects insufficient answer space before calling a provider while respecting explicit small output limits.