mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #5103] [MERGED] feat(image): global media-generation concurrency ceiling with priority, bounded waits, and live tuning #6629
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#6629
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/5103
Author: @kolacheee
Created: 8/15/2026
Status: ✅ Merged
Merged: 8/16/2026
Merged by: @kolacheee
Base:
staging← Head:feat/5097-generation-concurrency-cap📝 Commits (9)
2fafe73feat(image): global media-generation concurrency ceiling (#5097)6a3eeb7Merge branch 'staging' into feat/5097-generation-concurrency-capd865da9Merge remote-tracking branch 'origin/staging' into feat/5097-generation-concurrency-capc5db679fix(image): warn once on an invalid media-generation wait-timeout env3f66af2Merge remote-tracking branch 'origin/staging' into feat/5097-generation-concurrency-capb3ea4d9Merge remote-tracking branch 'origin/staging' into feat/5097-generation-concurrency-capf774d59Merge remote-tracking branch 'origin/staging' into feat/5097-generation-concurrency-capb987b70docs(changelog): qualify the no-stampede claim to when the ceiling is enabled (#5097)c2ab98bdocs(changelog): qualify the bounded-wait claim (WAIT_TIMEOUT_MS=0 waits indefinitely) (#5097)📊 Changes
8 files changed (+593 additions, -3 deletions)
View changed files
📝
.env.example(+5 -0)📝
CHANGELOG.md(+1 -0)📝
docs/CONFIGURATION.md(+2 -0)📝
package.json(+2 -1)📝
packages/server/src/services/image/image-generation-queue.ts(+217 -2)📝
packages/server/src/services/image/image-generation.ts(+27 -0)📝
packages/shared/src/constants/defaults.ts(+7 -0)➕
scripts/regressions/media-generation-cap.regression.ts(+332 -0)📄 Description
Closes #5097
Why
Media generation has no process-wide limit: the per-connection FIFO is opt-in and per-key, so a batch that fans out (a zone's worth of tiles, storyboard frames, gallery bulk) can stampede a local ComfyUI/SwarmUI GPU into OOM or fan out unbounded concurrent calls against a paid provider.
What changed
A two-tier permit semaphore in
image-generation-queue.ts, enforced at the generators themselves:generateImagenow self-wraps exactly the waygenerateVideoalready did, so every image path — game assets, sprites, avatars, storyboards, Mari images, previously all uncapped — is covered at a single point with no per-caller wiring. Default ceiling 4,MARINARA_MEDIA_GENERATION_CONCURRENCYto tune,0to disable.This PR went through a pre-submission adversarial review that reshaped it substantially; the design properties below are each regression-pinned:
AsyncLocalStorageguard makes nested acquisitions reuse the held permit — which is also what makesgenerateImage's self-wrap safe under the existing per-connection wrappers and its own fallback recursion..envchanges are hot-reloaded in this app, and the docs tell users to lower the cap exactly when a batch is thrashing VRAM — so lowering must converge while waiters exist (the naive direct-handoff pinned the old width), and raising must wake parked waiters. Pump-based accounting does both.MARINARA_MEDIA_GENERATION_WAIT_TIMEOUT_MS, default 10 min,0= forever) instead of parking forever behind a hung provider call — saturation now fails loudly, never silently.admissionModemarker from connection-admission) never occupies the last permit, so batches cannot fully starve interactive generation. Foreground waiters drain first.0= unlimited (the explicit opt-out), invalid values warn once and use the default; a would-be negative permit count logs an accounting-bug warning instead of hiding in a clamp.Acquisition ordering keeps the two queues cycle-free (global permit strictly after the per-connection turn), and release is idempotent and in
finallyon every path.New tracked lane
regression:generation-cap(inregression:issues), 10 deterministic cases: cap enforcement for non-queued callers, throw/abort/grant-then-abort permit recovery, nested-at-limit-1 no-deadlock, live lower convergence and raise wake-up, wait timeout, 0-unlimited, background-reserve + foreground-first draining, per-key FIFO with cross-queue no-deadlock, and pre-aborted rejection.Known limitations, stated plainly: video requests don't carry
admissionModeyet, so the priority split currently differentiates image work only (video defaults to foreground); and several signal-less call sites (sprite animation loop, connection tests) rely on the wait timeout rather than true cancellation — threading signals there is a natural follow-up.Validation
pnpm checkpnpm regression:generation-cap(new)pnpm regression:docsandpnpm version:check(defaults.ts gains a constant only)MARINARA_MEDIA_GENERATION_CONCURRENCYin.envmid-batch visibly reduces in-flight requests.Summary by CodeRabbit
New Features
Documentation
Tests
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.