[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

Closed
opened 2026-10-21 06:02:46 +07:00 by bsakaguchi · 2 comments
Owner

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)

  1. Settings -> Connections -> open the connection your game chat uses. Set Context Size to 4096 and save. (Any window size reproduces this; 4096 just keeps the numbers small.)
  2. Open a Game Mode chat running the Pixelforge Experience and go to the world setup screen.
  3. In the lorebook picker, tick entries until the selected entry content totals about 8,800 characters (roughly eight entries of ~1,100 characters). Do not try to do this by typing into the setting-description box - that field is capped at 8,000 characters by the route and clamped to 7,800 by the package, and even a maximal paste there never reaches this band.
  4. Press Generate.

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.

  1. Now tick one more ~1,100-character entry (about 10,000 characters of lore total) and press Generate again. It is refused instantly, nothing is billed, and you get the "exceeds this connection's context window" retry screen.

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-563 and :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. trimmed reports lost input only; a collapsed reply budget leaves it false.
  • packages/server/src/routes/game.routes.ts:11042-11061 - the experience-generation attempt loop gates on fit.trimmed alone, then does options.maxTokens = fit.maxTokens ?? options.maxTokens with 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_limit response 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 of GAME_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_limit chain 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 52799569c on 2026-09-13. Please verify before fixing.

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) 1. Settings -> Connections -> open the connection your game chat uses. Set **Context Size** to `4096` and save. (Any window size reproduces this; 4096 just keeps the numbers small.) 2. Open a Game Mode chat running the Pixelforge Experience and go to the world setup screen. 3. In the lorebook picker, tick entries until the selected entry content totals about **8,800 characters** (roughly eight entries of ~1,100 characters). Do not try to do this by typing into the setting-description box - that field is capped at 8,000 characters by the route and clamped to 7,800 by the package, and even a maximal paste there never reaches this band. 4. Press Generate. **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. 5. Now tick one more ~1,100-character entry (about 10,000 characters of lore total) and press Generate again. It is refused instantly, nothing is billed, and you get the "exceeds this connection's context window" retry screen. **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-563` and `: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. `trimmed` reports lost input only; a collapsed reply budget leaves it `false`. - `packages/server/src/routes/game.routes.ts:11042-11061` - the experience-generation attempt loop gates on `fit.trimmed` alone, then does `options.maxTokens = fit.maxTokens ?? options.maxTokens` with 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_limit` response 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 of `GAME_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_limit` chain 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 52799569c on 2026-09-13. Please verify before fixing.
bsakaguchi 2026-10-21 06:02:46 +07:00
Author
Owner

@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.

<!-- gh-comment-id:5651923896 --> @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.
Author
Owner

@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.

<!-- gh-comment-id:5652784684 --> @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.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#3406
No description provided.