[GH-ISSUE #2473] [Issue]: duplicate_persona shares the original's avatar file; deleting one persona breaks the duplicate's avatar #1215

Closed
opened 2026-10-21 05:29:11 +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/2473

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Severity: Medium — data-loss. duplicate_persona clones the record verbatim without copying the managed avatar file, so the duplicate's avatarFilePath points at the original persona's file. Because personas now have active delete-time avatar cleanup, deleting the original (or editing its avatar) breaks the duplicate's image. The sibling duplicate_character copies the file correctly.

Expected behavior

Duplicating a persona should make a fresh on-disk copy of its managed avatar and rewrite the avatar fields on the copy, exactly like duplicate_character, so the two records do not share a file.

Actual behavior

// src-tauri/src/commands/storage/personas.rs:4-20 (duplicate_persona)
let mut record = get_required(state, "personas", id)?;
// ...only id/name/isActive/active mutated...
state.storage.create("personas", record)   // record still carries the ORIGINAL avatarFilePath/avatarFilename/avatar

By contrast duplicate_character (characters.rs:548-580) calls duplicate_managed_character_avatar → persist_image_file_copy and rewrites avatar/avatarPath/avatarFilePath/avatarFilename on the copy. Personas use the same managed-avatar scheme (avatars/personas) and carry MEDIA_CLEANUP = RemoveOwnedMedia, so deleting the original persona runs remove_avatar_file_preserving_persona_snapshots → remove_avatar_file, which unlinks the shared file by path. The persona-snapshot guard only matches message snapshots by personaId, so a duplicate persona record pointing at the same file is not protected — its avatar becomes a broken image. Editing/cropping one persona's avatar also mutates the file shared by the other.

Steps to reproduce

  1. Create a persona with a generated/uploaded avatar (managed file under avatars/personas).
  2. Duplicate it (storage_duplicate entity personas).
  3. Delete the original persona.
  4. The duplicate's avatar is now broken (its avatarFilePath pointed at the deleted file).

Impact area

  • Catalog resources
  • 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: personas.rs:4-20 (no avatar copy) vs characters.rs:548-580 (duplicate_managed_character_avatar); cleanup avatars.rs:170-199.

Regression notes

Not a regression — main shares avatar paths on duplicate for both personas and characters and never deletes the avatar file on persona delete (so main's duplicate+delete merely leaks the file, it doesn't break the image). The break is refactor-only: the refactor added delete-time avatar cleanup and hardened duplicate_character with a fresh-copy path, while leaving duplicate_persona cloning verbatim. Filing as a refactor bug (fix-pattern-already-in-repo inconsistency).

Additional context

Recoverable by re-uploading the avatar (broken reference, not destruction of unrelated data), hence Medium. Fix: generalize the DuplicateAvatar copy/rewrite pattern from duplicate_character to duplicate_persona — copy the managed file (managed_record_file_path on avatars/personas + persist_image_file_copy), rewrite avatar/avatarPath/avatarFilePath/avatarFilename, and null the managed metadata when the source file is missing.

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/2473 Originally assigned to: @SpicyMarinara on GitHub. ## Summary **Severity: Medium — data-loss.** `duplicate_persona` clones the record verbatim without copying the managed avatar file, so the duplicate's `avatarFilePath` points at the *original* persona's file. Because personas now have active delete-time avatar cleanup, deleting the original (or editing its avatar) breaks the duplicate's image. The sibling `duplicate_character` copies the file correctly. ## Expected behavior Duplicating a persona should make a fresh on-disk copy of its managed avatar and rewrite the avatar fields on the copy, exactly like `duplicate_character`, so the two records do not share a file. ## Actual behavior ```rust // src-tauri/src/commands/storage/personas.rs:4-20 (duplicate_persona) let mut record = get_required(state, "personas", id)?; // ...only id/name/isActive/active mutated... state.storage.create("personas", record) // record still carries the ORIGINAL avatarFilePath/avatarFilename/avatar ``` By contrast `duplicate_character` (`characters.rs:548-580`) calls `duplicate_managed_character_avatar` → `persist_image_file_copy` and rewrites `avatar`/`avatarPath`/`avatarFilePath`/`avatarFilename` on the copy. Personas use the same managed-avatar scheme (`avatars/personas`) and carry `MEDIA_CLEANUP = RemoveOwnedMedia`, so deleting the original persona runs `remove_avatar_file_preserving_persona_snapshots` → `remove_avatar_file`, which unlinks the shared file by path. The persona-snapshot guard only matches message snapshots by `personaId`, so a *duplicate persona record* pointing at the same file is not protected — its avatar becomes a broken image. Editing/cropping one persona's avatar also mutates the file shared by the other. ## Steps to reproduce 1. Create a persona with a generated/uploaded avatar (managed file under `avatars/personas`). 2. Duplicate it (`storage_duplicate` entity `personas`). 3. Delete the original persona. 4. The duplicate's avatar is now broken (its `avatarFilePath` pointed at the deleted file). ## Impact area - [x] Catalog resources - [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: `personas.rs:4-20` (no avatar copy) vs `characters.rs:548-580` (`duplicate_managed_character_avatar`); cleanup `avatars.rs:170-199`. ## Regression notes Not a regression — main shares avatar paths on duplicate for both personas and characters and never deletes the avatar file on persona delete (so main's duplicate+delete merely leaks the file, it doesn't break the image). The break is refactor-only: the refactor *added* delete-time avatar cleanup and hardened `duplicate_character` with a fresh-copy path, while leaving `duplicate_persona` cloning verbatim. Filing as a refactor `bug` (fix-pattern-already-in-repo inconsistency). ## Additional context Recoverable by re-uploading the avatar (broken reference, not destruction of unrelated data), hence Medium. Fix: generalize the `DuplicateAvatar` copy/rewrite pattern from `duplicate_character` to `duplicate_persona` — copy the managed file (`managed_record_file_path` on `avatars/personas` + `persist_image_file_copy`), rewrite `avatar`/`avatarPath`/`avatarFilePath`/`avatarFilename`, and null the managed metadata when the source file is missing. ## 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:11 +07:00
Author
Owner

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

Fixed on refactor in 038b7220.

duplicate_persona now copies managed persona avatar files and rewrites avatar metadata so the duplicate no longer shares the original avatar file.

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:4638720137 --> @SpicyMarinara commented on GitHub (Jun 6, 2026): Fixed on refactor in 038b7220. duplicate_persona now copies managed persona avatar files and rewrites avatar metadata so the duplicate no longer shares the original avatar file. 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#1215
No description provided.