[GH-ISSUE #6145] World generation silently cuts off a lore entry you picked, then reports it as fully included #3419

Closed
opened 2026-10-21 06:02:53 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @kolacheee on GitHub (Sep 13, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6145

Originally assigned to: @SpicyMarinara on GitHub.

When you tick a lorebook entry for world generation and that entry contains a macro such as {{personaDescription}}, the engine can cut the entry off part way through and still report it as included in full. Nothing is logged and nothing is flagged, so the world gets written from less lore than you chose.

How to reproduce (try it yourself)

  1. In Personas, give the persona your Game chat uses a description of about 2,000 characters. Any real paragraph length description works, longer is easier to see.
  2. In Lorebooks, create a book that is not global and not bound to anything, and add one entry. Content: the word GHEAD, then {{personaDescription}} repeated 100 times, then about 50,000 characters of filler text, then the literal marker GTAIL_MARKER_END at the very end. The entry itself is only about 52 KB, an ordinary large lore entry.
  3. Point the Game chat at a connection with a large Max Context (1,000,000, or anything comfortably above the selection) so the context check and the output budget refusal cannot be what bites.
  4. Tick only that entry in the world generation lorebook picker, set server logging to debug, and run world generation.
  5. Read the outbound system message in the log.

What you'll see: The lore stops dead at 200,000 characters. GTAIL_MARKER_END is gone, along with roughly 48,000 characters of expanded persona text, about a fifth of the entry. No warning appears anywhere, and the reply's lorebook block still says includedEntries: 1 with an empty skippedEntries list.

What should happen: The whole entry reaches the model. If something really has to cut it, the entry is reported as skipped with a reason, never counted as included.

Two controls that pin the cause. Delete every {{personaDescription}} from the entry but keep the same size: the marker survives, which rules out entry size, the token budget and the context window. Shrink the filler so the resolved text lands under 200,000 characters (10 macros instead of 100): everything survives, expansions included.

Where it is

At staging ac14dd704:

  • packages/server/src/routes/game.routes.ts:10888, inside resolveLoreMacrosForFinal: maxMacroOutputLength: Math.max(value.length, 200_000), where value is the entry text before macros expand.
  • packages/shared/src/utils/macro-engine.ts:2387 applies clampMacroOutput to the fully expanded string. Lines 273 to 276 are a bare slice with no signal, and line 157 is MAX_MACRO_OUTPUT_LENGTH = 200_000.
  • packages/server/src/routes/game.routes.ts:11175-11184 builds skippedEntries only from the token budget skips, so a macro clamp cut has no path into it.
  • CHANGELOG.md:62 ships the sentence "Every eligible entry you select is included in full."

What's happening

The ceiling handed to the macro resolver is computed from the entry's length before macros expand, but the clamp is applied afterwards, to the expanded text. Headroom is therefore max(0, 200,000 minus the raw entry length): an entry of 200,000 characters or more gets none at all, and a smaller entry gets only whatever is left of a flat 200,000, which 100 copies of a 2,000 character persona description blow straight through. The boundary is not at 200,000 raw characters either: a 199,900 character entry that grows by about 2,000 characters truncates too. The clamp then simply slices the string and returns it, so nothing downstream can learn that anything was lost, and the entry is still counted in includedEntries.

Suggested fix

Two parts, and both are needed. Resizing the ceiling alone still truncates silently at some larger size, and a diagnostic alone leaves the loss in place.

  1. Size the ceiling for the resolved text rather than the raw text. Something like value.length + 200_000 keeps the runaway expansion guard that the call site comment says it is retaining, and removes the discontinuity.
  2. Make a clamp that does bite visible. clampMacroOutput should mark the budget as exceeded so the route can move the entry into skippedEntries with a blockedBy naming the macro clamp, or fail the call the way an over context selection already does. Returning a short string and then counting the entry as included is the invisible budget failure this feature was built to remove, relocated from the token budget into the macro clamp.

There is no coverage today. scripts/regressions/experience-lore-entries.regression.ts:704-718 asserts that a huge selection must arrive whole, but its content carries no macros, so the lane passes at head with this live. A macro carrying twin of that assertion is worth adding, asserting on the clamp signature (the lore section length equals the raw entry length, or exactly 200,000) rather than on a short end marker.

One thing to keep out of scope: every other resolveContent caller passes no override and clamps at a flat 200,000 with the same silence. That app wide question is older and larger, and deserves its own issue if you want it.

Context

Introduced by PR #5977, which closed issue #5953 ("World generation shouldn't cap how much lorebook a player can feed it"). That PR removed the 3,000 token EXPERIENCE_LORE_TOKEN_BUDGET, which used to refuse an oversized entry with a named skip record, and added the maxMacroOutputLength option in its place, so on this route an honest refusal became a silent cut. #5953 argues the opposite of the current behavior: "there's no per-entry content cap... The first real wall is the model's own context window." PR #6137 did not touch this: its game.routes.ts hunks are the three sibling fixes from the same sweep (#6122, #6126, #6129), and macro-engine.ts is not in that diff at all. Unreleased on staging, the latest release tag is v2.4.4.

Found by an AI-assisted sweep and re-verified against staging ac14dd704 on 2026-09-13. Please verify before fixing.

Related issue from the same sweep: #6146 (the pre-call context check missing the reply schema on the same route).

Originally created by @kolacheee on GitHub (Sep 13, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6145 Originally assigned to: @SpicyMarinara on GitHub. When you tick a lorebook entry for world generation and that entry contains a macro such as {{personaDescription}}, the engine can cut the entry off part way through and still report it as included in full. Nothing is logged and nothing is flagged, so the world gets written from less lore than you chose. ## How to reproduce (try it yourself) 1. In Personas, give the persona your Game chat uses a description of about 2,000 characters. Any real paragraph length description works, longer is easier to see. 2. In Lorebooks, create a book that is not global and not bound to anything, and add one entry. Content: the word GHEAD, then {{personaDescription}} repeated 100 times, then about 50,000 characters of filler text, then the literal marker GTAIL_MARKER_END at the very end. The entry itself is only about 52 KB, an ordinary large lore entry. 3. Point the Game chat at a connection with a large Max Context (1,000,000, or anything comfortably above the selection) so the context check and the output budget refusal cannot be what bites. 4. Tick only that entry in the world generation lorebook picker, set server logging to debug, and run world generation. 5. Read the outbound system message in the log. **What you'll see:** The lore stops dead at 200,000 characters. GTAIL_MARKER_END is gone, along with roughly 48,000 characters of expanded persona text, about a fifth of the entry. No warning appears anywhere, and the reply's lorebook block still says includedEntries: 1 with an empty skippedEntries list. **What should happen:** The whole entry reaches the model. If something really has to cut it, the entry is reported as skipped with a reason, never counted as included. Two controls that pin the cause. Delete every {{personaDescription}} from the entry but keep the same size: the marker survives, which rules out entry size, the token budget and the context window. Shrink the filler so the resolved text lands under 200,000 characters (10 macros instead of 100): everything survives, expansions included. ## Where it is At staging ac14dd704: - `packages/server/src/routes/game.routes.ts:10888`, inside `resolveLoreMacrosForFinal`: `maxMacroOutputLength: Math.max(value.length, 200_000)`, where `value` is the entry text before macros expand. - `packages/shared/src/utils/macro-engine.ts:2387` applies `clampMacroOutput` to the fully expanded string. Lines 273 to 276 are a bare slice with no signal, and line 157 is `MAX_MACRO_OUTPUT_LENGTH = 200_000`. - `packages/server/src/routes/game.routes.ts:11175-11184` builds `skippedEntries` only from the token budget skips, so a macro clamp cut has no path into it. - `CHANGELOG.md:62` ships the sentence "Every eligible entry you select is included in full." ## What's happening The ceiling handed to the macro resolver is computed from the entry's length before macros expand, but the clamp is applied afterwards, to the expanded text. Headroom is therefore max(0, 200,000 minus the raw entry length): an entry of 200,000 characters or more gets none at all, and a smaller entry gets only whatever is left of a flat 200,000, which 100 copies of a 2,000 character persona description blow straight through. The boundary is not at 200,000 raw characters either: a 199,900 character entry that grows by about 2,000 characters truncates too. The clamp then simply slices the string and returns it, so nothing downstream can learn that anything was lost, and the entry is still counted in includedEntries. ## Suggested fix Two parts, and both are needed. Resizing the ceiling alone still truncates silently at some larger size, and a diagnostic alone leaves the loss in place. 1. Size the ceiling for the resolved text rather than the raw text. Something like `value.length + 200_000` keeps the runaway expansion guard that the call site comment says it is retaining, and removes the discontinuity. 2. Make a clamp that does bite visible. `clampMacroOutput` should mark the budget as exceeded so the route can move the entry into `skippedEntries` with a `blockedBy` naming the macro clamp, or fail the call the way an over context selection already does. Returning a short string and then counting the entry as included is the invisible budget failure this feature was built to remove, relocated from the token budget into the macro clamp. There is no coverage today. `scripts/regressions/experience-lore-entries.regression.ts:704-718` asserts that a huge selection must arrive whole, but its content carries no macros, so the lane passes at head with this live. A macro carrying twin of that assertion is worth adding, asserting on the clamp signature (the lore section length equals the raw entry length, or exactly 200,000) rather than on a short end marker. One thing to keep out of scope: every other `resolveContent` caller passes no override and clamps at a flat 200,000 with the same silence. That app wide question is older and larger, and deserves its own issue if you want it. ## Context Introduced by PR #5977, which closed issue #5953 ("World generation shouldn't cap how much lorebook a player can feed it"). That PR removed the 3,000 token EXPERIENCE_LORE_TOKEN_BUDGET, which used to refuse an oversized entry with a named skip record, and added the maxMacroOutputLength option in its place, so on this route an honest refusal became a silent cut. #5953 argues the opposite of the current behavior: "there's no per-entry content cap... The first real wall is the model's own context window." PR #6137 did not touch this: its game.routes.ts hunks are the three sibling fixes from the same sweep (#6122, #6126, #6129), and macro-engine.ts is not in that diff at all. Unreleased on staging, the latest release tag is v2.4.4. Found by an AI-assisted sweep and re-verified against staging ac14dd704 on 2026-09-13. Please verify before fixing. Related issue from the same sweep: #6146 (the pre-call context check missing the reply schema on the same route).
bsakaguchi 2026-10-21 06:02:53 +07:00
Author
Owner

@SpicyMarinara commented on GitHub (Sep 13, 2026):

Codex is addressing this report on behalf of @SpicyMarinara in draft PR #6168 as part of the requested issue sweep. I will verify the reported path against staging and preserve existing behavior outside the narrow fix.

<!-- gh-comment-id:5654637306 --> @SpicyMarinara commented on GitHub (Sep 13, 2026): Codex is addressing this report on behalf of @SpicyMarinara in draft PR #6168 as part of the requested issue sweep. I will verify the reported path against staging and preserve existing behavior outside the narrow fix.
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#3419
No description provided.