[PR #488] [MERGED] Fix Lorebook Keeper duplicate paragraph persistence #4640

Closed
opened 2026-10-22 04:09:23 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/488
Author: @cha1latte
Created: 5/6/2026
Status: ✅ Merged
Merged: 5/7/2026
Merged by: @cha1latte

Base: main ← Head: fix/issue-459-lorebook-keeper-dedupe


📝 Commits (3)

  • ad4a1a8 Fix Lorebook Keeper duplicate paragraph persistence
  • effd23a Address Lorebook Keeper dedupe review feedback
  • b1f3108 Preserve replacement content with keeper facts

📊 Changes

1 file changed (+25 additions, -4 deletions)

View changed files

📝 packages/server/src/routes/generate/lorebook-keeper-utils.ts (+25 -4)

📄 Description

What?

Fixes Lorebook Keeper update persistence so repeated duplicate paragraphs are collapsed before content is saved.

This hardens the existing Lorebook Keeper merge path against model outputs that repeat the same replacement paragraph multiple times.

Fixes #459

Why?

Issue #459 reports Lorebook Keeper accumulating 3-6 copies of the same paragraph for a character instead of replacing or adding only new information.

Even with the newer newFacts prompt path, the server should defensively dedupe repeated replacement content because LLM output can ignore formatting instructions.

How?

Added paragraph-level deduplication inside mergeLorebookKeeperUpdateContent.

The helper normalizes paragraph text for comparison, keeps the first copy, and still preserves novel replacement paragraphs and novel newFacts.

Testing?

  • pnpm --dir packages/server exec tsx ../../scratch/issue-459-lorebook-keeper-repro.ts
    • Before the fix: failed with 3 occurrences of the same paragraph.
    • After the fix: passed.
    • Edge cases covered: duplicate replacement paragraphs collapse, novel replacement content is preserved, duplicate newFacts collapse.
  • pnpm check passed.

Screenshots / Visual Proof

Issue #459 visual proof

Visual proof shows the before repro failing with 3 duplicate paragraph occurrences, and the after repro passing with the duplicate collapsed to 1 copy.

Anything Else?

Opened as draft for maintainer review. No manual hardware, provider, or UI verification is required for the core claim.

Summary by CodeRabbit

  • Bug Fixes
    • Improved merging of lorebook keeper updates: paragraph content is now normalized, trimmed, deduplicated, and rejoined with proper spacing to prevent duplicate paragraphs and produce cleaner, consolidated lorebook entries.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/488 **Author:** [@cha1latte](https://github.com/cha1latte) **Created:** 5/6/2026 **Status:** ✅ Merged **Merged:** 5/7/2026 **Merged by:** [@cha1latte](https://github.com/cha1latte) **Base:** `main` ← **Head:** `fix/issue-459-lorebook-keeper-dedupe` --- ### 📝 Commits (3) - [`ad4a1a8`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ad4a1a87b860661148b59846ae6e3a7d0e5f2772) Fix Lorebook Keeper duplicate paragraph persistence - [`effd23a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/effd23a54985ced6c268a4b76736eb37eeb45b42) Address Lorebook Keeper dedupe review feedback - [`b1f3108`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b1f31082724f0bfbe4eea771ca690a8414cd8073) Preserve replacement content with keeper facts ### 📊 Changes **1 file changed** (+25 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/routes/generate/lorebook-keeper-utils.ts` (+25 -4) </details> ### 📄 Description ## What? Fixes Lorebook Keeper update persistence so repeated duplicate paragraphs are collapsed before content is saved. This hardens the existing Lorebook Keeper merge path against model outputs that repeat the same replacement paragraph multiple times. Fixes #459 ## Why? Issue #459 reports Lorebook Keeper accumulating 3-6 copies of the same paragraph for a character instead of replacing or adding only new information. Even with the newer `newFacts` prompt path, the server should defensively dedupe repeated replacement content because LLM output can ignore formatting instructions. ## How? Added paragraph-level deduplication inside `mergeLorebookKeeperUpdateContent`. The helper normalizes paragraph text for comparison, keeps the first copy, and still preserves novel replacement paragraphs and novel `newFacts`. ## Testing? - `pnpm --dir packages/server exec tsx ../../scratch/issue-459-lorebook-keeper-repro.ts` - Before the fix: failed with 3 occurrences of the same paragraph. - After the fix: passed. - Edge cases covered: duplicate replacement paragraphs collapse, novel replacement content is preserved, duplicate `newFacts` collapse. - `pnpm check` passed. ## Screenshots / Visual Proof ![Issue #459 visual proof](https://gist.githubusercontent.com/cha1latte/bdffc47430091cbccda9266a85d5e74d/raw/issue-459-visual-proof.svg) Visual proof shows the before repro failing with 3 duplicate paragraph occurrences, and the after repro passing with the duplicate collapsed to 1 copy. ## Anything Else? Opened as draft for maintainer review. No manual hardware, provider, or UI verification is required for the core claim. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved merging of lorebook keeper updates: paragraph content is now normalized, trimmed, deduplicated, and rejoined with proper spacing to prevent duplicate paragraphs and produce cleaner, consolidated lorebook entries. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:09:23 +07:00
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#4640
No description provided.