mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2971] [Issue]: Editing then reimporting a character-linked lorebook corrupts entry names and resets activation/timing fields #1546
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#1546
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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:
probability,sticky,cooldown,delay,ephemeral,group,groupWeight,selectiveLogic,preventRecursion/excludeRecursion/delayUntilRecursion,matchWholeWords,useRegex, andscanDepthback to their defaults.The cause is that the sync that mirrors the standalone lorebook back into the character's V2
data.character_bookonly writes a small subset of fields (and maps the entry description into the V2commentfield), while the reimporter reads the name fromcommentfirst and defaults every field the mirror omitted.How to reproduce (try it yourself)
extensions.importMetadata.embeddedLorebook.lorebookId).probability= 25,sticky= 3,selectiveLogic= "not",preventRecursion= false,matchWholeWords= true. Saving routes throughPATCH /lorebooks/:id/entries/:entryId, which callssyncCharacterBookFromLorebook.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/matchWholeWordsare back tonull/"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 intoname; line 64 writescomment: asString(entry.description)(description into the V2 title field) and emits nodescriptionfield; 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 asnonEmptyString(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— readsdescriptionfromentry.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.packages/server/src/routes/characters.routes.ts:673-710(reimport readscharData.character_book);packages/server/src/routes/lorebooks.routes.ts:568(edit triggerssyncCharacterBookFromLorebook).What's happening
toCharacterBookEntryreturns aCharacterBookEntrycarrying only a subset of the standalone entry's fields, with the entry description placed incomment.importSTLorebookthen reads the name fromcommentfirst and derives a fullCreateLorebookEntryInput, defaulting every absent field. Because reimport re-sources from the already-overwrittencharacter_book(not a pristine card), the mirror's losses become permanent on the next reimport.Suggested fix
Make
toCharacterBookEntrya non-lossy mirror of exactly whatimportSTLorebookreads back:comment(the ST/V2 title field the importer reads back as the name — this also matches the convention inst-character.importer.ts'snormalizeCharacterBook, which setscommentto the entry title), and add a top-leveldescriptionfield carryingentry.description.selectiveLogic,probability(whatever fieldresolveProbabilityreads),scanDepth,sticky,cooldown,delay,ephemeral,group,groupWeight,matchWholeWords,useRegex,preventRecursion,excludeRecursion,delayUntilRecursion, and the vectorization flag.CharacterBookEntryhas 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.
@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.