mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2757] [Issue]: Game asset generation — slug collisions, duplicate paid generations, and non-atomic writes #1395
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#1395
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?
Originally created by @kolacheee on GitHub (Jun 21, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2757
Originally assigned to: @SpicyMarinara on GitHub.
Summary
The game-asset generation and asset-management paths have a cluster of correctness/cost/robustness defects: slug-keyed portrait files collide and cross-assign, there is no idempotency lock so concurrent requests double-bill, recursive delete bypasses native-folder protection, and several disk writes are non-atomic/unvalidated.
Sub-bug 1: Slug collision cross-assigns portraits (#28)
safeNamecollapses punctuation/case so e.g. 'Eldrin the Wise' and 'Eldrin, the Wise!' -> same slug -> same avatar path (450). Two concurrent workers (GAME_ASSET_PORTRAIT_CONCURRENCY=2) both pass theexistsSyncgate (453), both pay, both writeFileSync (490, last wins); both NPCs get the same avatarUrl -> one shows the wrong face.Sub-bug 2: No idempotency lock -> duplicate paid gen (#29)
existsSyncis a TOCTOU gate. Overlapping callers (scene-flow fire-and-forget, combat-prep, retry button) both pass it and double-bill backgrounds/portraits.Sub-bug 3: Recursive delete wipes nested native assets (#60)
.nativeguard checks only the immediate target (640); native markers exist at every depth./movehas no native/dir guard, so a native folder can be relocated under a non-native folder, thenDELETE ?recursive=truermSyncs the subtree including the nested native assets. Shipped CC0 files are not restored on restart (bundle-hash gated).Sub-bug 4: Non-atomic portrait write + sticky skip (#62)
writeFileSync(avatarPath, ...)(490) writes straight to the final path; a crash mid-write leaves a truncated png, and theexistsSyncskip (453) reuses it forever (unless force). Recoverable via force, but sticky.Sub-bug 5: Portrait always .png (#64)
${slug}.pngand writes raw provider bytes; JPEG/WebP/AVIF (e.g. Pollinations) are mislabeled, served as image/png by extname-based MIME. Browsers sniff, but extension-trusting consumers mishandle it.Sub-bug 6: Background sharp resize unbounded vs upload guard (#63)
gameBackgroundImagecallssharp(input).resize(...)with nolimitInputPixels, unlike the upload path (which uses GENERATED_BACKGROUND_MAX_INPUT_PIXELS). Bounded by sharp's 268MP default backstop, so images between 32MP and 268MP decode/resize with transient memory pressure.Sub-bug 7: Multipart upload orphans / wasted IO (#27/#31)
await pipeline(file.file, createWriteStream(target))(448) has no try/catch; on stream error/oversize the partial file is orphaned (the post-pipeline unlink never runs). It also streams up to the 256MB global cap before the route's own 50MB check, wasting IO.Suggested Fix
npcsNeedingAvatarsby resolved slug before dispatch..nativemarkers before recursive delete; reject moving a native folder.statSync(...).size > 0(and magic bytes) before reusing.{ limitInputPixels: GENERATED_BACKGROUND_MAX_INPUT_PIXELS, failOn: 'warning' }to the generated-background sharp call.Verification checklist (all manual)
pnpm checkandpnpm db:pushAffected files
packages/server/src/services/game/game-asset-generation.tspackages/server/src/routes/game.routes.tspackages/server/src/routes/game-assets.routes.tsAudit 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
stagingtree. Severity: MEDIUM.@SpicyMarinara commented on GitHub (Jun 21, 2026):
Addressed on PR #2747. Fixed generated portrait slug collisions by adding an identity hash, preserved provider image extensions, made generated asset writes atomic, ignored broken generated image files when deciding whether to reuse, bounded generated-background sharp input pixels, serialized /game/generate-assets per chat, and hardened game asset upload/delete/move handling around temp files and native folders. Validation so far: git diff --check. Full pnpm checks are intentionally deferred until the issue sweep is complete.