[PR #8018] [MERGED] fix: text and media take turns on a shared local GPU (MARINARA_SHARED_GPU_HOSTS) #8060

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/8018
Author: @JamesMowery
Created: 10/21/2026
Status: ✅ Merged
Merged: 10/23/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/shared-gpu-media-turns


📝 Commits (8)

  • 5b9f884 fix: let text and media take turns on a shared local GPU
  • 227e8fc test: the prompt regression follows the selfie writer's reasoning strip
  • b0a24a0 docs: align the MARINARA_SHARED_GPU_HOSTS row with its table
  • acc8cc4 fix: a media request waits for its shared GPU turn no longer than for a media permit
  • 7ad6055 fix: a shared GPU wait limit past AbortSignal.timeout's range means no limit
  • 36db906 fix: wait for the shared GPU turn before taking a media permit or admission
  • 4390cdc fix: a queued clip waits for its connection before its shared GPU turn
  • 6c6705b fix: a queued first-frame selfie waits for the shared GPU before a permit

📊 Changes

11 files changed (+798 additions, -35 deletions)

View changed files

📝 .env.example (+3 -0)
📝 docs/CONFIGURATION.md (+1 -0)
📝 packages/server/src/services/generation/conversation-selfie-command-runtime.ts (+25 -7)
➕ packages/server/src/services/generation/shared-gpu-turns.ts (+207 -0)
📝 packages/server/src/services/image/image-generation-queue.ts (+18 -13)
📝 packages/server/src/services/image/image-generation.ts (+10 -4)
📝 packages/server/src/services/llm/provider-registry.ts (+3 -1)
📝 packages/server/src/services/video/video-generation.ts (+8 -1)
📝 scripts/regressions/prompt.regression.ts (+9 -9)
➕ scripts/regressions/shared-gpu-queued-selfie.regression.ts (+165 -0)
➕ scripts/regressions/shared-gpu-turns.regression.ts (+349 -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 #8017
@SpicyMarinara

Why this change

  • With one GPU shared by a local LLM and a local image/video backend (llama-swap swapping llama.cpp and ComfyUI), a media request waited while any text request was in flight, and every new text request went past it. With a few chats generating, pictures waited for minutes and were lost.
  • A ComfyUI video behind a render gate failed at Undici's five-minute headers timeout.
  • A selfie whose prompt came back empty ended without a word.

What changed

  • MARINARA_SHARED_GPU_HOSTS (comma-separated host:port, off by default; .env.example, docs/CONFIGURATION.md): text and media requests to a listed host take turns (services/generation/shared-gpu-turns.ts).
    • Requests of one kind run together, never both kinds at once. Once one kind is waiting, new requests of the running kind queue behind it; when the running kind drains, everything waiting of the other kind goes together. Neither kind can starve the other, and the GPU swaps once per turn instead of once per request.
    • Text goes through a provider wrapper (innermost in provider-registry.ts, so a turn is held only while the request is with the backend; a stream holds its turn until it closes). Images and videos go through runSharedGpuTurn inside their existing admission and queues. Embeddings are not held, and a call already inside a turn runs straight through.
    • A picture or clip waits for its turn no longer than MARINARA_MEDIA_GENERATION_WAIT_TIMEOUT_MS (10 minutes by default, 0 = no limit), so a stalled text stream can't hold it, and the text queued behind it, forever. Text waits for the render it follows.
    • Read on every call, so .env edits apply without a restart. Unlisted hosts are untouched.
  • ComfyUI video timeout: video requests use VIDEO_GEN_TIMEOUT for Undici's headers and body timeouts, so a render gate holding POST /prompt no longer fails the clip at five minutes.
  • Empty selfie prompt: leading think blocks are removed first; an empty prompt now throws "The Prompt Model returned an empty selfie prompt." (or says it ran out of its response budget) instead of ending the selfie silently.

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

Automated runs on 2026-10-21 on staging 5e7468ab4, Node 24.21.0:

  • pnpm check: passes. Its one lint warning, in HomeProfessorMariChat.tsx, is not from this PR.
  • pnpm localization:check: passes.
  • shared-gpu-turns (new): host matching; a waiting media request holds back new text while the running text drains; one kind runs together; an abort while waiting lets the queue move on; nested calls run through; a throw releases the turn; a stream holds its turn until it closes; unlisted hosts are not wrapped; a media wait times out behind stalled text and lets the text queued behind it go ahead (it hangs without the fix). prompt: its source checks follow the selfie writer's think-block strip. media-generation-cap passes.
  • Full pnpm regression on 227e8fccb: 961/961 pass. The later commits were checked with shared-gpu-turns, prompt, media-generation-cap and a server type check.
  • Local CodeRabbit (CLI) on the branch: 2 findings (one issue), fixed in acc8cc4a7: a media request without its own signal could wait for its turn forever behind a stalled text stream; it now waits no longer than MARINARA_MEDIA_GENERATION_WAIT_TIMEOUT_MS. A review of that commit: 2 findings, fixed in 7ad605543 (a limit past AbortSignal.timeout's range means no limit; the regression's deadline has room and its rejection is observed from the start). A review of that commit: 0 findings.
  • Manual: the author's setup (llama-swap with llama.cpp and ComfyUI on one GPU, MARINARA_SHARED_GPU_HOSTS=phoenix:8081) made pictures and three group-chat clips arrive while several chats generated; before, they were lost. That was on 2026-10-18, before the timeout commits.
  • Not run: pnpm smoke:ui and pnpm regression:ui (server-only change).

Manual verification notes

  • Manually verify with MARINARA_SHARED_GPU_HOSTS unset that text, pictures and clips behave exactly as before.
  • Manually verify on a shared GPU (llama-swap or similar) that pictures and selfies arrive while two or three chats keep generating.
  • Manually verify a long ComfyUI video (over five minutes) behind a render gate is saved.
  • Manually verify a selfie with a Prompt Model that returns nothing shows an error toast.

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)

English docs updated: docs/CONFIGURATION.md (MARINARA_SHARED_GPU_HOSTS), and .env.example. Translations: #8019

UI evidence (if applicable)

No UI changes.

🤖 Generated with Claude Code


🔄 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/8018 **Author:** [@JamesMowery](https://github.com/JamesMowery) **Created:** 10/21/2026 **Status:** ✅ Merged **Merged:** 10/23/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/shared-gpu-media-turns` --- ### 📝 Commits (8) - [`5b9f884`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5b9f8840bf9021cba0a726e09791c9800f8fc50d) fix: let text and media take turns on a shared local GPU - [`227e8fc`](https://github.com/Pasta-Devs/Marinara-Engine/commit/227e8fccbaf610adf6891fe95bcbba9829d117f4) test: the prompt regression follows the selfie writer's reasoning strip - [`b0a24a0`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b0a24a0ef1cc61493ac3364efe6270501a62431f) docs: align the MARINARA_SHARED_GPU_HOSTS row with its table - [`acc8cc4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/acc8cc4a7e208c87ce8c45b841e94f19b0debcf8) fix: a media request waits for its shared GPU turn no longer than for a media permit - [`7ad6055`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7ad6055432790598ea23f73061287bffaa216fa9) fix: a shared GPU wait limit past AbortSignal.timeout's range means no limit - [`36db906`](https://github.com/Pasta-Devs/Marinara-Engine/commit/36db90602e464cb1c2cf7af473e16580b0c5ec76) fix: wait for the shared GPU turn before taking a media permit or admission - [`4390cdc`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4390cdcf15ffe39db2c15c51552e8f53629649bb) fix: a queued clip waits for its connection before its shared GPU turn - [`6c6705b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6c6705bf1ed2b0ff8091535dd3dccc8b1eac4e13) fix: a queued first-frame selfie waits for the shared GPU before a permit ### 📊 Changes **11 files changed** (+798 additions, -35 deletions) <details> <summary>View changed files</summary> 📝 `.env.example` (+3 -0) 📝 `docs/CONFIGURATION.md` (+1 -0) 📝 `packages/server/src/services/generation/conversation-selfie-command-runtime.ts` (+25 -7) ➕ `packages/server/src/services/generation/shared-gpu-turns.ts` (+207 -0) 📝 `packages/server/src/services/image/image-generation-queue.ts` (+18 -13) 📝 `packages/server/src/services/image/image-generation.ts` (+10 -4) 📝 `packages/server/src/services/llm/provider-registry.ts` (+3 -1) 📝 `packages/server/src/services/video/video-generation.ts` (+8 -1) 📝 `scripts/regressions/prompt.regression.ts` (+9 -9) ➕ `scripts/regressions/shared-gpu-queued-selfie.regression.ts` (+165 -0) ➕ `scripts/regressions/shared-gpu-turns.regression.ts` (+349 -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`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Closes #8017 @SpicyMarinara ## Why this change - With one GPU shared by a local LLM and a local image/video backend (llama-swap swapping llama.cpp and ComfyUI), a media request waited while any text request was in flight, and every new text request went past it. With a few chats generating, pictures waited for minutes and were lost. - A ComfyUI video behind a render gate failed at Undici's five-minute headers timeout. - A selfie whose prompt came back empty ended without a word. ## What changed - **`MARINARA_SHARED_GPU_HOSTS`** (comma-separated `host:port`, off by default; `.env.example`, `docs/CONFIGURATION.md`): text and media requests to a listed host take turns (`services/generation/shared-gpu-turns.ts`). - Requests of one kind run together, never both kinds at once. Once one kind is waiting, new requests of the running kind queue behind it; when the running kind drains, everything waiting of the other kind goes together. Neither kind can starve the other, and the GPU swaps once per turn instead of once per request. - Text goes through a provider wrapper (innermost in `provider-registry.ts`, so a turn is held only while the request is with the backend; a stream holds its turn until it closes). Images and videos go through `runSharedGpuTurn` inside their existing admission and queues. Embeddings are not held, and a call already inside a turn runs straight through. - A picture or clip waits for its turn no longer than `MARINARA_MEDIA_GENERATION_WAIT_TIMEOUT_MS` (10 minutes by default, `0` = no limit), so a stalled text stream can't hold it, and the text queued behind it, forever. Text waits for the render it follows. - Read on every call, so `.env` edits apply without a restart. Unlisted hosts are untouched. - **ComfyUI video timeout**: video requests use `VIDEO_GEN_TIMEOUT` for Undici's headers and body timeouts, so a render gate holding `POST /prompt` no longer fails the clip at five minutes. - **Empty selfie prompt**: leading think blocks are removed first; an empty prompt now throws "The Prompt Model returned an empty selfie prompt." (or says it ran out of its response budget) instead of ending the selfie silently. ## Validation <!-- Required: include commands run and/or manual checks performed --> - [x] `pnpm check` passes locally - [x] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` Automated runs on 2026-10-21 on `staging` `5e7468ab4`, Node 24.21.0: - `pnpm check`: passes. Its one lint warning, in `HomeProfessorMariChat.tsx`, is not from this PR. - `pnpm localization:check`: passes. - `shared-gpu-turns` (new): host matching; a waiting media request holds back new text while the running text drains; one kind runs together; an abort while waiting lets the queue move on; nested calls run through; a throw releases the turn; a stream holds its turn until it closes; unlisted hosts are not wrapped; a media wait times out behind stalled text and lets the text queued behind it go ahead (it hangs without the fix). `prompt`: its source checks follow the selfie writer's think-block strip. `media-generation-cap` passes. - Full `pnpm regression` on `227e8fccb`: 961/961 pass. The later commits were checked with `shared-gpu-turns`, `prompt`, `media-generation-cap` and a server type check. - Local CodeRabbit (CLI) on the branch: 2 findings (one issue), fixed in `acc8cc4a7`: a media request without its own signal could wait for its turn forever behind a stalled text stream; it now waits no longer than `MARINARA_MEDIA_GENERATION_WAIT_TIMEOUT_MS`. A review of that commit: 2 findings, fixed in `7ad605543` (a limit past `AbortSignal.timeout`'s range means no limit; the regression's deadline has room and its rejection is observed from the start). A review of that commit: 0 findings. - Manual: the author's setup (llama-swap with llama.cpp and ComfyUI on one GPU, `MARINARA_SHARED_GPU_HOSTS=phoenix:8081`) made pictures and three group-chat clips arrive while several chats generated; before, they were lost. That was on 2026-10-18, before the timeout commits. - Not run: `pnpm smoke:ui` and `pnpm regression:ui` (server-only change). ### Manual verification notes - Manually verify with `MARINARA_SHARED_GPU_HOSTS` unset that text, pictures and clips behave exactly as before. - Manually verify on a shared GPU (llama-swap or similar) that pictures and selfies arrive while two or three chats keep generating. - Manually verify a long ComfyUI video (over five minutes) behind a render gate is saved. - Manually verify a selfie with a Prompt Model that returns nothing shows an error toast. ## Docs and release impact - [ ] No docs changes needed - [x] Updated docs (README / CONTRIBUTING / android/README) as needed - [x] 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) English docs updated: `docs/CONFIGURATION.md` (`MARINARA_SHARED_GPU_HOSTS`), and `.env.example`. Translations: #8019 ## UI evidence (if applicable) No UI changes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-24 04:10:03 +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#8060
No description provided.