[GH-ISSUE #2970] [Issue]: Lorebook Keeper approval updates overwrite existing entry content instead of appending, destroying accumulated lore #1545

Closed
opened 2026-10-21 05:38:50 +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/2970

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong

When a chat has agent write approval enabled (chatMeta.agentWriteApprovalRequired === true), approving a Lorebook Keeper update to an existing, populated entry replaces that entry's entire content with only the newly-extracted facts. All prior content the entry accumulated over many turns is lost. The same model output, with approval off, correctly appends. So enabling approval silently turns appends into destructive overwrites.

How to reproduce (try it yourself)

  1. Enable agent write approval for a chat (chatMeta.agentWriteApprovalRequired = true) and enable the Lorebook Keeper agent.
  2. Let the keeper build a target-lorebook entry (e.g. "Castle") with substantial content over several turns.
  3. Continue the roleplay so the keeper emits an update for that entry; per its prompt it returns only atomic new facts, e.g. {"entryName":"Castle","newFacts":["A secret passage was found."]}.
  4. Approve the proposal.

You'll see: the "Castle" entry now contains only "A secret passage was found." — every earlier paragraph is gone.
Expected: the new fact is appended to the existing content (the behavior you get with approval off).

Where it is

  • packages/server/src/routes/generate/agent-write-approval.ts:24-33 — readUpdateContent flattens newFacts into a markdown bullet string, never including existing content.
  • packages/server/src/routes/generate/agent-write-approval.ts:61-77 — formatLorebookWriteApprovalText puts only that flattened-facts string into the proposal.
  • packages/server/src/routes/generate/agent-write-approval.ts:134-140 — parseLorebookWriteApprovalText re-wraps the approved text as { action: "update", content: <flattened facts> }.
  • packages/server/src/routes/generate/lorebook-keeper-utils.ts:307-313 (getExplicitUpdateReplacementContent) and :407-414 (existing-entry branch) — any action:"update" with non-empty top-level content short-circuits mergeLorebookKeeperUpdateContent and becomes a full replacement.
  • Commit path: packages/server/src/routes/chats.routes.ts:1101-1124 (parseLorebookWriteApprovalText(text) → persistLorebookKeeperUpdates(... updates)).

What's happening

The non-approval path passes the raw model update ({entryName, newFacts}) straight to persistLorebookKeeperUpdates, so getExplicitUpdateReplacementContent returns null (no top-level content) and the merge appends. The approval round-trip instead flattens the update into a markdown proposal containing only the new facts, then parseLorebookWriteApprovalText re-wraps it as action:"update" + that text in content. On commit, getExplicitUpdateReplacementContent treats action:"update" + non-empty content as a full replacement, bypassing the merge. The append intent is lost in the approval serialization, and the existing content is never shown in the proposal, so the user has no way to know it's about to be wiped.

Suggested fix

Make the proposal what-you-see-is-what-you-commit. The cleanest fix is to build the proposal text from the merged (existing + new) content rather than the new facts alone — i.e. in markLorebookResultForApproval / readUpdateContent, seed the proposal with the existing entry content plus the new facts, so the committed full-replacement is exactly the content the user reviewed (and can edit).

Alternatively, preserve the append semantics across the round-trip: have parseLorebookWriteApprovalText emit the parsed facts as newFacts (or action:"append") instead of action:"update" + content, so persistLorebookKeeperUpdates merges with existing content. (Note: with this approach, if the user edited the proposal text intending a rewrite, the edit would be appended rather than replacing — which is why surfacing the existing content in the proposal, option one, is the more predictable fix.)


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/2970 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** When a chat has agent write approval enabled (`chatMeta.agentWriteApprovalRequired === true`), approving a Lorebook Keeper update to an **existing, populated** entry replaces that entry's entire content with only the newly-extracted facts. All prior content the entry accumulated over many turns is lost. The same model output, with approval **off**, correctly appends. So enabling approval silently turns appends into destructive overwrites. **How to reproduce (try it yourself)** 1. Enable agent write approval for a chat (`chatMeta.agentWriteApprovalRequired = true`) and enable the Lorebook Keeper agent. 2. Let the keeper build a target-lorebook entry (e.g. "Castle") with substantial content over several turns. 3. Continue the roleplay so the keeper emits an update for that entry; per its prompt it returns only atomic new facts, e.g. `{"entryName":"Castle","newFacts":["A secret passage was found."]}`. 4. Approve the proposal. **You'll see:** the "Castle" entry now contains only "A secret passage was found." — every earlier paragraph is gone. **Expected:** the new fact is appended to the existing content (the behavior you get with approval off). **Where it is** - `packages/server/src/routes/generate/agent-write-approval.ts:24-33` — `readUpdateContent` flattens `newFacts` into a markdown bullet string, never including existing content. - `packages/server/src/routes/generate/agent-write-approval.ts:61-77` — `formatLorebookWriteApprovalText` puts only that flattened-facts string into the proposal. - `packages/server/src/routes/generate/agent-write-approval.ts:134-140` — `parseLorebookWriteApprovalText` re-wraps the approved text as `{ action: "update", content: <flattened facts> }`. - `packages/server/src/routes/generate/lorebook-keeper-utils.ts:307-313` (`getExplicitUpdateReplacementContent`) and `:407-414` (existing-entry branch) — any `action:"update"` with non-empty top-level `content` short-circuits `mergeLorebookKeeperUpdateContent` and becomes a full replacement. - Commit path: `packages/server/src/routes/chats.routes.ts:1101-1124` (`parseLorebookWriteApprovalText(text)` → `persistLorebookKeeperUpdates(... updates)`). **What's happening** The non-approval path passes the raw model update (`{entryName, newFacts}`) straight to `persistLorebookKeeperUpdates`, so `getExplicitUpdateReplacementContent` returns null (no top-level `content`) and the merge appends. The approval round-trip instead flattens the update into a markdown proposal containing only the new facts, then `parseLorebookWriteApprovalText` re-wraps it as `action:"update"` + that text in `content`. On commit, `getExplicitUpdateReplacementContent` treats `action:"update"` + non-empty `content` as a full replacement, bypassing the merge. The append intent is lost in the approval serialization, and the existing content is never shown in the proposal, so the user has no way to know it's about to be wiped. **Suggested fix** Make the proposal **what-you-see-is-what-you-commit**. The cleanest fix is to build the proposal text from the *merged* (existing + new) content rather than the new facts alone — i.e. in `markLorebookResultForApproval` / `readUpdateContent`, seed the proposal with the existing entry content plus the new facts, so the committed full-replacement is exactly the content the user reviewed (and can edit). Alternatively, preserve the append semantics across the round-trip: have `parseLorebookWriteApprovalText` emit the parsed facts as `newFacts` (or `action:"append"`) instead of `action:"update"` + `content`, so `persistLorebookKeeperUpdates` merges with existing content. (Note: with this approach, if the user *edited* the proposal text intending a rewrite, the edit would be appended rather than replacing — which is why surfacing the existing content in the proposal, option one, is the more predictable fix.) --- *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: approval-gated Lorebook Keeper text is now parsed as append-style approved lore instead of an explicit replacement, so approving new facts no longer overwrites existing entry content. Validated with pnpm check and pnpm regression:prompt.

<!-- gh-comment-id:4831160191 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Fixed in the v2.0.7 branch: approval-gated Lorebook Keeper text is now parsed as append-style approved lore instead of an explicit replacement, so approving new facts no longer overwrites existing entry content. 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#1545
No description provided.