mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2329] [Issue]: NPC avatar files leak on re-upload and are never cleaned on chat delete #1155
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#1155
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 @Romuromylus on GitHub (Jun 5, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2329
Originally assigned to: @Romuromylus on GitHub.
Summary
Severity: Low — Disk leak. NPC avatar files leak in two ways:
update_npc_avatarwrites a new file on every regeneration without removing the prior one, anddelete_chat_with_messagesnever cleans a chat'savatars/npc/<chatId>-*files. The character-avatar path deliberately removes the old file, so this is an inconsistent omission.Expected behavior
Re-uploading an NPC avatar should remove the prior file for the same chat+name; deleting a chat should remove its NPC avatar files — mirroring
update_character_avatar_inner, which fetches the previous record and removes the old file after writing the new one.Actual behavior
src-tauri/src/commands/storage/avatars.rs:569-590(update_npc_avatar):persist_image_upload(media_uploads.rs:30-38) builds a timestamped filename and runs it throughunique_file_path(media_uploads.rs:363-383), which returns a non-colliding-Nsuffixed path when the target exists — so it never overwrites; every regen orphans the prior file. Contrastupdate_character_avatar_inner(avatars.rs:33/83), which removes the previous file.delete_chat_with_messages(chats.rs:1120-1166) cleans tracker snapshots, gallery, and message rows but never scans/removesavatars/npc/*for the deleted chat ids. NPC avatar paths live inline inmetadata.gameNpcs/gameState.presentCharacters, not as tracked top-level record fields, so there is no managed-file cleanup hook — all NPC avatars of a deleted game chat orphan permanently.Steps to reproduce
avatars/npcfiles orphan.Impact area
Environment
b0e5561dLogs, screenshots, or video
Static source audit; cited to file:line above.
Regression notes
Found via static audit of the refactor branch; not verified against main. Pure disk-space accumulation scaling with NPC-portrait churn, hence low.
Additional context
Suggested fix: in
update_npc_avatar, look up the prior NPC avatar path for the same chatId+name and remove it after the new write (mirrorremove_avatar_file_preserving_persona_snapshots). Indelete_chat_with_messages, best-effort scanavatars/npc/and remove files whose name starts with each deleted{chat_id}-prefix.Template check
Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked:
@Romuromylus commented on GitHub (Jun 6, 2026):
Fixed by #2402, merged into
refactor.