mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #7623] [MERGED] fix(avatars): Cancel stops avatar generation on the server, and 2D avatars have no background #7842
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#7842
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7623
Author: @SpicyMarinara
Created: 10/14/2026
Status: ✅ Merged
Merged: 10/14/2026
Merged by: @SpicyMarinara
Base:
staging← Head:fix/pngtuber-cancel-and-clean-backgrounds📝 Commits (6)
9137e5frefactor(sprites): move the sprite background cleanup into its servicecd987fbfix(avatars): Cancel stops generation on the server, and 2D avatars have no background11194d4docs(avatars): describe Cancel and avatars without backgroundse01bb13fix(avatars): a late Cancel never stops the next job, and cut-outs need an owner6c53e1dMerge branch 'staging' into fix/pngtuber-cancel-and-clean-backgroundsf1c9515fix(avatars): blink pictures keep the cut-out's own edge, and fallback cut-outs are redone📊 Changes
20 files changed (+1732 additions, -295 deletions)
View changed files
📝
docs/agents/avatars.md(+7 -4)📝
e2e/avatar-2d.e2e.ts(+5 -0)➕
e2e/avatar-generation.e2e.ts(+249 -0)📝
e2e/avatar-setup.e2e.ts(+7 -0)📝
packages/client/src/features/avatars/generation/use-avatar-generation.ts(+50 -14)📝
packages/client/src/features/avatars/stage/avatar-stage-logic.ts(+14 -2)📝
packages/server/src/routes/avatar-generation.routes.ts(+19 -3)📝
packages/server/src/routes/avatar-models.routes.ts(+28 -0)📝
packages/server/src/routes/sprites.routes.ts(+5 -199)➕
packages/server/src/services/avatars/cutouts.ts(+187 -0)📝
packages/server/src/services/avatars/formats/pngtuber.ts(+29 -17)📝
packages/server/src/services/avatars/generation/generation-context.ts(+112 -24)📝
packages/server/src/services/avatars/generation/mesh-rig.ts(+14 -8)📝
packages/server/src/services/avatars/generation/pngtuber-variants.ts(+41 -13)📝
packages/server/src/services/image/sprite-background.service.ts(+218 -4)📝
scripts/regressions/avatar-2d-importers.regression.ts(+5 -1)📝
scripts/regressions/avatar-2d-renderers.regression.ts(+3 -2)➕
scripts/regressions/avatar-backgrounds.regression.ts(+491 -0)➕
scripts/regressions/avatar-generation-cancel.regression.ts(+232 -0)📝
scripts/regressions/avatar-stage-logic.regression.ts(+16 -4)📄 Description
Linked issue
No linked issue: requested by the maintainer on 2026-10-14.
Why this change
What changed
What works differently for users:
How:
POST /api/avatar-generation/cancel(owner + kind). It aborts the job's provider requests through the job'sAbortSignaland frees the avatar right away. This covers the image edit (and its fallback connection) and the mesh avatar's vision request. Closing the request still works as before. A new start waits for the last Cancel request, so a late cancel never stops the next job.removeSpriteBackgroundPngand the AI remover's mask softening) moved unchanged fromroutes/sprites.routes.tsintoservices/image/sprite-background.service.ts. Its result now also saysfallbackwhen the AI remover was wanted but gave nothing. The newservices/avatars/cutouts.tsreuses it, with the configured engine: the built-in cleaner for a flat background, and the AI remover when it is installed and the background isn't flat (or always, when it is the configured engine). When the AI remover is missing or fails, the built-in cleaner is used, as on Lite and Termux. A picture counts as already transparent by the matte cleanup's own test (a tenth of it see-through, or some see-through pixels reaching the border).cutout-1-<hash>-fallback.png) and served withno-cache, notimmutable. It is made again when the AI remover is installed. If the installed remover failed on that sprite, it is not run again until the server restarts.applyAvatarSourceOutlinethen gives the drawn picture the cut-out's alpha. Within a few pixels of the cut-out's see-through part it keeps the cut-out's own pixels, because the model drew those mixed with its background. That band is used rather than "every pixel short of solid" because the AI remover's mask is often just short of solid inside the face, and the drawn eyes and mouth must show there.GET /api/avatar-models/:ownerType/:ownerId/sprite-cutouts/:labelserves a sprite's cut-out, made on first request. The stage, setup panel and preview ask for it instead of the raw sprite. The URL carries the sprite's own?v=version.docs/agents/avatars.mddescribes Cancel and the cut-outs, in short sentences.Decision for the maintainer: the cut-outs use the sprite cleanup's configured engine, as sprite generation does. On the default setting, a flat background goes to the built-in cleaner even when the AI remover is installed, and a busier one goes to the AI remover. The request said "AI remover when available". The built-in cleaner is much faster for flat backgrounds, and the AI remover runs one Python process per picture. Making the AI remover always go first is a one-line change in
cutouts.ts; say if you want it.Validation
pnpm checkpasses locallyCONTRIBUTING.mdCommands run by the agent (results as reported, not a substitute for the boxes above):
pnpm check(onf1c9515dc): passed.pnpm lintshows one warning in a client file this PR doesn't touch.pnpm localization:check: passed (no new UI copy).node scripts/run-regressions.mjs --filter avatar(onf1c9515dc): 16/16 passed, including the newavatar-generation-cancelandavatar-backgroundsregressions.--filter sprite2/2 passed onf1c9515dc.--filter image-generation1/1 passed on the same changes before the size cap below was added.--filter pixelize1/1 and--filter open-issues1/1 passed on the earlier head.avatar-backgrounds: the old outline function fails onthe edge is the cut-out's own (no rim from the model's background). Keeping only fully solid pixels from the drawn picture fails onthe drawn mark staysfor a cut-out whose inside is alpha 250. Showing the model the cut-out fails onthe model sees the sprite as it is. The oldcutouts.tsfails onit is stored as a fallback.avatar-generation-cancelagainst staging's avatar code fails withafter Cancel, the next picture: the Engine answered 409 {"error":"This avatar is already being made. …"}. The new e2e against staging's code fails on the cancelled panel still showing 2 "Waiting" pictures. Without the "wait for the last Cancel" change, the e2e fails because the late cancel closed the next picture's request.avatar-generation,avatar-2d,avatar-setuppassed (15) onf1c9515dc. desktop-chromiumavatar-generation,avatar-2d,avatar-setup,avatar-previewpassed (17) on the same changes before the size cap below was added.narrator-macro-avatarsfails locally because its fixturepackages/client/public/sprites/mari/Mari_wave.pngis not in the repository (not onstagingeither); it is unrelated to this change.coderabbit review --agent --committed): the first run had 2 findings, both fixed. A late/cancelcould stop the next job; a new start now waits for it, and the e2e proves it. The cut-out route didn't check that the owner exists; it now does and cleans up after a deletion race. The second run had 0 findings. The run on the review-fix commit had 1 trivial finding (the set of sprites the AI remover failed on had no size cap), fixed in that commit.Manual verification notes
.savewhose costume has a background layer: the faces come in as cut-outs.pnpm backgroundremover:install) on a sprite with a busy, non-flat background: the face is a clean cut-out, and a blink picture made from it still shows its closed eyes. Then on Lite/Termux (built-in cleaner only)._blink/_talksprites on a busy background with the AI remover: each sprite is cut out on its own, so check that the edge doesn't shimmer when it blinks. With the built-in cleaner the outlines match exactly; with the AI remover this is untested.Not covered: the real AI remover (the tests use a fake command). Also, local backends (ComfyUI, A1111, Draw Things, SwarmUI) keep drawing after their HTTP request is aborted, because the shared image service sends no interrupt. That affects every image feature, not only avatars, and is left for a separate change.
Docs and release impact
docs-i18nbranch updated to match, or a[docs-i18n]follow-up issue opened (see CONTRIBUTING.md § Translated documentation)docs/agents/avatars.mdchanged. The follow-up for translations is added to the open #7618 ([docs-i18n] docs/agents/avatars.md).UI evidence (if applicable)
Before/after screenshots were taken locally and are not uploaded. They show a PNGTuber face, its blink picture and a mesh avatar from a sprite on a cream background: staging shows the background box, this branch shows cut-outs. They also show the cancelled panel and a drawn blink picture.
Summary by CodeRabbit
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.