[GH-ISSUE #2476] [Issue]: Managed-thumbnail cache is never pruned when backgrounds, lorebook images, or gallery items are deleted #1219

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

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

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Severity: Low — resource leak. The .managed-thumbnails cache (backgrounds, gallery, game, lorebook images) is never pruned when its source asset is deleted, replaced, or renamed, while the parallel avatar-thumbnail cache is cleaned. Disk usage grows monotonically with asset churn and is never reclaimed.

Expected behavior

Deleting/renaming/replacing a managed image should remove its cached thumbnails, mirroring the avatar path (remove_avatar_file → remove_avatar_thumbnail_files).

Actual behavior

The write path creates up to 4 cached PNGs per asset:

// src-tauri/src/commands/storage/managed_thumbnails.rs:144-156 (thumbnail_target_path)
data_dir/.managed-thumbnails/<kind>/<size>/<relative>.thumb.png   // kinds: background/gallery/game/lorebook, sizes [64,128,256,512]

But no delete path removes them. A repo-wide grep for .managed-thumbnails finds it only in managed_thumbnails.rs (write/read) plus FS-scope config and read-delivery wiring — there is no remove call from any delete path. Traced delete paths are source-file-only: delete_background (backgrounds.rs:153), remove_lorebook_image_file (lorebook_images.rs:29), gallery delete (entities.rs:2366 → remove_managed_record_file in media_uploads.rs:143-166). Contrast avatars, which are cleaned via remove_avatar_thumbnail_files (avatars.rs:171/278). rename_background also moves the source, stranding the old-name-keyed thumbnails.

Steps to reproduce

  1. Upload a background and open the picker so a thumbnail renders (creates .managed-thumbnails/background/<size>/<name>.thumb.png).
  2. Delete the background — the source file is removed but the .managed-thumbnails entries remain.
  3. Repeat across many backgrounds/lorebook images/gallery items; the cache dir grows unbounded.

Impact area

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

Environment

  • Branch or commit: refactor @ 1fae2c42
  • Run mode: Tauri desktop
  • OS + version: found via static source audit (not runtime-reproduced)
  • Node + pnpm versions: n/a (static audit)
  • Rust version, if relevant: n/a (static audit)
  • Remote Runtime URL configured? not relevant
  • Provider, model, or integration, if relevant: n/a

Logs, screenshots, or video

Static trace: managed_thumbnails.rs:144-156 (write), delete paths backgrounds.rs:153 / lorebook_images.rs:29 / entities.rs:2366 → media_uploads.rs:143-166; contrast avatars.rs:171/278.

Regression notes

Not a regression — the managed-thumbnail cache (and the avatar cache it mirrors) is a refactor-only Rust asset-layer surface with no main/web equivalent. Filing as a refactor bug (fix-pattern-already-in-repo inconsistency).

Additional context

The cache is regeneratable and bounded by the count of distinct assets ever thumbnailed, hence Low. Fix: add a remove_managed_thumbnail_files(state, kind, relative) helper mirroring remove_avatar_thumbnail_files (iterate MANAGED_THUMBNAIL_SIZES, resolve relative via the canonical kind root as managed_thumbnail_path does), and call it from delete_background, rename_background (old name), remove_lorebook_image_file, and remove_gallery_file.

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 6, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2476 Originally assigned to: @SpicyMarinara on GitHub. ## Summary **Severity: Low — resource leak.** The `.managed-thumbnails` cache (backgrounds, gallery, game, lorebook images) is never pruned when its source asset is deleted, replaced, or renamed, while the parallel avatar-thumbnail cache *is* cleaned. Disk usage grows monotonically with asset churn and is never reclaimed. ## Expected behavior Deleting/renaming/replacing a managed image should remove its cached thumbnails, mirroring the avatar path (`remove_avatar_file` → `remove_avatar_thumbnail_files`). ## Actual behavior The write path creates up to 4 cached PNGs per asset: ```rust // src-tauri/src/commands/storage/managed_thumbnails.rs:144-156 (thumbnail_target_path) data_dir/.managed-thumbnails/<kind>/<size>/<relative>.thumb.png // kinds: background/gallery/game/lorebook, sizes [64,128,256,512] ``` But no delete path removes them. A repo-wide grep for `.managed-thumbnails` finds it only in `managed_thumbnails.rs` (write/read) plus FS-scope config and read-delivery wiring — there is no remove call from any delete path. Traced delete paths are source-file-only: `delete_background` (`backgrounds.rs:153`), `remove_lorebook_image_file` (`lorebook_images.rs:29`), gallery delete (`entities.rs:2366` → `remove_managed_record_file` in `media_uploads.rs:143-166`). Contrast avatars, which *are* cleaned via `remove_avatar_thumbnail_files` (`avatars.rs:171/278`). `rename_background` also moves the source, stranding the old-name-keyed thumbnails. ## Steps to reproduce 1. Upload a background and open the picker so a thumbnail renders (creates `.managed-thumbnails/background/<size>/<name>.thumb.png`). 2. Delete the background — the source file is removed but the `.managed-thumbnails` entries remain. 3. Repeat across many backgrounds/lorebook images/gallery items; the cache dir grows unbounded. ## Impact area - [x] Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime ## Environment - Branch or commit: refactor @ 1fae2c42 - Run mode: Tauri desktop - OS + version: found via static source audit (not runtime-reproduced) - Node + pnpm versions: n/a (static audit) - Rust version, if relevant: n/a (static audit) - Remote Runtime URL configured? not relevant - Provider, model, or integration, if relevant: n/a ## Logs, screenshots, or video Static trace: `managed_thumbnails.rs:144-156` (write), delete paths `backgrounds.rs:153` / `lorebook_images.rs:29` / `entities.rs:2366` → `media_uploads.rs:143-166`; contrast `avatars.rs:171/278`. ## Regression notes Not a regression — the managed-thumbnail cache (and the avatar cache it mirrors) is a refactor-only Rust asset-layer surface with no main/web equivalent. Filing as a refactor `bug` (fix-pattern-already-in-repo inconsistency). ## Additional context The cache is regeneratable and bounded by the count of distinct assets ever thumbnailed, hence Low. Fix: add a `remove_managed_thumbnail_files(state, kind, relative)` helper mirroring `remove_avatar_thumbnail_files` (iterate `MANAGED_THUMBNAIL_SIZES`, resolve `relative` via the canonical kind root as `managed_thumbnail_path` does), and call it from `delete_background`, `rename_background` (old name), `remove_lorebook_image_file`, and `remove_gallery_file`. ## 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:29:13 +07:00
Author
Owner

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

Fixed on refactor in 038b7220.

Managed thumbnail cache files are pruned when backgrounds, lorebook images, gallery items, and game assets are deleted, renamed, or moved.

Verification: pnpm typecheck; pnpm build; pnpm check:architecture; cargo check --manifest-path src-tauri/Cargo.toml --workspace; focused Rust backup/profile tests; git diff --check; no .test.ts/.test.tsx files present.

<!-- gh-comment-id:4638719592 --> @SpicyMarinara commented on GitHub (Jun 6, 2026): Fixed on refactor in 038b7220. Managed thumbnail cache files are pruned when backgrounds, lorebook images, gallery items, and game assets are deleted, renamed, or moved. Verification: pnpm typecheck; pnpm build; pnpm check:architecture; cargo check --manifest-path src-tauri/Cargo.toml --workspace; focused Rust backup/profile tests; git diff --check; no .test.ts/.test.tsx files present.
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#1219
No description provided.