[GH-ISSUE #4520] [Issue]: Local-sidecar generation paths bypass connection admission #2462

Closed
opened 2026-10-21 05:48:25 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @Gunterlie on GitHub (Aug 3, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/4520

Originally assigned to: @Gunterlie on GitHub.

Summary

PR #4514 added connection admission (foreground work always proceeds; background work yields to it and waits out an idle window) and wired the Noodle schedulers as the first background producers. Every path that resolves a remote connection is admitted, because it either passes connectionId to createLLMProvider or goes through withConnectionFallbackProvider. The local-sidecar branches are not: they hand out the raw getLocalSidecarProvider() singleton with no wrapper.

The result is that all local-sidecar work is invisible to admission — it neither registers as foreground activity nor yields as background.

Impact

Today this is latent, since only the Noodle schedulers produce background mode and they run on regular connections. It becomes a real defect as soon as any background caller targets the sidecar, or when sidecar foreground work should be blocking background work:

  • Scheduled/background work can start while a foreground local-model operation is running, and both contend for the one llama.cpp process.
  • Foreground sidecar work does not set lastForegroundFinishedAt, so the 30s post-generation idle window never applies to it.

Verified call sites (as of 1b6ddb3)

Unadmitted local-sidecar providers:

  • packages/server/src/services/capability-packages/capability-language-model.service.ts:61 — capability LLM host
  • packages/server/src/services/professor-mari/workspace-agent.service.ts:832 — Professor Mari workspace agent
  • packages/server/src/services/memory-recall-embedding.ts:122 — memory recall embeddings
  • packages/server/src/routes/lorebooks.routes.ts:1179 — lorebook vectorization
  • packages/server/src/services/generation/agent-resolution.ts:315 — cached sidecar agent provider
  • packages/server/src/routes/generate/sidecar.routes.ts:202 — direct sidecar embed endpoint
  • packages/server/src/routes/generate/raw-route.ts:415 — raw-route embed

Already admitted, listed so they are not touched: provider-generation-runtime.ts:203, retry-agents-route.ts:1408 and raw-route.ts:236 (via withConnectionFallbackProvider), chat-summary/connection-resolution.ts:100, illustrator-prompt-runtime.ts:74, image-captioning-runtime.ts:157, and dry-run-route.ts (fixed in #4514).

Suggested fix

Fix it once at the source rather than at seven call sites: add an admission-aware accessor next to getLocalSidecarProvider() — e.g. getAdmittedLocalSidecarProvider(mode?) returning withConnectionAdmissionProvider(getLocalSidecarProvider(), LOCAL_SIDECAR_CONNECTION_ID, mode) — and route the direct consumers through it. The wrapper is idempotent in practice only if applied once, so the already-admitted sites above must keep using the raw singleton as their primary.

Worth deciding as part of this: whether embedding calls (memory recall, lorebook vectorization, the two embed endpoints) should hold a foreground slot at all, or whether admission should cover only generation. They run on the same sidecar process, which argues for including them.

Acceptance

  • The listed sidecar consumers acquire an admission slot under LOCAL_SIDECAR_CONNECTION_ID.
  • No path is wrapped twice.
  • Regression covering both the bypass and accidental double wrapping.
  • Manually verify a background caller targeting the sidecar is deferred while a foreground sidecar generation is running.

Context

  • Follow-up to #4514, where this was recorded as a known gap in the PR description.
  • Related review finding: F3 ("Five local-sidecar foreground paths bypass admission") — the count here is seven after re-verification against the merged code.
Originally created by @Gunterlie on GitHub (Aug 3, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/4520 Originally assigned to: @Gunterlie on GitHub. ## Summary PR #4514 added connection admission (foreground work always proceeds; background work yields to it and waits out an idle window) and wired the Noodle schedulers as the first background producers. Every path that resolves a *remote* connection is admitted, because it either passes `connectionId` to `createLLMProvider` or goes through `withConnectionFallbackProvider`. The **local-sidecar branches are not**: they hand out the raw `getLocalSidecarProvider()` singleton with no wrapper. The result is that all local-sidecar work is invisible to admission — it neither registers as foreground activity nor yields as background. ## Impact Today this is latent, since only the Noodle schedulers produce background mode and they run on regular connections. It becomes a real defect as soon as any background caller targets the sidecar, or when sidecar foreground work should be blocking background work: - Scheduled/background work can start while a foreground local-model operation is running, and both contend for the one llama.cpp process. - Foreground sidecar work does not set `lastForegroundFinishedAt`, so the 30s post-generation idle window never applies to it. ## Verified call sites (as of `1b6ddb3`) Unadmitted local-sidecar providers: - `packages/server/src/services/capability-packages/capability-language-model.service.ts:61` — capability LLM host - `packages/server/src/services/professor-mari/workspace-agent.service.ts:832` — Professor Mari workspace agent - `packages/server/src/services/memory-recall-embedding.ts:122` — memory recall embeddings - `packages/server/src/routes/lorebooks.routes.ts:1179` — lorebook vectorization - `packages/server/src/services/generation/agent-resolution.ts:315` — cached sidecar agent provider - `packages/server/src/routes/generate/sidecar.routes.ts:202` — direct sidecar embed endpoint - `packages/server/src/routes/generate/raw-route.ts:415` — raw-route embed Already admitted, listed so they are not touched: `provider-generation-runtime.ts:203`, `retry-agents-route.ts:1408` and `raw-route.ts:236` (via `withConnectionFallbackProvider`), `chat-summary/connection-resolution.ts:100`, `illustrator-prompt-runtime.ts:74`, `image-captioning-runtime.ts:157`, and `dry-run-route.ts` (fixed in #4514). ## Suggested fix Fix it once at the source rather than at seven call sites: add an admission-aware accessor next to `getLocalSidecarProvider()` — e.g. `getAdmittedLocalSidecarProvider(mode?)` returning `withConnectionAdmissionProvider(getLocalSidecarProvider(), LOCAL_SIDECAR_CONNECTION_ID, mode)` — and route the direct consumers through it. The wrapper is idempotent in practice only if applied once, so the already-admitted sites above must keep using the raw singleton as their primary. Worth deciding as part of this: whether embedding calls (memory recall, lorebook vectorization, the two embed endpoints) should hold a foreground slot at all, or whether admission should cover only generation. They run on the same sidecar process, which argues for including them. ## Acceptance - [ ] The listed sidecar consumers acquire an admission slot under `LOCAL_SIDECAR_CONNECTION_ID`. - [ ] No path is wrapped twice. - [ ] Regression covering both the bypass and accidental double wrapping. - [ ] Manually verify a background caller targeting the sidecar is deferred while a foreground sidecar generation is running. ## Context - Follow-up to #4514, where this was recorded as a known gap in the PR description. - Related review finding: F3 ("Five local-sidecar foreground paths bypass admission") — the count here is seven after re-verification against the merged code.
bsakaguchi 2026-10-21 05:48:25 +07:00
  • closed this issue
  • added the
    server
    bug
    labels
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#2462
No description provided.