[GH-ISSUE #8112] [Issue]: Avatar storage cleanup deletes frozen chat identity images #7566

Closed
opened 2026-10-24 04:04:19 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @SpicyMarinara on GitHub (Oct 22, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/8112

Originally assigned to: @SpicyMarinara on GitHub.

Summary

The existing avatar storage cleaner treats a local image as abandoned even when a saved user message still displays it through extra.personaSnapshot.avatarUrl. Reproduced against the cleanup code currently on staging (7217a4b550fbc37230debf87c247eaacf4ea4baa) using an isolated file database and one valid PNG.

Expected behavior

A frozen chat identity keeps its avatar image available after the current persona changes or is removed. Cleanup must also account for historical swipe metadata and recoverable message-trash snapshots before unlinking files.

Actual behavior

The reference collector in packages/server/src/services/image/avatar-file-lifecycle.ts checks characters, character versions, personas, persona versions and groups. It does not read frozen message identities. The read-only scan reports the referenced PNG as abandoned, and cleanup deletes it.

The isolated reproducer returned:

{"legacyGcBugReproduced":true,"retainedMessageSnapshot":true,"scan":{"files":1,"bytes":68},"deletion":{"files":1,"bytes":68},"avatarFilePreserved":false}

Reproduction

  1. Keep a user message with extra.personaSnapshot.avatarUrl pointing to a local avatar, without a current card/version owning that file (for example after replacing an unversioned persona avatar).
  2. Let the avatar age past the cleaner's grace period.
  3. Scan/remove abandoned avatar files from storage optimization.
  4. The snapshot remains, but its avatar file is gone.

Complete isolated reproducer: download the .mts file and run it from the repository with pnpm --filter @marinara-engine/server exec tsx /path/to/marinara-frozen-avatar-gc-audit.mts. It creates and removes its own temporary database and files; the clock advances only inside the test input.

Source trace: generate.routes.ts stores resolvedUserIdentity.avatarPath in a user message snapshot; ConversationMessage.tsx reads that snapshot to keep old identities stable. message-trash.storage.ts keeps the message and swipe rows for restore.

Fix boundaries

  • Verify current message, historical swipe and recoverable trash references before collection.
  • Preserve lazy storage behavior; routine avatar updates should not eagerly load every chat's message/shard contents.
  • Validate concurrent identity writes and cleanup, and preserve committed references if a cleanup-only read fails.

This is an existing garbage-collection follow-up, separate from the persona avatar removal UI in #8097. That UI now deliberately clears only the current card reference and retains files, with a regression proving frozen chat avatars continue to return HTTP 200.

Ownership: @SpicyMarinara / Codex triaged this with a source trace and runnable proof. No implementation branch has been started for this broader cleanup work.

Originally created by @SpicyMarinara on GitHub (Oct 22, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/8112 Originally assigned to: @SpicyMarinara on GitHub. ## Summary The existing avatar storage cleaner treats a local image as abandoned even when a saved user message still displays it through `extra.personaSnapshot.avatarUrl`. Reproduced against the cleanup code currently on staging (`7217a4b550fbc37230debf87c247eaacf4ea4baa`) using an isolated file database and one valid PNG. ## Expected behavior A frozen chat identity keeps its avatar image available after the current persona changes or is removed. Cleanup must also account for historical swipe metadata and recoverable message-trash snapshots before unlinking files. ## Actual behavior The reference collector in `packages/server/src/services/image/avatar-file-lifecycle.ts` checks characters, character versions, personas, persona versions and groups. It does not read frozen message identities. The read-only scan reports the referenced PNG as abandoned, and cleanup deletes it. The isolated reproducer returned: ```json {"legacyGcBugReproduced":true,"retainedMessageSnapshot":true,"scan":{"files":1,"bytes":68},"deletion":{"files":1,"bytes":68},"avatarFilePreserved":false} ``` ## Reproduction 1. Keep a user message with `extra.personaSnapshot.avatarUrl` pointing to a local avatar, without a current card/version owning that file (for example after replacing an unversioned persona avatar). 2. Let the avatar age past the cleaner's grace period. 3. Scan/remove abandoned avatar files from storage optimization. 4. The snapshot remains, but its avatar file is gone. [Complete isolated reproducer](https://gist.github.com/SpicyMarinara/35688cc020ca827fb4ecd6bf0b889661): download the `.mts` file and run it from the repository with `pnpm --filter @marinara-engine/server exec tsx /path/to/marinara-frozen-avatar-gc-audit.mts`. It creates and removes its own temporary database and files; the clock advances only inside the test input. Source trace: `generate.routes.ts` stores `resolvedUserIdentity.avatarPath` in a user message snapshot; `ConversationMessage.tsx` reads that snapshot to keep old identities stable. `message-trash.storage.ts` keeps the message and swipe rows for restore. ## Fix boundaries - Verify current message, historical swipe and recoverable trash references before collection. - Preserve lazy storage behavior; routine avatar updates should not eagerly load every chat's message/shard contents. - Validate concurrent identity writes and cleanup, and preserve committed references if a cleanup-only read fails. This is an existing garbage-collection follow-up, separate from the persona avatar removal UI in #8097. That UI now deliberately clears only the current card reference and retains files, with a regression proving frozen chat avatars continue to return HTTP 200. Ownership: @SpicyMarinara / Codex triaged this with a source trace and runnable proof. No implementation branch has been started for this broader cleanup work.
bsakaguchi 2026-10-24 04:04:19 +07:00
Author
Owner

@SpicyMarinara commented on GitHub (Oct 23, 2026):

Ownership: @SpicyMarinara / Codex is implementing this in the isolated fix/frozen-avatar-gc branch. I am checking frozen current messages, historical swipes and recoverable trash without forcing lazy chat storage fully into memory, including cleanup-read failures and concurrent writes.

<!-- gh-comment-id:6354431172 --> @SpicyMarinara commented on GitHub (Oct 23, 2026): Ownership: @SpicyMarinara / Codex is implementing this in the isolated `fix/frozen-avatar-gc` branch. I am checking frozen current messages, historical swipes and recoverable trash without forcing lazy chat storage fully into memory, including cleanup-read failures and concurrent writes.
Author
Owner

@SpicyMarinara commented on GitHub (Oct 23, 2026):

Fixed on staging by #8130 (merge 5d64e0f993). The reviewed head passed all eight required checks, all ten platform jobs, the full Node regression suite, local CodeRabbit, and Dottore Review with no defects. Frozen identities in messages, historical swipes and restorable trash now protect their avatar files; cold scans release the write gate and fail closed on concurrent history changes. Images already deleted by earlier cleanup require restoration from a backup. The post-merge container and regression workflows are running; their results are separate from the passed PR checks.

<!-- gh-comment-id:6356315254 --> @SpicyMarinara commented on GitHub (Oct 23, 2026): Fixed on staging by #8130 (merge 5d64e0f993250189acacfbaf1e270efd57bb40e5). The reviewed head passed all eight required checks, all ten platform jobs, the full Node regression suite, local CodeRabbit, and Dottore Review with no defects. Frozen identities in messages, historical swipes and restorable trash now protect their avatar files; cold scans release the write gate and fail closed on concurrent history changes. Images already deleted by earlier cleanup require restoration from a backup. The post-merge container and regression workflows are running; their results are separate from the passed PR checks.
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#7566
No description provided.