[PR #4423] [CLOSED] AFTER UPDATE: fix(generation): centralize connection admission and provider fallback #6373

Closed
opened 2026-10-23 04:09:47 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/4423
Author: @Gunterlie
Created: 8/1/2026
Status: ❌ Closed

Base: staging ← Head: stack/1-admission


📝 Commits (7)

  • 5a4c047 fix(generation): centralize connection admission and provider fallback
  • 7f5a6cc fix(generation): thread connection ids through admission call sites
  • 84f28a3 fix(generation): release the admission slot when a stream is abandoned
  • c5e88a6 fix(generation): keep teardown failures from masking provider errors
  • 4499a53 fix(generation): log primary stream teardown failures instead of dropping them
  • 8b8cb1f fix(generation): key image admission by endpoint and keep provider diagnostics concrete
  • f727e13 fix(image): scope endpoint-keyed admission to RunPod backends

📊 Changes

14 files changed (+451 additions, -25 deletions)

View changed files

📝 packages/server/src/routes/connections.routes.ts (+3 -0)
📝 packages/server/src/routes/encounter.routes.ts (+3 -0)
📝 packages/server/src/routes/generate/dry-run-route.ts (+1 -0)
📝 packages/server/src/routes/lorebooks.routes.ts (+1 -0)
📝 packages/server/src/services/capability-packages/capability-language-model.service.ts (+4 -1)
➕ packages/server/src/services/generation/connection-admission.ts (+196 -0)
📝 packages/server/src/services/image/image-generation.ts (+37 -2)
📝 packages/server/src/services/llm/connection-fallback-provider.ts (+44 -21)
📝 packages/server/src/services/llm/provider-registry.ts (+5 -1)
📝 packages/server/src/services/memory-recall-embedding.ts (+1 -0)
📝 packages/server/src/services/professor-mari/workspace-agent.service.ts (+1 -0)
📝 packages/server/src/services/spotify/dj-mari-playlist.service.ts (+1 -0)
📝 packages/server/src/services/turn-games/turn-game-bot-runner.service.ts (+1 -0)
📝 scripts/regressions/provider-compat.regression.ts (+153 -0)

📄 Description

Why

NoodleR posts and images generate in the background, on the same API connection the user is actively chatting on. Without a gate, a scheduled creator post fires mid-roleplay and the user queues behind their own bot, or burns rate limit they wanted for themselves.

This adds a shared admission service so background work yields to foreground work: it is admitted only when nothing is running in the foreground on that connection and the last foreground request finished at least 30s ago. Foreground work never asks permission.

Admission failures are typed distinctly (isConnectionAdmissionFailure) so the fallback chain can tell "connection busy" apart from "provider failed" — otherwise a busy connection would look like an outage and trigger a pointless failover to the backup model.

Relationship to #4503

Standalone against staging — not a stack. This PR is the connection-admission
work only, and it stands on its own.

The rest of what was originally split across stack/2-docs and stack/3-server
now lives in #4503 (NoodleR Slice 8f), which is also based on staging and is
reviewed independently.

#4503's branch does contain this PR's commits, because the Slice 8f code is
built on the admission service. Merge this PR first — once it lands, these
changes drop out of #4503's diff and what remains there is the Slice 8f work.

Notes

  • No linked issue exists for this work; one should be opened before this is taken out of draft.
  • states is a module-level map keyed per connection id and per image base URL, and is never pruned. Bounded by configured connections, so not a leak that matters in practice, but it is an unmarked deliberate call.

Test plan

  • pnpm check
  • pnpm regression:providers
  • Manually verify in the app: start a long foreground generation, confirm a scheduled NoodleR post does not fire until 30s after it finishes
  • Manually verify a genuinely failing primary provider still falls back to the backup model (admission errors must not suppress real failover)

Summary by CodeRabbit

  • New Features

    • Added connection-aware controls for language model, embedding, and image-generation requests.
    • Prevented conflicting background requests during active foreground work.
    • Improved handling of shared image-generation endpoints and interrupted streaming requests.
  • Bug Fixes

    • Prevented unnecessary fallback retries after connection admission failures.
    • Ensured connection activity is released after completed or interrupted requests.
  • Tests

    • Added coverage for connection exclusivity, fallback behavior, stream abandonment, and background request handling.

🔄 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/4423 **Author:** [@Gunterlie](https://github.com/Gunterlie) **Created:** 8/1/2026 **Status:** ❌ Closed **Base:** `staging` ← **Head:** `stack/1-admission` --- ### 📝 Commits (7) - [`5a4c047`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5a4c0474d59f4b4f33069f0b5cc55807ed5f92f1) fix(generation): centralize connection admission and provider fallback - [`7f5a6cc`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7f5a6cc8f272823a457a2976fe26dab1c0529a5b) fix(generation): thread connection ids through admission call sites - [`84f28a3`](https://github.com/Pasta-Devs/Marinara-Engine/commit/84f28a39d9f977138943c5c2c4f9ea0d7fe1fa5b) fix(generation): release the admission slot when a stream is abandoned - [`c5e88a6`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c5e88a66abd9f2aa19625775b0707cbdac863a2d) fix(generation): keep teardown failures from masking provider errors - [`4499a53`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4499a53f3d127ebdb84bd5640e96c9e18507c14f) fix(generation): log primary stream teardown failures instead of dropping them - [`8b8cb1f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/8b8cb1f622430a691bd77228b491fa298235d294) fix(generation): key image admission by endpoint and keep provider diagnostics concrete - [`f727e13`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f727e13067255ccb6db291a8a3f904f23cf50dd1) fix(image): scope endpoint-keyed admission to RunPod backends ### 📊 Changes **14 files changed** (+451 additions, -25 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/routes/connections.routes.ts` (+3 -0) 📝 `packages/server/src/routes/encounter.routes.ts` (+3 -0) 📝 `packages/server/src/routes/generate/dry-run-route.ts` (+1 -0) 📝 `packages/server/src/routes/lorebooks.routes.ts` (+1 -0) 📝 `packages/server/src/services/capability-packages/capability-language-model.service.ts` (+4 -1) ➕ `packages/server/src/services/generation/connection-admission.ts` (+196 -0) 📝 `packages/server/src/services/image/image-generation.ts` (+37 -2) 📝 `packages/server/src/services/llm/connection-fallback-provider.ts` (+44 -21) 📝 `packages/server/src/services/llm/provider-registry.ts` (+5 -1) 📝 `packages/server/src/services/memory-recall-embedding.ts` (+1 -0) 📝 `packages/server/src/services/professor-mari/workspace-agent.service.ts` (+1 -0) 📝 `packages/server/src/services/spotify/dj-mari-playlist.service.ts` (+1 -0) 📝 `packages/server/src/services/turn-games/turn-game-bot-runner.service.ts` (+1 -0) 📝 `scripts/regressions/provider-compat.regression.ts` (+153 -0) </details> ### 📄 Description ## Why NoodleR posts and images generate in the background, on the same API connection the user is actively chatting on. Without a gate, a scheduled creator post fires mid-roleplay and the user queues behind their own bot, or burns rate limit they wanted for themselves. This adds a shared admission service so background work yields to foreground work: it is admitted only when nothing is running in the foreground on that connection and the last foreground request finished at least 30s ago. Foreground work never asks permission. Admission failures are typed distinctly (`isConnectionAdmissionFailure`) so the fallback chain can tell "connection busy" apart from "provider failed" — otherwise a busy connection would look like an outage and trigger a pointless failover to the backup model. ## Relationship to #4503 Standalone against `staging` — not a stack. This PR is the connection-admission work only, and it stands on its own. The rest of what was originally split across `stack/2-docs` and `stack/3-server` now lives in #4503 (NoodleR Slice 8f), which is also based on `staging` and is reviewed independently. #4503's branch does contain this PR's commits, because the Slice 8f code is built on the admission service. **Merge this PR first** — once it lands, these changes drop out of #4503's diff and what remains there is the Slice 8f work. ## Notes - No linked issue exists for this work; one should be opened before this is taken out of draft. - `states` is a module-level map keyed per connection id and per image base URL, and is never pruned. Bounded by configured connections, so not a leak that matters in practice, but it is an unmarked deliberate call. ## Test plan - [ ] `pnpm check` - [ ] `pnpm regression:providers` - [ ] Manually verify in the app: start a long foreground generation, confirm a scheduled NoodleR post does not fire until 30s after it finishes - [ ] Manually verify a genuinely failing primary provider still falls back to the backup model (admission errors must not suppress real failover) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added connection-aware controls for language model, embedding, and image-generation requests. * Prevented conflicting background requests during active foreground work. * Improved handling of shared image-generation endpoints and interrupted streaming requests. * **Bug Fixes** * Prevented unnecessary fallback retries after connection admission failures. * Ensured connection activity is released after completed or interrupted requests. * **Tests** * Added coverage for connection exclusivity, fallback behavior, stream abandonment, and background request handling. <!-- 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-23 04:09:47 +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#6373
No description provided.