[PR #7664] [MERGED] fix(images): queue media requests per provider account #7866

Closed
opened 2026-10-24 04:08:18 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7664
Author: @ylli-selmani
Created: 10/14/2026
Status: ✅ Merged
Merged: 10/15/2026
Merged by: @ylli-selmani

Base: staging ← Head: fix/provider-media-queue


📝 Commits (10+)

  • 8a4aa40 fix(images): queue media requests per provider account in generateImage (#7662)
  • b4e317b fix(images): leave a short gap between NovelAI requests in one lane (#7662)
  • a40dacd fix(images): retry NovelAI image requests when the provider is busy (#7662)
  • 9f538bb fix(video): queue video requests per provider account (#7662)
  • 5cf8f96 fix(images): type the busy-retry delay lookup (#7662)
  • f655f32 refactor(images): let generateImage own media queueing on image routes (#7662)
  • f456735 fix(images): key provider lanes without hashing API keys (#7662)
  • bc43e85 fix(images): forget interned API keys once every lane is idle (#7662)
  • 9890996 fix(images): release the provider lane before trying a fallback (#7662)
  • fbf9784 fix(images): skip the 429 retry wait when cancelled during body cleanup (#7662)

📊 Changes

10 files changed (+782 additions, -184 deletions)

View changed files

📝 packages/client/src/lib/settings-registry.ts (+2 -1)
📝 packages/client/src/localization/locales/en.json (+1 -1)
📝 packages/server/src/routes/app-settings.routes.ts (+2 -0)
📝 packages/server/src/routes/gallery.routes.ts (+31 -48)
📝 packages/server/src/routes/generate/retry-agents-route.ts (+20 -30)
📝 packages/server/src/services/image/image-generation-queue.ts (+126 -0)
📝 packages/server/src/services/image/image-generation.ts (+69 -36)
📝 packages/server/src/services/storage/app-settings.storage.ts (+4 -0)
📝 packages/server/src/services/video/video-generation.ts (+84 -68)
➕ scripts/regressions/media-provider-lane.regression.ts (+443 -0)

📄 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 #7662

Why this change

  • With Queue media generation requests on, NovelAI still rejected images whenever two features drew at once: the Illustrator alongside an [illustrate] command, the Illustrator alongside Character Tracker NPC avatars, or Slurp generating many posts. Only a few routes honored the toggle, and everything else only had the global ceiling of 4 parallel requests.

What changed

  • With the toggle on, image and video requests to the same provider account now go out one at a time, whichever feature sends them: agents, trackers, [illustrate] commands, capability packages (Slurp), the gallery, and game assets. Different accounts and providers still run in parallel.
  • Two connections that use the same endpoint and API key now share one queue.
  • The toggle now also applies to work the server starts on its own (agents, packages). It was already synced to the server; the server now reads it.
  • NovelAI gets 1 s of breathing room between back-to-back requests. If NovelAI still answers "busy" (429), Marinara waits and retries twice (after 2 s, then 4 s) instead of failing the image.
  • The gallery's "generate image" button used to queue even with the setting off. It now follows the setting like everything else.
  • The setting's help text now says it queues per provider account instead of per connection.

How: generateImage and generateVideo enter a provider lane before they take a global permit. The lane is keyed on the physical endpoint plus an opaque per-process account number, so no API key or digest ends up in a key. The lane is re-entrant, so nested and fallback calls don't wait on themselves. Capability packages reach images through host.images.generate, which calls generateImage, so no Marinara-Agents change is needed. The illustrator retry and gallery routes no longer wrap generateImage in the old per-connection queue.

Slices

  • 1. Provider lane in generateImage. One queue per provider account, with the toggle read on the server, plus a regression.
  • 2. Breathing room. A short gap after each response inside a lane, so back-to-back requests (Slurp posts) don't hit NovelAI's lock.
  • 3. Backoff. On NovelAI's "concurrent generation" 429, wait in the lane and retry instead of failing.
  • 4. Video. The same lane in generateVideo.
  • 5. Cleanup. Drop the now-redundant per-route wrappers so no waiter holds a permit, and update the setting's help text ("per connection" → "per provider account").

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

  • Claude ran pnpm check on the final head (passed), plus the regressions matching media, image, gallery, retry, video and novelai (all pass).
  • The new scripts/regressions/media-provider-lane.regression.ts checks:
    • FIFO order within a lane, and parallel lanes for different accounts.
    • Re-entrancy, and that an abort or a thrown error frees the lane.
    • The toggle off, and the gap between requests.
    • The 429 retry.
    • The real generateImage and generateVideo paths against local fixture providers.
  • The image and video sections fail without the change: the provider sees 2 parallel requests.
  • Local CodeRabbit ran once and raised 2 findings, both left as is. (1, minor) The retry route passes the model as source: its imgServiceHint already falls back to imageGenerationSource, so the lane resolves the same backend the request actually goes to. (2, trivial) The account map keeps API keys in memory: the server already holds those keys, and the map grows by one entry per distinct key. Hashing them is what CodeQL rejected.
  • Not yet verified live against NovelAI.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) 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)

UI evidence (if applicable)

Only the setting's help text changed (Settings → Overall Generations → Queue media generation requests).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Image and video generation requests are queued one at a time per provider account within each generation type; requests for different accounts can run in parallel. Queuing is enabled by default and can be disabled in settings.
    • NovelAI image requests have a brief cooldown between jobs, and temporary “too many requests” responses are retried automatically.
  • Bug Fixes
    • Gallery image generation and retry requests follow the same provider-account queue behavior as other image-generation requests.

🔄 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/7664 **Author:** [@ylli-selmani](https://github.com/ylli-selmani) **Created:** 10/14/2026 **Status:** ✅ Merged **Merged:** 10/15/2026 **Merged by:** [@ylli-selmani](https://github.com/ylli-selmani) **Base:** `staging` ← **Head:** `fix/provider-media-queue` --- ### 📝 Commits (10+) - [`8a4aa40`](https://github.com/Pasta-Devs/Marinara-Engine/commit/8a4aa4051ed698ea7a989856eefca906b86ec615) fix(images): queue media requests per provider account in generateImage (#7662) - [`b4e317b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b4e317bb9fcb02f660596e64abca150dcd67e438) fix(images): leave a short gap between NovelAI requests in one lane (#7662) - [`a40dacd`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a40dacd4ec3e0ba7884eedb77237545fbd613b12) fix(images): retry NovelAI image requests when the provider is busy (#7662) - [`9f538bb`](https://github.com/Pasta-Devs/Marinara-Engine/commit/9f538bb2b5e9863f1dd2cb3992ae7d39b52da0be) fix(video): queue video requests per provider account (#7662) - [`5cf8f96`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5cf8f965f6fc36b379a44b6774608060995f7c97) fix(images): type the busy-retry delay lookup (#7662) - [`f655f32`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f655f32e98a5632b4281d9754487d3fd458451e1) refactor(images): let generateImage own media queueing on image routes (#7662) - [`f456735`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f4567353d8d6db90c485a39b86d316b558afae8f) fix(images): key provider lanes without hashing API keys (#7662) - [`bc43e85`](https://github.com/Pasta-Devs/Marinara-Engine/commit/bc43e85ae3d9c758b6d7c6acdd7cadc9aff23838) fix(images): forget interned API keys once every lane is idle (#7662) - [`9890996`](https://github.com/Pasta-Devs/Marinara-Engine/commit/98909964f951c759d46e7e7c241f5eb2b1087056) fix(images): release the provider lane before trying a fallback (#7662) - [`fbf9784`](https://github.com/Pasta-Devs/Marinara-Engine/commit/fbf9784f1669302fe0880d587921f182ab2d2d6d) fix(images): skip the 429 retry wait when cancelled during body cleanup (#7662) ### 📊 Changes **10 files changed** (+782 additions, -184 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/lib/settings-registry.ts` (+2 -1) 📝 `packages/client/src/localization/locales/en.json` (+1 -1) 📝 `packages/server/src/routes/app-settings.routes.ts` (+2 -0) 📝 `packages/server/src/routes/gallery.routes.ts` (+31 -48) 📝 `packages/server/src/routes/generate/retry-agents-route.ts` (+20 -30) 📝 `packages/server/src/services/image/image-generation-queue.ts` (+126 -0) 📝 `packages/server/src/services/image/image-generation.ts` (+69 -36) 📝 `packages/server/src/services/storage/app-settings.storage.ts` (+4 -0) 📝 `packages/server/src/services/video/video-generation.ts` (+84 -68) ➕ `scripts/regressions/media-provider-lane.regression.ts` (+443 -0) </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`. ## Linked issue Closes #7662 ## Why this change - With **Queue media generation requests** on, NovelAI still rejected images whenever two features drew at once: the Illustrator alongside an `[illustrate]` command, the Illustrator alongside Character Tracker NPC avatars, or Slurp generating many posts. Only a few routes honored the toggle, and everything else only had the global ceiling of 4 parallel requests. ## What changed - With the toggle on, image **and video** requests to the same provider account now go out one at a time, whichever feature sends them: agents, trackers, `[illustrate]` commands, capability packages (Slurp), the gallery, and game assets. Different accounts and providers still run in parallel. - Two connections that use the same endpoint and API key now share one queue. - The toggle now also applies to work the server starts on its own (agents, packages). It was already synced to the server; the server now reads it. - NovelAI gets 1 s of breathing room between back-to-back requests. If NovelAI still answers "busy" (429), Marinara waits and retries twice (after 2 s, then 4 s) instead of failing the image. - The gallery's "generate image" button used to queue even with the setting off. It now follows the setting like everything else. - The setting's help text now says it queues per provider account instead of per connection. **How:** `generateImage` and `generateVideo` enter a provider lane before they take a global permit. The lane is keyed on the physical endpoint plus an opaque per-process account number, so no API key or digest ends up in a key. The lane is re-entrant, so nested and fallback calls don't wait on themselves. Capability packages reach images through `host.images.generate`, which calls `generateImage`, so no Marinara-Agents change is needed. The illustrator retry and gallery routes no longer wrap `generateImage` in the old per-connection queue. ## Slices - [x] **1. Provider lane in `generateImage`.** One queue per provider account, with the toggle read on the server, plus a regression. - [x] **2. Breathing room.** A short gap after each response inside a lane, so back-to-back requests (Slurp posts) don't hit NovelAI's lock. - [x] **3. Backoff.** On NovelAI's "concurrent generation" 429, wait in the lane and retry instead of failing. - [x] **4. Video.** The same lane in `generateVideo`. - [x] **5. Cleanup.** Drop the now-redundant per-route wrappers so no waiter holds a permit, and update the setting's help text ("per connection" → "per provider account"). ## 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 - Claude ran `pnpm check` on the final head (passed), plus the regressions matching `media`, `image`, `gallery`, `retry`, `video` and `novelai` (all pass). - The new `scripts/regressions/media-provider-lane.regression.ts` checks: - FIFO order within a lane, and parallel lanes for different accounts. - Re-entrancy, and that an abort or a thrown error frees the lane. - The toggle off, and the gap between requests. - The 429 retry. - The real `generateImage` and `generateVideo` paths against local fixture providers. - The image and video sections fail without the change: the provider sees 2 parallel requests. - Local CodeRabbit ran once and raised 2 findings, both left as is. (1, minor) The retry route passes the model as `source`: its `imgServiceHint` already falls back to `imageGenerationSource`, so the lane resolves the same backend the request actually goes to. (2, trivial) The account map keeps API keys in memory: the server already holds those keys, and the map grows by one entry per distinct key. Hashing them is what CodeQL rejected. - Not yet verified live against NovelAI. ## Docs and release impact - [x] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) 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) ## UI evidence (if applicable) Only the setting's help text changed (Settings → Overall Generations → Queue media generation requests). 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Image and video generation requests are queued one at a time per provider account within each generation type; requests for different accounts can run in parallel. Queuing is enabled by default and can be disabled in settings. * NovelAI image requests have a brief cooldown between jobs, and temporary “too many requests” responses are retried automatically. * **Bug Fixes** * Gallery image generation and retry requests follow the same provider-account queue behavior as other image-generation requests. <!-- 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-24 04:08:18 +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#7866
No description provided.