[GH-ISSUE #6122] Picking thousands of lorebook entries makes world generation fail with a refusal that never mentions lore #3401

Closed
opened 2026-10-21 06:02:42 +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/6122

Originally assigned to: @SpicyMarinara on GitHub.

When a player ticks a very large number of lorebook entries for an Experience's world generation, the request is turned away by the server before anything is generated, and the refusal says only that the request body is too large. Nothing tells the player how many entries they picked, how many the server will take, or that lore is the cause at all - so in Pixelforge the failure surfaces as generic "refused" copy telling them to shorten their setting description, which is the wrong advice and cannot fix it. Unticking entries clears it immediately, but there is no way for the player to learn that.

How to reproduce (try it yourself)

The quick way, on the wire (30 seconds, no giant lorebook needed). With your own Engine running, run this against a chat id that does not exist - a real id would run a live, paid generation call for the first request:

python3 - <<'EOF'
import json,urllib.request,urllib.error
URL="http://127.0.0.1:7860/api/game/no-such-chat-id-xxxxx/experience-generation"
def post(n):
 body={"instructions":"Generate a world.","userContent":"",
 "lorebookEntryIds":["%021d"%i for i in range(n)]}
 raw=json.dumps(body).encode()
 req=urllib.request.Request(URL,data=raw,headers={"Content-Type":"application/json"},method="POST")
 try:
 r=urllib.request.urlopen(req); print(n,len(raw),r.status,r.read()[:120].decode())
 except urllib.error.HTTPError as e:
 print(n,len(raw),e.code,e.read()[:120].decode())
post(101)
post(3000)
EOF

What you'll see: 101 2603 404 {"error":"Chat not found"} and 3000 75078 413 {"error":"The request body is larger than this endpoint accepts."}. The 404 on 101 ids proves validation accepted the list (the id check runs after validation). The 3,000-id call never reaches the handler - it dies at the socket with a message that names no count and carries no machine-readable code.

What should happen: the over-long selection should come back as a counted refusal that names how many entries were sent and how many are accepted, in the same family as the context_limit 422 this route already returns when the selection is too big for the model's context.

The in-app way (the path a player actually walks):

  1. Sidebar -> Lorebooks -> Import a very large world-info book (around 2,500 enabled entries; content can be one word each, only the entry count matters), or import several books totalling that many.
  2. Start a new chat on an Experience that uses the setup wizard (Pixelforge) so the lore picker opens.
  3. Expand each book and click Select all. The readout says "Picked all N entries in ." - there is no cap and no warning, and the count accumulates across books.
  4. Type a short setting line, e.g. A damp river town under a broken aqueduct.
  5. Click the button that generates the world.

What you'll see: the world-generation step drops straight to the retry screen reading "The request was turned down rather than delayed... a shorter, plainer setting description is the likeliest thing to change it." Retry fails identically. The browser console shows 413 The request body is larger than this endpoint accepts.

What should happen: the refusal should say the selection is too large and that unticking entries is the fix.

The exact threshold depends on how much the player typed - measured against the real request body it sits at about 2,450 ticked entries (2,446 once a world name and a setting line are in the body). Tick one fewer and generation proceeds normally.

Where it is

At staging 52799569c:

  • packages/server/src/routes/game.routes.ts:10770 - lorebookEntryIds: z.array(z.string()).optional() (no .max), with { bodyLimit: 64 * 1024 } on the route at :10775.
  • packages/server/src/routes/game.routes.ts:10769 - the field's own comment says "The complete selection is checked against model context before generation", which is not what happens past the byte limit: the request never reaches the context fit at :11050.
  • packages/server/src/middleware/error-handler.ts:20-26 - the 413 body is deliberately number-free, because the app-wide limit and the per-route limits differ.
  • packages/server/src/services/lorebook/index.ts:1085-1087 and packages/server/src/services/storage/lorebooks.storage.ts:662 - the forced-entries path passes unlimited: true, so nothing downstream re-imposes a count. LIMITS.MAX_LOREBOOK_ENTRIES (packages/shared/src/constants/defaults.ts:100) is now unreachable on this path.

What's happening

The route's 64 KB body limit was sized when the route was created (#5135), for a body of instructions plus user content plus schema - before lorebookEntryIds existed. #5944 later added the id array under a count cap of 100, which kept the byte limit out of reach. #5977 removed that cap on purpose (per #5953) and did not revisit the byte limit, so the byte limit is now the only surviving ceiling on how many entries a player can pick. Nobody chose 2,450; it is what 64 KB divides into at roughly 24 bytes per entry id. Because the request dies at the transport layer, the handler's well-shaped counted refusals never run, and the caller gets a bare 413.

Suggested fix

This is not a request to re-impose a count cap - #5953 settled that there should not be one. Two parts:

  1. Raise this route's bodyLimit so a lore selection can never hit the byte wall before the checks that produce a good message. The body is a list of short ids plus a fixed prompt, so the ceiling can be generous.
  2. If a ceiling on the selection is still wanted, express it where the handler can explain it: an explicit count check returning the same shape as the existing context_limit refusal - a distinct code, the number the player sent, and the number accepted - so a client can say "you picked N entries; untick some" instead of inheriting a transport-level error with no count.

A useful place to surface such a limit in the picker would be the "Select all" readout, which currently reports a total with no upper bound.

Context

Introduced by merged PR #5977 (commit 848e8fa3d), which implemented the maintainer call in #5953 by removing the .max(LIMITS.MAX_LOREBOOK_ENTRIES) that PR #5944 had added, and deleted the regression scenario that pinned the old counted 400. #5953 anticipated this gap ("uncap and fix that failure message in the same change so an over-large selection says so plainly"); the context_limit half landed, this half did not. Unreleased on staging - 848e8fa3d is not in any tag, and the latest release is v2.4.4. The client half (Pixelforge has no branch for a 413 in its failure ladder, so it lands on "refused" copy that blames the setting description) is a separate Marinara-Agents issue and should be fixed there too, since a 413 can also arrive from an older Engine.

Found by an AI-assisted sweep of merged PR #5977 against issue #5953, then re-verified against staging 52799569c on 2026-09-13. Please verify before fixing.

Related issue from the same sweep: Pasta-Devs/Marinara-Agents#812 (the Pixelforge-side failure copy for the same 413).

Originally created by @kolacheee on GitHub (Sep 13, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6122 Originally assigned to: @SpicyMarinara on GitHub. When a player ticks a very large number of lorebook entries for an Experience's world generation, the request is turned away by the server before anything is generated, and the refusal says only that the request body is too large. Nothing tells the player how many entries they picked, how many the server will take, or that lore is the cause at all - so in Pixelforge the failure surfaces as generic "refused" copy telling them to shorten their setting description, which is the wrong advice and cannot fix it. Unticking entries clears it immediately, but there is no way for the player to learn that. ## How to reproduce (try it yourself) The quick way, on the wire (30 seconds, no giant lorebook needed). With your own Engine running, run this against a chat id that does **not** exist - a real id would run a live, paid generation call for the first request: ``` python3 - <<'EOF' import json,urllib.request,urllib.error URL="http://127.0.0.1:7860/api/game/no-such-chat-id-xxxxx/experience-generation" def post(n): body={"instructions":"Generate a world.","userContent":"", "lorebookEntryIds":["%021d"%i for i in range(n)]} raw=json.dumps(body).encode() req=urllib.request.Request(URL,data=raw,headers={"Content-Type":"application/json"},method="POST") try: r=urllib.request.urlopen(req); print(n,len(raw),r.status,r.read()[:120].decode()) except urllib.error.HTTPError as e: print(n,len(raw),e.code,e.read()[:120].decode()) post(101) post(3000) EOF ``` **What you'll see:** `101 2603 404 {"error":"Chat not found"}` and `3000 75078 413 {"error":"The request body is larger than this endpoint accepts."}`. The 404 on 101 ids proves validation accepted the list (the id check runs after validation). The 3,000-id call never reaches the handler - it dies at the socket with a message that names no count and carries no machine-readable code. **What should happen:** the over-long selection should come back as a counted refusal that names how many entries were sent and how many are accepted, in the same family as the `context_limit` 422 this route already returns when the selection is too big for the model's context. The in-app way (the path a player actually walks): 1. Sidebar -> Lorebooks -> Import a very large world-info book (around 2,500 enabled entries; content can be one word each, only the entry count matters), or import several books totalling that many. 2. Start a new chat on an Experience that uses the setup wizard (Pixelforge) so the lore picker opens. 3. Expand each book and click **Select all**. The readout says "Picked all N entries in <book>." - there is no cap and no warning, and the count accumulates across books. 4. Type a short setting line, e.g. `A damp river town under a broken aqueduct.` 5. Click the button that generates the world. **What you'll see:** the world-generation step drops straight to the retry screen reading "The request was turned down rather than delayed... a shorter, plainer setting description is the likeliest thing to change it." Retry fails identically. The browser console shows `413 The request body is larger than this endpoint accepts.` **What should happen:** the refusal should say the selection is too large and that unticking entries is the fix. The exact threshold depends on how much the player typed - measured against the real request body it sits at about 2,450 ticked entries (2,446 once a world name and a setting line are in the body). Tick one fewer and generation proceeds normally. ## Where it is At staging 52799569c: - `packages/server/src/routes/game.routes.ts:10770` - `lorebookEntryIds: z.array(z.string()).optional()` (no `.max`), with `{ bodyLimit: 64 * 1024 }` on the route at `:10775`. - `packages/server/src/routes/game.routes.ts:10769` - the field's own comment says "The complete selection is checked against model context before generation", which is not what happens past the byte limit: the request never reaches the context fit at `:11050`. - `packages/server/src/middleware/error-handler.ts:20-26` - the 413 body is deliberately number-free, because the app-wide limit and the per-route limits differ. - `packages/server/src/services/lorebook/index.ts:1085-1087` and `packages/server/src/services/storage/lorebooks.storage.ts:662` - the forced-entries path passes `unlimited: true`, so nothing downstream re-imposes a count. `LIMITS.MAX_LOREBOOK_ENTRIES` (`packages/shared/src/constants/defaults.ts:100`) is now unreachable on this path. ## What's happening The route's 64 KB body limit was sized when the route was created (#5135), for a body of instructions plus user content plus schema - before `lorebookEntryIds` existed. #5944 later added the id array under a count cap of 100, which kept the byte limit out of reach. #5977 removed that cap on purpose (per #5953) and did not revisit the byte limit, so the byte limit is now the only surviving ceiling on how many entries a player can pick. Nobody chose 2,450; it is what 64 KB divides into at roughly 24 bytes per entry id. Because the request dies at the transport layer, the handler's well-shaped counted refusals never run, and the caller gets a bare 413. ## Suggested fix This is not a request to re-impose a count cap - #5953 settled that there should not be one. Two parts: 1. Raise this route's `bodyLimit` so a lore selection can never hit the byte wall before the checks that produce a good message. The body is a list of short ids plus a fixed prompt, so the ceiling can be generous. 2. If a ceiling on the selection is still wanted, express it where the handler can explain it: an explicit count check returning the same shape as the existing `context_limit` refusal - a distinct `code`, the number the player sent, and the number accepted - so a client can say "you picked N entries; untick some" instead of inheriting a transport-level error with no count. A useful place to surface such a limit in the picker would be the "Select all" readout, which currently reports a total with no upper bound. ## Context Introduced by merged PR #5977 (commit 848e8fa3d), which implemented the maintainer call in #5953 by removing the `.max(LIMITS.MAX_LOREBOOK_ENTRIES)` that PR #5944 had added, and deleted the regression scenario that pinned the old counted 400. #5953 anticipated this gap ("uncap and fix that failure message in the same change so an over-large selection says so plainly"); the `context_limit` half landed, this half did not. Unreleased on staging - 848e8fa3d is not in any tag, and the latest release is v2.4.4. The client half (Pixelforge has no branch for a 413 in its failure ladder, so it lands on "refused" copy that blames the setting description) is a separate Marinara-Agents issue and should be fixed there too, since a 413 can also arrive from an older Engine. Found by an AI-assisted sweep of merged PR #5977 against issue #5953, then re-verified against staging 52799569c on 2026-09-13. Please verify before fixing. Related issue from the same sweep: Pasta-Devs/Marinara-Agents#812 (the Pixelforge-side failure copy for the same 413).
bsakaguchi 2026-10-21 06:02:42 +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:5651923204 --> @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 accepts large lore selections with a larger bounded request limit.

<!-- gh-comment-id:5652783192 --> @SpicyMarinara commented on GitHub (Sep 13, 2026): Fixed in #6137, now merged to staging (`e044997a2`). World generation accepts large lore selections with a larger bounded request limit.
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#3401
No description provided.