[GH-ISSUE #6143] Lore attached to the place you are standing in can vanish from the prompt even when you type its keyword #3414

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

Originally assigned to: @SpicyMarinara on GitHub.

When a location carries more attached lore than its reserved slice can hold, the entries that do not fit are not just left out of the location's own contribution, they are removed from the rest of the turn entirely. An entry whose keyword the player literally typed, an entry in the middle of an open sticky window, or an entry another entry would have pulled in, all stay out of the prompt while the player stands in that place, and all arrive normally the moment the entry is detached from the location. Being somewhere makes the model know less about it.

How to reproduce (try it yourself)

You need a Roleplay chat with World Maps enabled and a saved map with at least one location. No model reply is needed: the prompt peek shows the drop.

  1. Lorebooks: create a book, leave it enabled for the chat, and set its Token Budget to 20000 so only the location's own 2048 token reserve can bind.
  2. Add six entries. For five of them, tick Constant, leave the keys empty, and paste about 1600 characters of filler into each (roughly 400 tokens each, so about 2000 of the 2048 token location reserve). For the sixth, leave Constant off, set its key to dragon, and paste about 1600 characters containing the marker word DRAGONMARK.
  3. Agents, World Maps: select a location, open Linked lore, attach all six entries, save.
  4. In the chat, make that location the current location, then send: I ask the innkeeper about the dragon.
  5. Open Peek Prompt / Active Context for that turn and search for DRAGONMARK.

What you'll see: the five constant entries are in the prompt, the dragon entry is not. It is listed as skipped with blockedBy "location" and matchType "keyword". Total lore is about 2000 tokens against the chat's 8192 token lorebook budget, so there was plenty of room. Detach only the dragon entry from the location, leave everything else the same, and send the identical message: it now arrives through its keyword alongside the same five constants.

What should happen: the dragon entry arrives through its keyword either way. The location reserve should decide how much the location contributes, not whether the entry is allowed to activate at all.

Two more variants of the same drop, if you want to see the range:

  • Sticky: make the sixth entry non constant, key ledger, Sticky 3. Send a message containing ledger while the location is not current, so the sticky window opens. Then make the location current and send a message that does not contain ledger. The entry is withheld even though its window is still open, and the window still counts down that turn.
  • Recursion: turn Recursive Scanning on for the book. Add a parent entry keyed gate, untick its Prevent Recursion (it defaults to on, the repro fails without this), and give it content mentioning Obsidian Order. Key the sixth entry Obsidian Order. Send I approach the gate.: the parent arrives, the child does not. Detach the child from the location and it arrives as a recursive activation.

Where it is

packages/server/src/services/lorebook/index.ts, in processLorebooks at staging ac14dd704:

  • :1252 to :1253 build locationBudgetSkippedIds from the location budget's skipped entries and filter them out of allEntries into scannableEntries. There is no check for whether the entry was constant.
  • :1256 passes scannableEntries to scanForActivatedEntries (before PR #5976 this was allEntries), which is the ordinary keyword, semantic and sticky scan.
  • :1261 passes the same scannableEntries as the entry pool for recursive activation.
  • :620 sets CURRENT_LOCATION_LORE_TOKEN_BUDGET = 2_048. No production caller overrides it, so it binds on every chat turn.

What's happening

The location reserve is applied first, and every entry it declines is then deleted from the pool that the rest of the turn scans. Constants sort ahead of everything in the selection order, so the entries the reserve declines are structurally the non constant ones, which are exactly the entries that had another legitimate way into the prompt. Losing the location source therefore also loses the keyword match, the open sticky window, and recursion reachability.

Suggested fix

Make the location reserve bound the contribution of the location source only, and leave the entry eligible for everything else. An entry the reserve declines should still enter the ordinary keyword and semantic scan, should still be delivered by its own open sticky window, and should still be reachable as a recursive child. If it activates that way it should be charged against the ordinary chat wide lorebook budget and reported with its real activation source, and no "location" skip record should be left behind for an entry that is present in the prompt. That accounting change is what issue #5943's second complaint (an entry reported as set aside while being present) actually needs. The specific escape hatch #5943 named was a constant entry re activating with zero messages, so suppressing the constant re activation alone would close it.

This also matches the design documents: docs/development/hierarchical-locations-prd-v3.md line 76 calls a location attachment "an explicit chat-scoped activation source", line 356 calls the 2048 figure a total reserved cap per owner prompt, and line 357 says an entry activated by both location and ordinary keyword, semantic, recursive or constant rules is injected once and reports every activation source.

One open question before anyone patches this: the discussion on #5943 said the patch would preserve the shared location budget across ordinary and recursive scans. Was removing location budget drops from the keyword, semantic, sticky and recursive sources intended, or was the target only the constant re activation? If the narrow shape is the intended one, note that the regression lane the PR added (scripts/regressions/experience-lore-entries.regression.ts:255 to 281) pins only a dropped forced constant and a recursive child that is not in the forced selection, so narrowing the filter would not fight an existing assertion. The CHANGELOG line at CHANGELOG.md:227 says the change keeps rejected constant entries out of later scans, which is narrower than what the code does, so it would need a word either way.

Context

Introduced by merged PR #5976, which closed issue #5943. PR #6137 did not touch this area: it changed only the per chat entry scope files, and nothing since has touched services/lorebook/index.ts or keyword-scanner.ts. Unreleased on staging (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.

Originally created by @kolacheee on GitHub (Sep 13, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6143 Originally assigned to: @SpicyMarinara on GitHub. When a location carries more attached lore than its reserved slice can hold, the entries that do not fit are not just left out of the location's own contribution, they are removed from the rest of the turn entirely. An entry whose keyword the player literally typed, an entry in the middle of an open sticky window, or an entry another entry would have pulled in, all stay out of the prompt while the player stands in that place, and all arrive normally the moment the entry is detached from the location. Being somewhere makes the model know less about it. ## How to reproduce (try it yourself) You need a Roleplay chat with World Maps enabled and a saved map with at least one location. No model reply is needed: the prompt peek shows the drop. 1. Lorebooks: create a book, leave it enabled for the chat, and set its Token Budget to 20000 so only the location's own 2048 token reserve can bind. 2. Add six entries. For five of them, tick Constant, leave the keys empty, and paste about 1600 characters of filler into each (roughly 400 tokens each, so about 2000 of the 2048 token location reserve). For the sixth, leave Constant off, set its key to `dragon`, and paste about 1600 characters containing the marker word DRAGONMARK. 3. Agents, World Maps: select a location, open Linked lore, attach all six entries, save. 4. In the chat, make that location the current location, then send: `I ask the innkeeper about the dragon.` 5. Open Peek Prompt / Active Context for that turn and search for DRAGONMARK. **What you'll see:** the five constant entries are in the prompt, the dragon entry is not. It is listed as skipped with blockedBy "location" and matchType "keyword". Total lore is about 2000 tokens against the chat's 8192 token lorebook budget, so there was plenty of room. Detach only the dragon entry from the location, leave everything else the same, and send the identical message: it now arrives through its keyword alongside the same five constants. **What should happen:** the dragon entry arrives through its keyword either way. The location reserve should decide how much the location contributes, not whether the entry is allowed to activate at all. Two more variants of the same drop, if you want to see the range: - Sticky: make the sixth entry non constant, key `ledger`, Sticky 3. Send a message containing `ledger` while the location is not current, so the sticky window opens. Then make the location current and send a message that does not contain `ledger`. The entry is withheld even though its window is still open, and the window still counts down that turn. - Recursion: turn Recursive Scanning on for the book. Add a parent entry keyed `gate`, untick its Prevent Recursion (it defaults to on, the repro fails without this), and give it content mentioning `Obsidian Order`. Key the sixth entry `Obsidian Order`. Send `I approach the gate.`: the parent arrives, the child does not. Detach the child from the location and it arrives as a recursive activation. ## Where it is `packages/server/src/services/lorebook/index.ts`, in `processLorebooks` at staging ac14dd704: - :1252 to :1253 build `locationBudgetSkippedIds` from the location budget's skipped entries and filter them out of `allEntries` into `scannableEntries`. There is no check for whether the entry was constant. - :1256 passes `scannableEntries` to `scanForActivatedEntries` (before PR #5976 this was `allEntries`), which is the ordinary keyword, semantic and sticky scan. - :1261 passes the same `scannableEntries` as the entry pool for recursive activation. - :620 sets `CURRENT_LOCATION_LORE_TOKEN_BUDGET = 2_048`. No production caller overrides it, so it binds on every chat turn. ## What's happening The location reserve is applied first, and every entry it declines is then deleted from the pool that the rest of the turn scans. Constants sort ahead of everything in the selection order, so the entries the reserve declines are structurally the non constant ones, which are exactly the entries that had another legitimate way into the prompt. Losing the location source therefore also loses the keyword match, the open sticky window, and recursion reachability. ## Suggested fix Make the location reserve bound the contribution of the location source only, and leave the entry eligible for everything else. An entry the reserve declines should still enter the ordinary keyword and semantic scan, should still be delivered by its own open sticky window, and should still be reachable as a recursive child. If it activates that way it should be charged against the ordinary chat wide lorebook budget and reported with its real activation source, and no "location" skip record should be left behind for an entry that is present in the prompt. That accounting change is what issue #5943's second complaint (an entry reported as set aside while being present) actually needs. The specific escape hatch #5943 named was a constant entry re activating with zero messages, so suppressing the constant re activation alone would close it. This also matches the design documents: `docs/development/hierarchical-locations-prd-v3.md` line 76 calls a location attachment "an explicit chat-scoped activation source", line 356 calls the 2048 figure a total reserved cap per owner prompt, and line 357 says an entry activated by both location and ordinary keyword, semantic, recursive or constant rules is injected once and reports every activation source. One open question before anyone patches this: the discussion on #5943 said the patch would preserve the shared location budget across ordinary and recursive scans. Was removing location budget drops from the keyword, semantic, sticky and recursive sources intended, or was the target only the constant re activation? If the narrow shape is the intended one, note that the regression lane the PR added (`scripts/regressions/experience-lore-entries.regression.ts`:255 to 281) pins only a dropped forced constant and a recursive child that is not in the forced selection, so narrowing the filter would not fight an existing assertion. The CHANGELOG line at `CHANGELOG.md`:227 says the change keeps rejected constant entries out of later scans, which is narrower than what the code does, so it would need a word either way. ## Context Introduced by merged PR #5976, which closed issue #5943. PR #6137 did not touch this area: it changed only the per chat entry scope files, and nothing since has touched `services/lorebook/index.ts` or `keyword-scanner.ts`. Unreleased on staging (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.
bsakaguchi 2026-10-21 06:02:52 +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:5654637564 --> @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#3414
No description provided.