mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #3048] [Issue]: Deleting a persona leaves its id orphaned inside every persona folder/group, overcounting members in the delete-folder dialog #1617
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#1617
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/3048
Originally assigned to: @SpicyMarinara on GitHub.
What's wrong
Deleting a persona never removes its id from the persona folders/groups it belonged to.
personaGroups.personaIdsis a plain JSON array string with no foreign key, so there's no cascade and the delete path does no manual cleanup — the deleted persona stays listed as a member forever. In the Personas panel the folder member badge and the "Delete Folder" confirmation are driven by the raw parsedgroup.memberIds.length, so after a delete the dialog overcounts (e.g. "Its 3 personas will stay in the library" when only 2 exist) while the expanded member list (which filters against live personas) shows 2 — a visible inconsistency. The dangling id also persists in stored JSON and survives into backups/exports and the mari-dbpersona_groups.personaIdsJSON sync.How to reproduce (try it yourself)
You'll see: the personaIds JSON still contains P3, and the badge/dialog say "3 personas" while the expanded member list shows only P1 and P2.
Expected: P3's id is removed on delete; the badge and dialog say "2 personas."
Where it is
packages/server/src/services/storage/characters.storage.ts:435-437—removePersona(id)only runsdb.delete(personas).packages/server/src/routes/characters.routes.ts:930-944— DELETE /personas/:id removes the gallery dir and callsstorage.removePersona, no group cleanup.packages/server/src/db/schema/characters.ts:103-111—personaGroups.personaIds = text("persona_ids").notNull().default("[]"), denormalized JSON array, no FK (contrast personaCardVersions.personaId cascade at :74-78).packages/client/src/components/panels/PersonasPanel.tsx:284-289(delete-folder dialog uses raw count) and:743-746(folder-header badge), inconsistent with:773-775(member list filters via personaMap).What's happening
personaGroups.personaIdsis denormalized JSON with no referential integrity, so no DB/file-store cascade reaches it and no application-level scrub runs.updatePersonaGrouponly rewritespersonaIdswhen the client sends it, so the dangling id persists indefinitely.Suggested fix
Scrub the deleted id out of every persona group inside
removePersona, so all callers benefit, mirroring the character-group fix. Parse defensively (rows storepersonaIdsas a JSON STRING, not an array) and only rewrite groups that actually contained the id:This reuses the existing
listPersonaGroups()reader andupdatePersonaGroup()writer (which already JSON.stringifies the array). Regression notes: theincludes(id)guard means only affected folders are rewritten, so untouched folders keep theirupdatedAtand ordering (listPersonaGroups/PersonasPanel order bydesc(updatedAt)) and the file-backed store isn't needlessly dirtied. Thetry/catchkeeps one malformed group from aborting the persona delete. Client consumers already tolerate dangling ids defensively, so this is strictly corrective. Persona versioning/images already cascade via FK and are untouched. The character-group equivalent is filed separately.Related: the same orphaned-membership pattern affects CHARACTER folders/groups, filed as a sibling issue (
removeneeds 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.