[GH-ISSUE #3384] [Issue]: Lorebook Keeper "Proposed Text" omits the proposed newFacts for updates to existing entries #1831

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

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

Originally assigned to: @SpicyMarinara on GitHub.

Reported against v2.1.0; confirmed still present on v2.1.1 (verified against source).

What's wrong

When Lorebook Keeper proposes an update to an existing lorebook entry, the "Proposed Text" in the review modal shows the entry's existing/echoed content and leaves out the actual facts being proposed (newFacts). So you review roughly what the entry already says, not what's being added. Brand-new entries preview correctly — it's only updates to existing entries where the newFacts go missing from the preview. (You can confirm the newFacts exist by checking the agent's response in the console: "newFacts": [...] — those items aren't in the Proposed Text.)

How to reproduce (try it yourself)

  1. In a chat with Lorebook Keeper active and "require approval for agent writes" turned on, get it to propose an update to an existing entry (e.g. a new durable fact about a character who already has an entry).
  2. Open the "Review Lorebook Update" modal and read the "Proposed Text".
  3. Compare with the agent's response in the browser console / network.

You'll see: the Proposed Text shows the existing/echoed entry content; the proposed newFacts (visible in the console response) are absent.
Expected: the Proposed Text shows what will actually be committed — the existing entry plus the new facts.

Where it is

packages/server/src/routes/generate/agent-write-approval.ts — the preview is built by formatLorebookWriteApprovalText (61-77) → readUpdateContent (24-33), which returns update.content (or update.entry.content) if present and only falls back to formatting newFacts when there is no content:

if (typeof update.content === "string" && update.content.trim()) return update.content.trim();   // returns here
...
if (Array.isArray(update.newFacts)) { ... }   // never reached when content is present

The Lorebook Keeper is instructed (packages/shared/src/constants/agent-prompts.ts ~165-174) to return only newFacts for updates and use content only for empty/malformed entries — but the model frequently returns a content too (echoing/rewriting the current entry). When it does, the preview shows that content and drops the newFacts.

By contrast, the commit path merges: persistLorebookKeeperUpdates (lorebook-keeper-utils.ts:409-416) uses mergeLorebookKeeperUpdateContent (271-305) with existing + replacement + newFacts. So the preview is built by a different, incomplete path than the commit — it doesn't reflect what will be saved. The proposal is assembled from the raw agent updates (generate.routes.ts:3097, 3135) with no existing-entry lookup.

⚠️ Also worth verifying — possible newFacts loss at commit (not just preview): when an update has action:"update" and a non-empty content, the commit takes the getExplicitUpdateReplacementContent branch (lorebook-keeper-utils.ts:409-411 → 307-315), which treats that content as a wholesale replacement and also drops newFacts. If the model's echoed content doesn't already contain the new facts, they may not just be hidden from the preview — they may not be saved at all. Please check whether newFacts survive to the committed entry in this case.

What's happening

The approval preview and the commit use different content logic. The preview is content-first and treats newFacts as a fallback, so any update carrying a content hides its newFacts. New entries put their real text in content, so they preview fine; updates (whose delta lives in newFacts) don't.

Suggested fix

Build the preview from the same merge the commit uses — resolve the existing entry and show mergeLorebookKeeperUpdateContent(existing, replacement, newFacts), so "Proposed Text" is exactly what will be committed (existing + new facts). This means the proposal builder (buildLorebookWriteApprovalProposal / its call site at generate.routes.ts:3135) needs the existing entry content, which it doesn't currently fetch. Also reconsider whether an update carrying content should drop newFacts at commit at all (the instructions reserve content for empty/malformed entries).

Related enhancement (also requested): once the newFacts are shown, highlight/diff them against the original so it's clear what's new vs. original text (render the appended facts distinctly, or a small diff view). Even when displayed, it's hard to tell new from existing.


AI-investigated against v2.1.1 (git describe = v2.1.1); the preview builder, the keeper output schema, and the commit merge/replace paths were all read and confirmed. The preview-drops-newFacts behavior is verified from the code; the commit-loss angle depends on the model including content — please verify on a real proposal before fixing.

Originally created by @kolacheee on GitHub (Jul 8, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3384 Originally assigned to: @SpicyMarinara on GitHub. *Reported against v2.1.0; confirmed still present on v2.1.1 (verified against source).* **What's wrong** When Lorebook Keeper proposes an **update** to an existing lorebook entry, the "Proposed Text" in the review modal shows the entry's existing/echoed content and leaves **out** the actual facts being proposed (`newFacts`). So you review roughly what the entry already says, not what's being added. **Brand-new entries preview correctly** — it's only updates to existing entries where the newFacts go missing from the preview. (You can confirm the newFacts exist by checking the agent's response in the console: `"newFacts": [...]` — those items aren't in the Proposed Text.) **How to reproduce (try it yourself)** 1. In a chat with Lorebook Keeper active and "require approval for agent writes" turned on, get it to propose an **update** to an existing entry (e.g. a new durable fact about a character who already has an entry). 2. Open the "Review Lorebook Update" modal and read the "Proposed Text". 3. Compare with the agent's response in the browser console / network. **You'll see:** the Proposed Text shows the existing/echoed entry content; the proposed `newFacts` (visible in the console response) are absent. **Expected:** the Proposed Text shows what will actually be committed — the existing entry **plus** the new facts. **Where it is** `packages/server/src/routes/generate/agent-write-approval.ts` — the preview is built by `formatLorebookWriteApprovalText` (61-77) → `readUpdateContent` (24-33), which returns `update.content` (or `update.entry.content`) if present and only falls back to formatting `newFacts` when there is **no** content: ``` if (typeof update.content === "string" && update.content.trim()) return update.content.trim(); // returns here ... if (Array.isArray(update.newFacts)) { ... } // never reached when content is present ``` The Lorebook Keeper is instructed (`packages/shared/src/constants/agent-prompts.ts` ~165-174) to return **only** `newFacts` for updates and use `content` only for empty/malformed entries — but the model frequently returns a `content` too (echoing/rewriting the current entry). When it does, the preview shows that content and drops the `newFacts`. By contrast, the **commit** path merges: `persistLorebookKeeperUpdates` (`lorebook-keeper-utils.ts:409-416`) uses `mergeLorebookKeeperUpdateContent` (271-305) with existing + replacement + newFacts. So the preview is built by a **different, incomplete** path than the commit — it doesn't reflect what will be saved. The proposal is assembled from the raw agent updates (`generate.routes.ts:3097, 3135`) with no existing-entry lookup. **⚠️ Also worth verifying — possible newFacts loss at commit (not just preview):** when an update has `action:"update"` **and** a non-empty `content`, the commit takes the `getExplicitUpdateReplacementContent` branch (`lorebook-keeper-utils.ts:409-411` → `307-315`), which treats that content as a **wholesale replacement** and also drops `newFacts`. If the model's echoed `content` doesn't already contain the new facts, they may not just be hidden from the preview — they may not be saved at all. Please check whether newFacts survive to the committed entry in this case. **What's happening** The approval preview and the commit use different content logic. The preview is content-first and treats `newFacts` as a fallback, so any update carrying a `content` hides its `newFacts`. New entries put their real text in `content`, so they preview fine; updates (whose delta lives in `newFacts`) don't. **Suggested fix** Build the preview from the **same merge the commit uses** — resolve the existing entry and show `mergeLorebookKeeperUpdateContent(existing, replacement, newFacts)`, so "Proposed Text" is exactly what will be committed (existing + new facts). This means the proposal builder (`buildLorebookWriteApprovalProposal` / its call site at `generate.routes.ts:3135`) needs the existing entry content, which it doesn't currently fetch. Also reconsider whether an update carrying `content` should drop `newFacts` at commit at all (the instructions reserve `content` for empty/malformed entries). **Related enhancement (also requested):** once the newFacts are shown, highlight/diff them against the original so it's clear what's **new** vs. original text (render the appended facts distinctly, or a small diff view). Even when displayed, it's hard to tell new from existing. --- *AI-investigated against v2.1.1 (`git describe` = v2.1.1); the preview builder, the keeper output schema, and the commit merge/replace paths were all read and confirmed. The preview-drops-newFacts behavior is verified from the code; the commit-loss angle depends on the model including `content` — please verify on a real proposal before fixing.*
bsakaguchi 2026-10-21 05:43:05 +07:00
Author
Owner

@SpicyMarinara commented on GitHub (Jul 8, 2026):

Addressed in #3388 and merged to staging.

<!-- gh-comment-id:4918159195 --> @SpicyMarinara commented on GitHub (Jul 8, 2026): Addressed in #3388 and merged to staging.
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#1831
No description provided.