[GH-ISSUE #2752] [Issue]: Sprite Generation Modal — in-flight generation not abortable on close, stale/lost state, partial saves (orphaned requests + wasted image cost) #1390

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

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

Originally assigned to: @SpicyMarinara on GitHub.

Summary

SpriteGenerationModal is rendered permanently mounted by both parent editors (open={spriteGenOpen}), and its lifecycle is not wired to the open/close transition. This yields a cluster of bugs: generation can't be cancelled, state leaks across opens, an avatar edit destroys unsaved work, and saves are non-atomic with silent overwrites.

Sub-bug 1: No abort on close; multi-batch cost amplification (#32)

  • How it breaks: The only AbortController lives inside postSpriteGenerationRequest (374) and is reachable only by its own 305s timeout — never stored in a ref, never aborted on close/unmount. The modal never unmounts (Modal.tsx nulls only its portal). For matched full-body mode, runMatchedFullBodyBatches keeps issuing NEW paid /sprites/generate-sheet requests after the user closed. Server withSpriteGenerationDeadline only rejects the race; the underlying provider call isn't aborted.
  • Repro: Start a matched full-body batch, close the modal mid-generation. Remaining batches still POST and bill.

Sub-bug 2: Stale step/result on reopen (#33)

  • How it breaks: The only effect that resets step/cells/generatedSheets is keyed on [entityId, defaultAvatarUrl, defaultAppearance] (695), not on open; the open-keyed effect (680) resets only config fields. Closing without Save retains step 2 + cells.
  • Repro: Generate sprites, close with X/Escape, reopen same character -> lands on the old step-2 preview (or step-1 spinner if a request resolved while hidden) instead of config.

Sub-bug 3: Avatar/appearance change wipes unsaved sprites (#34)

  • How it breaks: The reset effect (695-713) fires on any change to entityId/defaultAvatarUrl/defaultAppearance and unconditionally clears step/cells/generatedSheets. The header avatar tile is rendered outside the tab content and stays clickable while reviewing sprites; editing/regenerating the avatar changes avatarPreview (a plain string prop) and wipes the in-progress batch with no warning.
  • Repro: Generate sprites (step 2), click the header avatar to upload/regenerate -> all generated cells vanish, modal jumps to step 0.

Sub-bug 4: Partial save on first failure (#35)

  • How it breaks: handleSave (1275-1314) serially await api.post('/sprites/{id}', ...) per cell; the first rejection throws out of the loop, skipping onSpritesGenerated/onClose/reset. Earlier sprites persisted, later ones never attempted; generic error, no per-item status, re-clicking re-POSTs already-saved ones.
  • Repro: Select several sprites where one will fail (network blip / bad name). Some save, the rest silently don't; no indication which.

Sub-bug 5: Duplicate expression overwrite (#66)

  • How it breaks: Nothing dedupes expression labels among selected cells. The per-cell assignment (2102) offers the same options to every cell and the rename lets two cells share a label. Server (sprites.routes.ts:1254-1297) builds ${expression}.${ext} and writeFile with no collision handling -> the second write clobbers the first while the UI reports N saved.
  • Repro: Label two selected cells 'neutral', save. Only one file exists; toast says both saved.

Suggested Fix

  • Store the AbortController in a ref; add a Cancel button on the generating step; abort on close/unmount; check an aborted flag between matched-full-body batches.
  • Reset step/cells/generatedSheets/error/progress on an open-transition (or wrap onClose to call handleReset).
  • Gate the destructive reset on an actual entityId change (previous-id ref) or skip it while step===2/in-flight.
  • Use Promise.allSettled (or accumulate per-cell results), report 'Saved X, failed Y', mark already-saved cells, only onClose on full success.
  • Detect duplicate normalized expressions before saving and block/auto-suffix with an inline warning.

Verification checklist (all manual)

  • Manually verify closing the modal mid-generation aborts the request and stops further matched-full-body batches
  • Verify reopening the modal for the same character returns to the config step
  • Verify editing/regenerating the avatar during sprite review does not wipe unsaved sprites (or warns first)
  • Verify a mid-save failure reports per-item results and does not silently drop later sprites
  • Verify saving two same-named cells is blocked/disambiguated rather than silently overwriting
  • Run pnpm check

Affected files

  • packages/client/src/components/ui/SpriteGenerationModal.tsx
  • packages/client/src/components/characters/CharacterEditor.tsx
  • packages/client/src/components/personas/PersonaEditor.tsx
  • packages/server/src/routes/sprites.routes.ts

Audit provenance

Found by a multi-agent static audit of the TTS/voice + image-generation subsystems (Round 1 + round-2 gap sweep + completeness critic, each finding adversarially verified) against the merged staging tree. Severity: HIGH.

AI-drafted from a static read; validation/test-plan boxes intentionally left UNCHECKED for a human to verify before close.

Originally created by @kolacheee on GitHub (Jun 21, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2752 Originally assigned to: @SpicyMarinara on GitHub. ## Summary `SpriteGenerationModal` is rendered permanently mounted by both parent editors (`open={spriteGenOpen}`), and its lifecycle is not wired to the open/close transition. This yields a cluster of bugs: generation can't be cancelled, state leaks across opens, an avatar edit destroys unsaved work, and saves are non-atomic with silent overwrites. ## Sub-bug 1: No abort on close; multi-batch cost amplification (#32) - **How it breaks:** The only `AbortController` lives inside `postSpriteGenerationRequest` (374) and is reachable only by its own 305s timeout — never stored in a ref, never aborted on close/unmount. The modal never unmounts (Modal.tsx nulls only its portal). For matched full-body mode, `runMatchedFullBodyBatches` keeps issuing NEW paid `/sprites/generate-sheet` requests after the user closed. Server `withSpriteGenerationDeadline` only rejects the race; the underlying provider call isn't aborted. - **Repro:** Start a matched full-body batch, close the modal mid-generation. Remaining batches still POST and bill. ## Sub-bug 2: Stale step/result on reopen (#33) - **How it breaks:** The only effect that resets step/cells/generatedSheets is keyed on [entityId, defaultAvatarUrl, defaultAppearance] (695), not on `open`; the `open`-keyed effect (680) resets only config fields. Closing without Save retains step 2 + cells. - **Repro:** Generate sprites, close with X/Escape, reopen same character -> lands on the old step-2 preview (or step-1 spinner if a request resolved while hidden) instead of config. ## Sub-bug 3: Avatar/appearance change wipes unsaved sprites (#34) - **How it breaks:** The reset effect (695-713) fires on any change to entityId/defaultAvatarUrl/defaultAppearance and unconditionally clears step/cells/generatedSheets. The header avatar tile is rendered outside the tab content and stays clickable while reviewing sprites; editing/regenerating the avatar changes `avatarPreview` (a plain string prop) and wipes the in-progress batch with no warning. - **Repro:** Generate sprites (step 2), click the header avatar to upload/regenerate -> all generated cells vanish, modal jumps to step 0. ## Sub-bug 4: Partial save on first failure (#35) - **How it breaks:** `handleSave` (1275-1314) serially `await api.post('/sprites/{id}', ...)` per cell; the first rejection throws out of the loop, skipping `onSpritesGenerated`/`onClose`/reset. Earlier sprites persisted, later ones never attempted; generic error, no per-item status, re-clicking re-POSTs already-saved ones. - **Repro:** Select several sprites where one will fail (network blip / bad name). Some save, the rest silently don't; no indication which. ## Sub-bug 5: Duplicate expression overwrite (#66) - **How it breaks:** Nothing dedupes expression labels among selected cells. The per-cell assignment <select> (2102) offers the same options to every cell and the rename <input> lets two cells share a label. Server (sprites.routes.ts:1254-1297) builds `${expression}.${ext}` and `writeFile` with no collision handling -> the second write clobbers the first while the UI reports N saved. - **Repro:** Label two selected cells 'neutral', save. Only one file exists; toast says both saved. ## Suggested Fix - Store the AbortController in a ref; add a Cancel button on the generating step; abort on close/unmount; check an aborted flag between matched-full-body batches. - Reset step/cells/generatedSheets/error/progress on an `open`-transition (or wrap onClose to call handleReset). - Gate the destructive reset on an actual entityId change (previous-id ref) or skip it while step===2/in-flight. - Use `Promise.allSettled` (or accumulate per-cell results), report 'Saved X, failed Y', mark already-saved cells, only `onClose` on full success. - Detect duplicate normalized expressions before saving and block/auto-suffix with an inline warning. ## Verification checklist (all manual) - [ ] Manually verify closing the modal mid-generation aborts the request and stops further matched-full-body batches - [ ] Verify reopening the modal for the same character returns to the config step - [ ] Verify editing/regenerating the avatar during sprite review does not wipe unsaved sprites (or warns first) - [ ] Verify a mid-save failure reports per-item results and does not silently drop later sprites - [ ] Verify saving two same-named cells is blocked/disambiguated rather than silently overwriting - [ ] Run `pnpm check` --- ### Affected files - `packages/client/src/components/ui/SpriteGenerationModal.tsx` - `packages/client/src/components/characters/CharacterEditor.tsx` - `packages/client/src/components/personas/PersonaEditor.tsx` - `packages/server/src/routes/sprites.routes.ts` ### Audit provenance Found by a multi-agent static audit of the TTS/voice + image-generation subsystems (Round 1 + round-2 gap sweep + completeness critic, each finding adversarially verified) against the merged `staging` tree. Severity: **HIGH**. > AI-drafted from a static read; validation/test-plan boxes intentionally left UNCHECKED for a human to verify before close.
Author
Owner

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

Addressed on PR #2747. SpriteGenerationModal now owns an abortable generation run, cancels on close/unmount and via a visible Cancel button, passes the abort signal through prompt preview and generation requests, checks cancellation between matched full-body batches, resets generated preview state on fresh open, and no longer wipes generated sprites just because same-entity avatar/appearance props change. Saving now blocks duplicate/empty normalized labels and uses all-settled saves so partial failures report saved/failed counts and leave failed cells selected for retry. Validated with git diff --check for the touched file; full pnpm validation is deferred until the end of the issue sweep per maintainer request.

<!-- gh-comment-id:4763284809 --> @SpicyMarinara commented on GitHub (Jun 21, 2026): Addressed on PR #2747. SpriteGenerationModal now owns an abortable generation run, cancels on close/unmount and via a visible Cancel button, passes the abort signal through prompt preview and generation requests, checks cancellation between matched full-body batches, resets generated preview state on fresh open, and no longer wipes generated sprites just because same-entity avatar/appearance props change. Saving now blocks duplicate/empty normalized labels and uses all-settled saves so partial failures report saved/failed counts and leave failed cells selected for retry. Validated with git diff --check for the touched file; full pnpm validation is deferred until the end of the issue sweep per maintainer request.
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#1390
No description provided.