[PR #4790] [MERGED] fix: complete Persona avatar lifecycle safety #6500

Closed
opened 2026-10-23 04:11:00 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/4790
Author: @Xelvanis
Created: 8/9/2026
Status: ✅ Merged
Merged: 8/9/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/persona-avatar-lifecycle


📝 Commits (2)

  • 04b32f4 fix: complete persona avatar lifecycle safety
  • 3bce6d1 Merge branch 'staging' into fix/persona-avatar-lifecycle

📊 Changes

4 files changed (+127 additions, -72 deletions)

View changed files

📝 packages/server/src/routes/characters.routes.ts (+41 -38)
📝 packages/server/src/services/image/avatar-file-lifecycle.ts (+24 -9)
📝 packages/server/src/services/import/marinara.importer.ts (+16 -13)
📝 packages/server/src/services/mari-db/mari-images.service.ts (+46 -12)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #4789

Why this change

  • Persona avatar replacement and removal span both database references and local files. A failure between those operations can leave an unattached file or remove one that Persona history still needs.
  • Crop data is specific to the previous image's framing and must not survive when the Persona avatar changes.
  • The assignment, import, gallery, and Mari Images paths need to follow the same lifecycle guarantees introduced for card deletion in PR #4669.

What changed

  • Reuse one cleanup helper for avatar files that were written but could not be attached, covering direct uploads, gallery copies, native imports, and Mari Images assignment.
  • Serialize Mari Images Persona avatar assignment and clearing through the shared avatar lifecycle lock, and reset avatarCrop whenever a Persona avatar is replaced or cleared.
  • Clear Persona avatar references before deleting files, collect current and version-history paths, and unlink only files that have no remaining owner.
  • Preserve existing error behavior and the Mari command result shape, including filesDeleted for clear operations.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

  • pnpm build:shared passed.
  • A temporary collector-spy probe confirmed cleanup-disabled mutations skip unused avatar-path collection; the probe was removed afterward.
  • git diff --check origin/staging...HEAD passed.
  • After removing stale generated dependency directories and reinstalling from the lockfile, pnpm check passed locally. The earlier Fastify augmentation errors came from broken absolute symlinks retained from the worktree’s previous path; no source change was required.
  • A disposable headed Edge session rendered a seeded cropped Persona in the normal editor, then verified direct replacement changed the avatar path, retained the new file, and cleared the old crop.
  • Persona Gallery Set as avatar was clicked in the browser; its POST returned 200, the copied avatar file existed, and the reseeded prior crop was cleared.
  • Mari Images cleared the Persona avatar with file deletion enabled: filesDeleted was 0, current avatar/crop became null, two version-history rows retained the old path, and that history-owned file still existed.
  • The cleared Persona rendered the expected Add Avatar state on desktop and at 390×844. Browser console reported 0 errors and 0 warnings; displayed non-static local requests returned 200.
  • Valid uploads to a missing Persona and missing Character returned 404 without changing the avatar-directory filename set.
  • The owned browser/server runtime was removed after verification. The post-rebase four-file binary patch remained byte-identical to the browser-tested patch. No light-theme or container run was performed, and injected database-write failures were not re-run in the browser.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

This is a focused server-side lifecycle correction with no documentation, translation, or version-metadata changes.

UI evidence (if applicable)

No UI layout or copy changed. Disposable desktop/mobile evidence was captured locally in the Traycer browser-verification artifact.

Summary by CodeRabbit

  • Bug Fixes
    • Improved avatar upload reliability by removing incomplete files when saving or updating avatars fails.
    • Prevented orphaned avatar files during character and persona imports, gallery updates, and avatar replacements.
    • Avatar replacements now reset cropping settings to ensure the new image displays correctly.
    • Improved avatar deletion and replacement handling to keep stored files synchronized with records.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/4790 **Author:** [@Xelvanis](https://github.com/Xelvanis) **Created:** 8/9/2026 **Status:** ✅ Merged **Merged:** 8/9/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/persona-avatar-lifecycle` --- ### 📝 Commits (2) - [`04b32f4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/04b32f4249a6bc6e5b78b384a6a419b8be7a5447) fix: complete persona avatar lifecycle safety - [`3bce6d1`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3bce6d10f3eb1a6ea4bcb3554f68cbf3b5769fa4) Merge branch 'staging' into fix/persona-avatar-lifecycle ### 📊 Changes **4 files changed** (+127 additions, -72 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/routes/characters.routes.ts` (+41 -38) 📝 `packages/server/src/services/image/avatar-file-lifecycle.ts` (+24 -9) 📝 `packages/server/src/services/import/marinara.importer.ts` (+16 -13) 📝 `packages/server/src/services/mari-db/mari-images.service.ts` (+46 -12) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Closes #4789 ## Why this change - Persona avatar replacement and removal span both database references and local files. A failure between those operations can leave an unattached file or remove one that Persona history still needs. - Crop data is specific to the previous image's framing and must not survive when the Persona avatar changes. - The assignment, import, gallery, and Mari Images paths need to follow the same lifecycle guarantees introduced for card deletion in PR #4669. ## What changed - Reuse one cleanup helper for avatar files that were written but could not be attached, covering direct uploads, gallery copies, native imports, and Mari Images assignment. - Serialize Mari Images Persona avatar assignment and clearing through the shared avatar lifecycle lock, and reset `avatarCrop` whenever a Persona avatar is replaced or cleared. - Clear Persona avatar references before deleting files, collect current and version-history paths, and unlink only files that have no remaining owner. - Preserve existing error behavior and the Mari command result shape, including `filesDeleted` for clear operations. ## Validation - [x] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes - `pnpm build:shared` passed. - A temporary collector-spy probe confirmed cleanup-disabled mutations skip unused avatar-path collection; the probe was removed afterward. - `git diff --check origin/staging...HEAD` passed. - After removing stale generated dependency directories and reinstalling from the lockfile, `pnpm check` passed locally. The earlier Fastify augmentation errors came from broken absolute symlinks retained from the worktree’s previous path; no source change was required. - A disposable headed Edge session rendered a seeded cropped Persona in the normal editor, then verified direct replacement changed the avatar path, retained the new file, and cleared the old crop. - Persona Gallery **Set as avatar** was clicked in the browser; its POST returned 200, the copied avatar file existed, and the reseeded prior crop was cleared. - Mari Images cleared the Persona avatar with file deletion enabled: `filesDeleted` was `0`, current avatar/crop became null, two version-history rows retained the old path, and that history-owned file still existed. - The cleared Persona rendered the expected **Add Avatar** state on desktop and at 390×844. Browser console reported 0 errors and 0 warnings; displayed non-static local requests returned 200. - Valid uploads to a missing Persona and missing Character returned 404 without changing the avatar-directory filename set. - The owned browser/server runtime was removed after verification. The post-rebase four-file binary patch remained byte-identical to the browser-tested patch. No light-theme or container run was performed, and injected database-write failures were not re-run in the browser. ## Docs and release impact - [x] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) This is a focused server-side lifecycle correction with no documentation, translation, or version-metadata changes. ## UI evidence (if applicable) No UI layout or copy changed. Disposable desktop/mobile evidence was captured locally in the Traycer browser-verification artifact. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved avatar upload reliability by removing incomplete files when saving or updating avatars fails. * Prevented orphaned avatar files during character and persona imports, gallery updates, and avatar replacements. * Avatar replacements now reset cropping settings to ensure the new image displays correctly. * Improved avatar deletion and replacement handling to keep stored files synchronized with records. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:11:00 +07:00
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#6500
No description provided.