[GH-ISSUE #2971] [Issue]: Editing then reimporting a character-linked lorebook corrupts entry names and resets activation/timing fields #1546

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/2971

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong

Editing a character-linked (embedded) lorebook via "Edit Linked Lorebook" and then clicking "Reimport Embedded Lorebook" is a lossy round-trip that corrupts entries. Two distinct losses, same root cause:

  1. Names get overwritten with descriptions. If an entry has a non-empty description, after edit→reimport its name becomes the old description text and its description is reset to empty.
  2. Activation/timing/grouping settings reset to defaults. The same round-trip silently wipes probability, sticky, cooldown, delay, ephemeral, group, groupWeight, selectiveLogic, preventRecursion/excludeRecursion/delayUntilRecursion, matchWholeWords, useRegex, and scanDepth back to their defaults.

The cause is that the sync that mirrors the standalone lorebook back into the character's V2 data.character_book only writes a small subset of fields (and maps the entry description into the V2 comment field), while the reimporter reads the name from comment first and defaults every field the mirror omitted.

How to reproduce (try it yourself)

  1. Import a character card with an embedded lorebook (creates a standalone lorebook linked via extensions.importMetadata.embeddedLorebook.lorebookId).
  2. Open "Edit Linked Lorebook" and edit an entry: set name = "Red Dragon", description = "A summary of the red dragon", probability = 25, sticky = 3, selectiveLogic = "not", preventRecursion = false, matchWholeWords = true. Saving routes through PATCH /lorebooks/:id/entries/:entryId, which calls syncCharacterBookFromLorebook.
  3. Click "Reimport Embedded Lorebook" (POST /api/characters/:id/embedded-lorebook/import).

You'll see: the re-imported entry's name is now "A summary of the red dragon", its description is empty, and probability/sticky/selectiveLogic/preventRecursion/matchWholeWords are back to null/"and"/true/false.
Expected: name stays "Red Dragon", description stays "A summary of the red dragon", and all configured fields survive the edit→reimport round-trip.

Where it is

  • packages/server/src/services/lorebook/character-book-sync.ts:49-72 (toCharacterBookEntry) — the lossy mirror. Line 61 writes the entry name only into name; line 64 writes comment: asString(entry.description) (description into the V2 title field) and emits no description field; and it omits probability/sticky/cooldown/delay/ephemeral/group/groupWeight/selectiveLogic/scanDepth/matchWholeWords/useRegex/preventRecursion/excludeRecursion/delayUntilRecursion entirely.
  • packages/server/src/services/import/st-lorebook.importer.ts:421 — resolves the name as nonEmptyString(entry.comment, entry.name) (comment first), so the synced description wins as the name.
  • packages/server/src/services/import/st-lorebook.importer.ts:445-483 — reads description from entry.description (undefined in the synced book → empty) and defaults every omitted field: resolveSelectiveLogic(undefined)→"and", resolveProbability→null, asNullableNumber(undefined)→null, matchWholeWords/useRegex→false, preventRecursion→true, etc.
  • Reachability: packages/server/src/routes/characters.routes.ts:673-710 (reimport reads charData.character_book); packages/server/src/routes/lorebooks.routes.ts:568 (edit triggers syncCharacterBookFromLorebook).

What's happening

toCharacterBookEntry returns a CharacterBookEntry carrying only a subset of the standalone entry's fields, with the entry description placed in comment. importSTLorebook then reads the name from comment first and derives a full CreateLorebookEntryInput, defaulting every absent field. Because reimport re-sources from the already-overwritten character_book (not a pristine card), the mirror's losses become permanent on the next reimport.

Suggested fix

Make toCharacterBookEntry a non-lossy mirror of exactly what importSTLorebook reads back:

  • Put the entry name into comment (the ST/V2 title field the importer reads back as the name — this also matches the convention in st-character.importer.ts's normalizeCharacterBook, which sets comment to the entry title), and add a top-level description field carrying entry.description.
  • Add the remaining fields the importer reads as top-level passthrough keys: selectiveLogic, probability (whatever field resolveProbability reads), scanDepth, sticky, cooldown, delay, ephemeral, group, groupWeight, matchWholeWords, useRegex, preventRecursion, excludeRecursion, delayUntilRecursion, and the vectorization flag.

CharacterBookEntry has an index signature ([key: string]: unknown), so these extra fields typecheck without changing the type. Round-trip then preserves name, description, and all activation/timing/grouping settings.


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/2971 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** Editing a character-linked (embedded) lorebook via "Edit Linked Lorebook" and then clicking "Reimport Embedded Lorebook" is a lossy round-trip that corrupts entries. Two distinct losses, same root cause: 1. **Names get overwritten with descriptions.** If an entry has a non-empty description, after edit→reimport its **name** becomes the old description text and its **description** is reset to empty. 2. **Activation/timing/grouping settings reset to defaults.** The same round-trip silently wipes `probability`, `sticky`, `cooldown`, `delay`, `ephemeral`, `group`, `groupWeight`, `selectiveLogic`, `preventRecursion`/`excludeRecursion`/`delayUntilRecursion`, `matchWholeWords`, `useRegex`, and `scanDepth` back to their defaults. The cause is that the sync that mirrors the standalone lorebook back into the character's V2 `data.character_book` only writes a small subset of fields (and maps the entry **description** into the V2 `comment` field), while the reimporter reads the name from `comment` first and defaults every field the mirror omitted. **How to reproduce (try it yourself)** 1. Import a character card with an embedded lorebook (creates a standalone lorebook linked via `extensions.importMetadata.embeddedLorebook.lorebookId`). 2. Open "Edit Linked Lorebook" and edit an entry: set name = "Red Dragon", description = "A summary of the red dragon", `probability` = 25, `sticky` = 3, `selectiveLogic` = "not", `preventRecursion` = false, `matchWholeWords` = true. Saving routes through `PATCH /lorebooks/:id/entries/:entryId`, which calls `syncCharacterBookFromLorebook`. 3. Click "Reimport Embedded Lorebook" (`POST /api/characters/:id/embedded-lorebook/import`). **You'll see:** the re-imported entry's name is now "A summary of the red dragon", its description is empty, and `probability`/`sticky`/`selectiveLogic`/`preventRecursion`/`matchWholeWords` are back to `null`/`"and"`/`true`/`false`. **Expected:** name stays "Red Dragon", description stays "A summary of the red dragon", and all configured fields survive the edit→reimport round-trip. **Where it is** - `packages/server/src/services/lorebook/character-book-sync.ts:49-72` (`toCharacterBookEntry`) — the lossy mirror. Line 61 writes the entry name only into `name`; line 64 writes `comment: asString(entry.description)` (description into the V2 title field) and emits **no** `description` field; and it omits probability/sticky/cooldown/delay/ephemeral/group/groupWeight/selectiveLogic/scanDepth/matchWholeWords/useRegex/preventRecursion/excludeRecursion/delayUntilRecursion entirely. - `packages/server/src/services/import/st-lorebook.importer.ts:421` — resolves the name as `nonEmptyString(entry.comment, entry.name)` (**comment first**), so the synced description wins as the name. - `packages/server/src/services/import/st-lorebook.importer.ts:445-483` — reads `description` from `entry.description` (undefined in the synced book → empty) and defaults every omitted field: `resolveSelectiveLogic(undefined)`→"and", `resolveProbability`→null, `asNullableNumber(undefined)`→null, `matchWholeWords`/`useRegex`→false, `preventRecursion`→true, etc. - Reachability: `packages/server/src/routes/characters.routes.ts:673-710` (reimport reads `charData.character_book`); `packages/server/src/routes/lorebooks.routes.ts:568` (edit triggers `syncCharacterBookFromLorebook`). **What's happening** `toCharacterBookEntry` returns a `CharacterBookEntry` carrying only a subset of the standalone entry's fields, with the entry description placed in `comment`. `importSTLorebook` then reads the name from `comment` first and derives a full `CreateLorebookEntryInput`, defaulting every absent field. Because reimport re-sources from the already-overwritten `character_book` (not a pristine card), the mirror's losses become permanent on the next reimport. **Suggested fix** Make `toCharacterBookEntry` a **non-lossy mirror** of exactly what `importSTLorebook` reads back: - Put the entry **name** into `comment` (the ST/V2 title field the importer reads back as the name — this also matches the convention in `st-character.importer.ts`'s `normalizeCharacterBook`, which sets `comment` to the entry title), and add a top-level `description` field carrying `entry.description`. - Add the remaining fields the importer reads as top-level passthrough keys: `selectiveLogic`, `probability` (whatever field `resolveProbability` reads), `scanDepth`, `sticky`, `cooldown`, `delay`, `ephemeral`, `group`, `groupWeight`, `matchWholeWords`, `useRegex`, `preventRecursion`, `excludeRecursion`, `delayUntilRecursion`, and the vectorization flag. `CharacterBookEntry` has an index signature (`[key: string]: unknown`), so these extra fields typecheck without changing the type. Round-trip then preserves name, description, and all activation/timing/grouping settings. --- *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: character-linked lorebook sync now mirrors entry name/comment/description without turning descriptions into names, and it preserves supported entry settings for reimport. Validated with pnpm check and pnpm regression:prompt.

<!-- gh-comment-id:4831160222 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Fixed in the v2.0.7 branch: character-linked lorebook sync now mirrors entry name/comment/description without turning descriptions into names, and it preserves supported entry settings for reimport. 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#1546
No description provided.