[GH-ISSUE #3344] [Bug]: Native export double-counts a character's/persona's embedded lorebook (character_book + re-linked standalone) #1813

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

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

Summary

Native (.marinara.json) export of a character (or persona) whose lorebook is embedded — i.e. it has a data.character_book and a standalone linked copy (the "Edit Linked Lorebook" state you get after clicking Import Embedded Lorebook) — now includes that lorebook twice: once as character_book in the card data, and once as a bundled standalone. #3342 added the bundle via listByCharacter, which doesn't exclude the character's own embedded copy. On import this produces a duplicated, confusing state.

Expected behavior

The lorebook is represented once. A character's embedded lorebook is already carried by character_book, so the native export bundle should exclude the standalone that corresponds to it — the one whose id === data.extensions.importMetadata.embeddedLorebook.lorebookId.

Actual behavior

The export envelope contains both data.character_book and a lorebooks: [{ lorebook, entries, folders }] bundle for the same lorebook. On native import the imported character ends up with:

  • the character_book entries (shown in the Lorebook tab), plus
  • a freshly re-linked standalone lorebook (the bundle), plus
  • a stale importMetadata.embeddedLorebook.lorebookId pointing at the old (now non-existent) standalone id, plus
  • the Import Embedded Lorebook button still offered — clicking it creates a third copy.

It is not a runtime double-injection — character_book has no prompt-scan consumer server-side (only the standalone activates, via its character link) — so it's survivable, but it's a duplicated/confusing imported state that invites extra copies.

Steps to reproduce

  1. Import (or create) a character with an embedded lorebook, then click Import Embedded Lorebook so a standalone linked copy exists (Edit Linked Lorebook appears).
  2. Export the character in Native format.
  3. Inspect the .marinara.json: data.character_book and a top-level lorebooks bundle both contain the lorebook.
  4. Import the file into a fresh instance → the Lorebook tab shows the embedded entries and a separate assigned-lorebook row for the same content, plus an Import Embedded Lorebook button.

Environment

  • Marinara Engine version: 2.1.1 (staging, post-#3342 bb26008b9)
  • Install type: source
  • OS + version: N/A (server-side data-shape issue)
  • Browser or app shell: N/A

Logs, screenshots, or video

N/A (data-shape issue). Code refs: readAttachedLorebooksForCharacter / readAttachedLorebooksForPersona / readLorebookBundles (packages/server/src/routes/characters.routes.ts) call listByCharacter / listByPersona (packages/server/src/services/storage/lorebooks.storage.ts), neither of which excludes the embedded standalone; buildNativeCharacterEnvelope then serializes both data.character_book and the bundle.

Additional context

Introduced by #3342 (native lorebook export). Suggested fix: in readLorebookBundles (or the two callers), skip the lorebook whose id === the owner's importMetadata.embeddedLorebook.lorebookId, so an embedded lorebook is carried only once (as character_book). This also keeps the native export coherent with the Embed into card work in #3341 / #3343, which writes character_book + links a standalone and would hit the same double-count under #3342.

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @kolacheee on GitHub (Jul 7, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3344 ## Summary Native (`.marinara.json`) export of a character (or persona) whose lorebook is **embedded** — i.e. it has a `data.character_book` **and** a standalone linked copy (the "Edit Linked Lorebook" state you get after clicking *Import Embedded Lorebook*) — now includes that lorebook **twice**: once as `character_book` in the card data, and once as a bundled standalone. #3342 added the bundle via `listByCharacter`, which doesn't exclude the character's own embedded copy. On import this produces a duplicated, confusing state. ## Expected behavior The lorebook is represented once. A character's embedded lorebook is already carried by `character_book`, so the native export bundle should **exclude** the standalone that corresponds to it — the one whose id === `data.extensions.importMetadata.embeddedLorebook.lorebookId`. ## Actual behavior The export envelope contains both `data.character_book` **and** a `lorebooks: [{ lorebook, entries, folders }]` bundle for the same lorebook. On native import the imported character ends up with: - the `character_book` entries (shown in the Lorebook tab), **plus** - a freshly re-linked standalone lorebook (the bundle), **plus** - a stale `importMetadata.embeddedLorebook.lorebookId` pointing at the old (now non-existent) standalone id, **plus** - the *Import Embedded Lorebook* button still offered — clicking it creates a **third** copy. It is **not** a runtime double-injection — `character_book` has no prompt-scan consumer server-side (only the standalone activates, via its character link) — so it's survivable, but it's a duplicated/confusing imported state that invites extra copies. ## Steps to reproduce 1. Import (or create) a character with an embedded lorebook, then click **Import Embedded Lorebook** so a standalone linked copy exists (*Edit Linked Lorebook* appears). 2. Export the character in **Native** format. 3. Inspect the `.marinara.json`: `data.character_book` **and** a top-level `lorebooks` bundle both contain the lorebook. 4. Import the file into a fresh instance → the Lorebook tab shows the embedded entries **and** a separate assigned-lorebook row for the same content, plus an *Import Embedded Lorebook* button. ## Environment - Marinara Engine version: 2.1.1 (staging, post-#3342 `bb26008b9`) - Install type: source - OS + version: N/A (server-side data-shape issue) - Browser or app shell: N/A ## Logs, screenshots, or video N/A (data-shape issue). Code refs: `readAttachedLorebooksForCharacter` / `readAttachedLorebooksForPersona` / `readLorebookBundles` (`packages/server/src/routes/characters.routes.ts`) call `listByCharacter` / `listByPersona` (`packages/server/src/services/storage/lorebooks.storage.ts`), neither of which excludes the embedded standalone; `buildNativeCharacterEnvelope` then serializes both `data.character_book` and the bundle. ## Additional context Introduced by #3342 (native lorebook export). Suggested fix: in `readLorebookBundles` (or the two callers), skip the lorebook whose id === the owner's `importMetadata.embeddedLorebook.lorebookId`, so an embedded lorebook is carried only once (as `character_book`). This also keeps the native export coherent with the *Embed into card* work in #3341 / #3343, which writes `character_book` + links a standalone and would hit the same double-count under #3342. ## Template check - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:42:56 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@kolacheee commented on GitHub (Jul 7, 2026):

Superseded by #3345. On clarification: linked (assigned) lorebooks are not supposed to export at all — only the embedded character_book should travel with a card. So the correct fix is not "exclude the embedded standalone from the bundle" (this issue's suggestion, which keeps the linked bundle) but removing the linked-lorebook bundling from native export entirely (#3345). The embedded double-count described here is just one symptom of exporting linked lorebooks at all, so #3345's fix resolves it too. Closing in favor of #3345.

<!-- gh-comment-id:4908634684 --> @kolacheee commented on GitHub (Jul 7, 2026): Superseded by #3345. On clarification: linked (assigned) lorebooks are not supposed to export at all — only the embedded `character_book` should travel with a card. So the correct fix is not "exclude the embedded standalone from the bundle" (this issue's suggestion, which keeps the linked bundle) but removing the linked-lorebook bundling from native export entirely (#3345). The embedded double-count described here is just one symptom of exporting linked lorebooks at all, so #3345's fix resolves it too. Closing in favor of #3345.
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#1813
No description provided.