mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #3043] [Issue]: Deleting a character leaves its id orphaned inside every folder/group (no membership cleanup), inflating folder member counts #1611
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#1611
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/3043
Originally assigned to: @SpicyMarinara on GitHub.
What's wrong
When you delete a character, its id is never removed from the character folders/groups it belonged to. Group membership is stored as a plain JSON array of ids with no database foreign key, so the cascade that cleans up versions and gallery images can't reach it, and nothing in the delete path scrubs it manually. The deleted character stays listed as a member of every folder forever. The most visible symptom: in the Characters panel, a folder's member count and its "Delete Folder" confirmation count the phantom member, so the dialog says e.g. "Its 3 characters will stay in the library" when only 2 actually exist. The stale id also accumulates permanently in stored JSON and survives into backups/exports.
How to reproduce (try it yourself)
You'll see: the group's characterIds JSON still contains C's id, and the folder's member count / delete-folder dialog still says "3 characters" even though only A and B remain in the library.
Expected: C's id is removed from the folder on delete; the member count and dialog say "2 characters."
Where it is
packages/server/src/services/storage/characters.storage.ts:291-293—remove(id)only runsdb.delete(characters), no group scrub.packages/server/src/routes/characters.routes.ts:488-498— DELETE /:id removes the gallery dir and callsstorage.remove, no cleanup.packages/server/src/db/schema/characters.ts:92-101—characterGroups.characterIds = text("character_ids").notNull().default("[]"), a denormalized JSON array with no.references()/FK.packages/client/src/components/panels/CharactersPanel.tsx:402-417(parses memberIds with no existence filter) and:503-509(usesgroup.memberIds.lengthfor the count and the "Its N characters will stay in the library" message).What's happening
characterGroups.characterIdsis a denormalized JSON array string, so SQLiteonDeletecascade (and the file-backed store's row-FK-only cascade) structurally cannot edit it.storage.removedeletes only thecharactersrow, and there is no application-level cleanup step.updateGrouponly rewritescharacterIdswhen the client explicitly sends it, so the dangling id persists indefinitely. The actual member render list (CharactersPanel.tsx:841-842) filters against live characters, but the count and dialog read the raw parsed array, producing the inflated number.Suggested fix
Scrub the deleted id out of every character group inside
storage.remove(covers both the DELETE route and the import-rollback caller). Only rewrite groups that actually contained the id, and parse defensively so one malformed group row can't abort the delete:Regression notes:
updateGroupalways bumpsupdatedAt, andlistGroupssorts bydesc(updatedAt), so writing back EVERY group would silently reorder folders and dirty the file-backed store on every delete — theincludes(id)guard limits writes to affected folders only. Thetry/catchmirrors the server's existingtypeof === "string" ? JSON.parse(...) : []idiom (chats.routes.ts) so a single legacy/corrupt group value can't throw and abort deletion of an unrelated character. Empty folders are already valid, and chats store their own copied characterIds snapshot, so scrubbing the group preset doesn't touch any chat. Do NOT add id-existence validation to createGroup/updateGroup — that would reject valid out-of-order import/restore flows. The same orphan pattern exists for persona groups and is filed as a separate issue.Related: the same orphaned-membership pattern affects PERSONA folders/groups, filed as a sibling issue (
removePersonaneeds the same scrub).AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.
@SpicyMarinara commented on GitHub (Jun 29, 2026):
Claiming this for the current staging sweep in draft PR #3053 (branch
codex/issue-sweep-3033-3052).@SpicyMarinara commented on GitHub (Jun 29, 2026):
Fixed in PR #3053 on branch
codex/issue-sweep-3033-3052(commitbfb1bc76). Closing this issue as addressed; the PR remains open for staging review/merge.