[GH-ISSUE #2328] [Issue]: Character/persona sprite directories are never deleted on entity delete (disk leak) #1156

Closed
opened 2026-10-21 05:28:04 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @Romuromylus on GitHub (Jun 5, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2328

Originally assigned to: @Romuromylus on GitHub.

Summary

Severity: Low — Disk leak. Character and persona sprite directories (<data_dir>/sprites/<characterId>, <data_dir>/sprites/personas/<personaId>) are never deleted when the owning character/persona is deleted. remove_owned_media has no sprites branch and there is no startup orphan-prune, so a deleted entity's whole sprite pack (up to ~28 PNGs) leaks permanently with no UI to reach it.

Expected behavior

Deleting a character or persona should remove its sprite directory, mirroring how avatar/gallery/lorebook-image files are cleaned on delete.

Actual behavior

src-tauri/src/commands/storage/commands/entities.rs:1931-1942:

fn remove_owned_media(state: &AppState, entity: &str, record: &Value) {
    match entity {
        "characters" => avatars::remove_avatar_file(state, entity, record),
        "character-versions" => characters::remove_character_version_avatar_file(state, record),
        "personas" => avatars::remove_avatar_file_preserving_persona_snapshots(state, entity, record),
        "lorebooks" => lorebook_images::remove_lorebook_image_file(state, record),
        "gallery" | "character-gallery" => remove_gallery_file(state, record),
        _ => {}
    }
}  // no sprite-dir removal

The DeleteCleanup enum (contracts.rs:17-27) has no sprite variant; CHARACTER_CLEANUP = RemoveOwnedMedia + DeleteCharacterGallery, personas use RemoveOwnedMedia only. Sprite files are written outside the DB by upload_sprite/upload_sprites (sprites.rs:346,371) into sprites_dir/persona_sprites_dir. delete_sprite only removes a single expression (per-expression command), not the dir on entity delete. Even the admin bulk-expunge misses them: clear_collections only clears the legacy sprites DB collection, and clear_runtime_media (admin.rs:127-141) remove_dir_alls avatars/fonts/knowledge-sources/game_assets/backgrounds but NOT sprites.

Steps to reproduce

  1. Generate or upload sprites for a character or persona.
  2. Delete that character/persona from the catalog.
  3. sprites/<id> (or sprites/personas/<id>) and all its PNGs remain on disk forever.

Impact area

  • Catalog resources
  • Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime

Environment

  • Branch or commit: refactor @ b0e5561d
  • Run mode: Tauri desktop (also server mode)
  • OS + version: not relevant (static source audit)
  • Node + pnpm versions: not relevant
  • Rust version, if relevant: not relevant
  • Remote Runtime URL configured? not relevant (applies to both)
  • Provider, model, or integration, if relevant: sprites feature

Logs, 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. Bounded local disk waste, no correctness/data-loss/security impact, hence low.

Additional context

Suggested fix: add sprite-dir cleanup on character and persona delete — a DeleteCleanup::RemoveOwnedSprites variant wired into CHARACTER_CLEANUP and the persona contract, or extend remove_owned_media to best-effort fs::remove_dir_all the owner's sprite dir (using sprites_dir/persona_sprites_dir, logging on error like avatar cleanup). The persona-expunge admin scope should likewise gain sprites cleanup.

Template check

Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @Romuromylus on GitHub (Jun 5, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2328 Originally assigned to: @Romuromylus on GitHub. ## Summary **Severity: Low — Disk leak.** Character and persona sprite directories (`<data_dir>/sprites/<characterId>`, `<data_dir>/sprites/personas/<personaId>`) are never deleted when the owning character/persona is deleted. `remove_owned_media` has no sprites branch and there is no startup orphan-prune, so a deleted entity's whole sprite pack (up to ~28 PNGs) leaks permanently with no UI to reach it. ## Expected behavior Deleting a character or persona should remove its sprite directory, mirroring how avatar/gallery/lorebook-image files are cleaned on delete. ## Actual behavior `src-tauri/src/commands/storage/commands/entities.rs:1931-1942`: ```rust fn remove_owned_media(state: &AppState, entity: &str, record: &Value) { match entity { "characters" => avatars::remove_avatar_file(state, entity, record), "character-versions" => characters::remove_character_version_avatar_file(state, record), "personas" => avatars::remove_avatar_file_preserving_persona_snapshots(state, entity, record), "lorebooks" => lorebook_images::remove_lorebook_image_file(state, record), "gallery" | "character-gallery" => remove_gallery_file(state, record), _ => {} } } // no sprite-dir removal ``` The `DeleteCleanup` enum (`contracts.rs:17-27`) has no sprite variant; `CHARACTER_CLEANUP` = RemoveOwnedMedia + DeleteCharacterGallery, personas use RemoveOwnedMedia only. Sprite files are written outside the DB by `upload_sprite`/`upload_sprites` (`sprites.rs:346,371`) into `sprites_dir`/`persona_sprites_dir`. `delete_sprite` only removes a single expression (per-expression command), not the dir on entity delete. Even the admin bulk-expunge misses them: `clear_collections` only clears the legacy `sprites` DB collection, and `clear_runtime_media` (`admin.rs:127-141`) `remove_dir_all`s avatars/fonts/knowledge-sources/game_assets/backgrounds but NOT `sprites`. ## Steps to reproduce 1. Generate or upload sprites for a character or persona. 2. Delete that character/persona from the catalog. 3. `sprites/<id>` (or `sprites/personas/<id>`) and all its PNGs remain on disk forever. ## Impact area - [x] Catalog resources - [x] Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime ## Environment - Branch or commit: refactor @ b0e5561d - Run mode: Tauri desktop (also server mode) - OS + version: not relevant (static source audit) - Node + pnpm versions: not relevant - Rust version, if relevant: not relevant - Remote Runtime URL configured? not relevant (applies to both) - Provider, model, or integration, if relevant: sprites feature ## Logs, 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. Bounded local disk waste, no correctness/data-loss/security impact, hence low. ## Additional context Suggested fix: add sprite-dir cleanup on character and persona delete — a `DeleteCleanup::RemoveOwnedSprites` variant wired into `CHARACTER_CLEANUP` and the persona contract, or extend `remove_owned_media` to best-effort `fs::remove_dir_all` the owner's sprite dir (using `sprites_dir`/`persona_sprites_dir`, logging on error like avatar cleanup). The persona-expunge admin scope should likewise gain sprites cleanup. ## Template check Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:28:04 +07:00
Author
Owner

@Romuromylus commented on GitHub (Jun 6, 2026):

Fixed by #2378, merged into refactor (squash fa79513b).

<!-- gh-comment-id:4637085200 --> @Romuromylus commented on GitHub (Jun 6, 2026): Fixed by #2378, merged into `refactor` (squash fa79513b).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#1156
No description provided.