mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #4932] Mari: whole-lorebook delete/restore leaves an embedded character's character_book + pointer stale #2735
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#2735
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 (Aug 11, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/4932
Originally assigned to: @SpicyMarinara on GitHub.
Summary
When Professor Mari deletes a whole lorebook that is embedded in a character card (or restores such a delete) through her generic mutation path (
mari lorebooks delete <id>,mari db delete lorebooks <id>), the character's deriveddata.character_bookand itsextensions.importMetadata.embeddedLorebook.lorebookIdforward pointer are left stale. The character editor's Lorebook tab then shows phantom entries and an "Edit Embedded Lorebook" button pointing at a lorebook that no longer exists.This is the whole-lorebook counterpart of #4927 (which keeps the embedded copy in sync for entry add/update/delete + restore). It is a pre-existing gap — Mari's generic path never synced embedded character books at all before #4927 — and #4927 is deliberately scoped to entry-level edits, so it is being tracked separately here.
Why the #4927 sync hook can't cover it
#4927addedsyncAffectedCharacterBooks, which callssyncCharacterBookFromLorebook(db, lorebookId)after apply/restore. That helper is a rebuild-from-the-live-row function: it starts withgetById(lorebookId)and returns early if the row is gone. On a whole-lorebook delete, the row is already removed by the time the hook runs, so the rebuild no-ops — it can neither clear the character'scharacter_booknor drop the dangling pointer. The #4927lorebooksbranch is therefore intentionally narrowed to non-delete changes.What the HTTP route does (the parity target)
DELETE /lorebooks/:id(packages/server/src/routes/lorebooks.routes.ts) handles this deliberately: it resolves the embedding character before removal and then callsclearCharacterEmbeddedLorebook(db, characterId, lorebookId)to nullcharacter_bookand drop the pointer. The generic mari-db mutation path has no equivalent.Suggested approach
In
packages/server/src/services/mari-db/mari-db.service.tssyncAffectedCharacterBooks, handlelorebooksaction: "delete"changes:resolveEmbeddedCharacterId(db, id, change.before)(the pre-delete row is a validlorebookHint, and the character still carries the forward pointer at apply time), thenclearCharacterEmbeddedLorebook(db, characterId, id).restorePlan): the clear dropped the forward pointer, soresolveEmbeddedCharacterIdcan no longer find it — re-embed viaembedLorebookIntoCharacter(db, change.before.characterId, id)to restore bothcharacter_bookand the pointer. Direction can be inferred from whethergetById(id)currently returns the row.Edge cases to cover in the fix: multi-linked lorebooks (which character actually embeds it), and a
--cascadedelete vs. the empty-embedded-book case. Add anopen-issues.regression.tscase that deletes an embedded lorebook via Mari, asserts the character is cleared, then restores and asserts it is re-embedded.Acceptance
character_book+ embed pointer (no phantom entries, no dangling "Edit Embedded Lorebook").@kolacheee commented on GitHub (Aug 11, 2026):
i got this confused with the other one whoops this still needs fixed