[GH-ISSUE #2980] [Issue]: Explicit Lorebook Keeper update is ignored for the nested-entry output shape, turning replacements into appends #1555

Closed
opened 2026-10-21 05:39:00 +07:00 by bsakaguchi · 1 comment
Owner

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

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong

On the direct (non-approval) keeper path, when the model emits an explicit replacement using the nested-entry shape { action:"update", entryName:"X", entry:{ content:"..." } }, the keeper does not replace the entry. getExplicitUpdateReplacementContent only inspects the top-level update.content and ignores entry.content, so it returns null and the code falls through to mergeLorebookKeeperUpdateContent, which appends. An entry the model intended to fully rewrite (e.g. "the castle is now destroyed") ends up with old and new — often contradictory — content concatenated. The canonical prompt instructs the flat shape, so this fires only when the model drifts to the nested shape, which the codebase explicitly tolerates everywhere else.

How to reproduce (try it yourself)

  1. Enable the Lorebook Keeper (no write approval needed; direct persist path).
  2. Have an existing entry "Castle" with content "The castle stands proud and intact.".
  3. Cause the model to emit {"action":"update","entryName":"Castle","entry":{"content":"The castle has been destroyed and lies in ruins."}}.

You'll see: the entry becomes "The castle stands proud and intact.\n\nThe castle has been destroyed and lies in ruins." — contradictory content.
Expected: a full replacement, as with the flat {action:"update", entryName, content} shape.

Where it is

  • packages/server/src/routes/generate/lorebook-keeper-utils.ts:307-313 (getExplicitUpdateReplacementContent checks only the top-level update.content) vs :334-341 (readKeeperUpdateContent, which is nested-aware via readNestedEntry).
  • Call site :407-414; append behavior at :282-290.

What's happening

All the other keeper field readers (readKeeperUpdateName/Content/Keys/Tag) consult both the top-level update and the nested update.entry object, but getExplicitUpdateReplacementContent only checks the top-level update.content. The two readers are inconsistent, so an explicit replacement in the supported nested shape is misclassified as a non-replacement and merged (appended) instead.

Suggested fix

Make getExplicitUpdateReplacementContent use the same nested-aware read as the rest of the file (reuse readNestedEntry / readKeeperUpdateContent): treat action === "update" with non-empty resolved content (top-level or entry.content) as a full replacement.


AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.

Originally created by @kolacheee on GitHub (Jun 29, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2980 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** On the direct (non-approval) keeper path, when the model emits an explicit replacement using the nested-entry shape `{ action:"update", entryName:"X", entry:{ content:"..." } }`, the keeper does **not** replace the entry. `getExplicitUpdateReplacementContent` only inspects the top-level `update.content` and ignores `entry.content`, so it returns null and the code falls through to `mergeLorebookKeeperUpdateContent`, which **appends**. An entry the model intended to fully rewrite (e.g. "the castle is now destroyed") ends up with old and new — often contradictory — content concatenated. The canonical prompt instructs the flat shape, so this fires only when the model drifts to the nested shape, which the codebase explicitly tolerates everywhere else. **How to reproduce (try it yourself)** 1. Enable the Lorebook Keeper (no write approval needed; direct persist path). 2. Have an existing entry "Castle" with content "The castle stands proud and intact.". 3. Cause the model to emit `{"action":"update","entryName":"Castle","entry":{"content":"The castle has been destroyed and lies in ruins."}}`. **You'll see:** the entry becomes "The castle stands proud and intact.\n\nThe castle has been destroyed and lies in ruins." — contradictory content. **Expected:** a full replacement, as with the flat `{action:"update", entryName, content}` shape. **Where it is** - `packages/server/src/routes/generate/lorebook-keeper-utils.ts:307-313` (`getExplicitUpdateReplacementContent` checks only the top-level `update.content`) vs `:334-341` (`readKeeperUpdateContent`, which **is** nested-aware via `readNestedEntry`). - Call site `:407-414`; append behavior at `:282-290`. **What's happening** All the other keeper field readers (`readKeeperUpdateName`/`Content`/`Keys`/`Tag`) consult both the top-level update and the nested `update.entry` object, but `getExplicitUpdateReplacementContent` only checks the top-level `update.content`. The two readers are inconsistent, so an explicit replacement in the supported nested shape is misclassified as a non-replacement and merged (appended) instead. **Suggested fix** Make `getExplicitUpdateReplacementContent` use the same nested-aware read as the rest of the file (reuse `readNestedEntry` / `readKeeperUpdateContent`): treat `action === "update"` with non-empty resolved content (top-level **or** `entry.content`) as a full replacement. --- *AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.*
Author
Owner

@SpicyMarinara commented on GitHub (Jun 29, 2026):

Fixed in the v2.0.7 branch: explicit Lorebook Keeper update replacements now read nested entry.content as well as top-level content, so nested action:update proposals replace instead of append. Validated with pnpm check and pnpm regression:prompt.

<!-- gh-comment-id:4831163686 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Fixed in the v2.0.7 branch: explicit Lorebook Keeper update replacements now read nested entry.content as well as top-level content, so nested action:update proposals replace instead of append. Validated with pnpm check and pnpm regression:prompt.
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#1555
No description provided.