[GH-ISSUE #2719] [Issue]: Local sidecar params not backend-aware (min_p dropped; MLX allows tool calls with no support, ignores contextSize/thinking-disable/json_schema) #1364

Closed
opened 2026-10-21 05:32:23 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @kolacheee on GitHub (Jun 21, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2719

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Local request building is not parameter-complete or backend-aware. top_k is plumbed for the local backend but its sibling sampler min_p is dropped; and the MLX backend is handed tool requests, llama.cpp-specific params, and a non-standard json_schema envelope it cannot honor, plus its context-size setting and restart signature ignore the user's config.


1. Preset min_p silently dropped for the local sidecar (medium)

How it breaks the pipeline: Min-P is a primary sampler for local models, but ChatOptions has no minP field and OpenAIProvider never emits body.min_p, so a user's preset Min-P is ignored on the only backend (llama-server /v1/chat/completions) that natively honors it — diverging from SillyTavern and the preset display.

Steps to replicate: Set Min-P in a preset, generate via the local sidecar; sampling ignores it (top_k, the sibling sampler, is honored).

Trace: ChatOptions declares topK but no minP (base-provider.ts:85-135). The body special-cases top_k for local via shouldSendTopK() (openai.provider.ts:871/1104, true for apiKey==='local-sidecar') but has no min_p branch. applyRuntimeSettings only forwards maxTokens/temperature/topP/topK (local-sidecar.provider.ts:41-56). The preset value is salvaged (generate-route-utils.ts:829) and imported (st-prompt.importer.ts:97) but never read back out.

Suggested Fix: Add minP to ChatOptions, plumb it through applyRuntimeSettings, and emit body.min_p guarded by a shouldSendMinP() (true for local-sidecar) when options.minP is finite in [0,1].


2. MLX accepts tool requests with no tool support (low)

How it breaks the pipeline: assertToolCallsAvailable only blocks tools for llama_cpp; for mlx it returns without checking, so tools flow to mlx_lm.server (launched with no jinja/tools flags). For the curated default Gemma model, emitted tool delimiters are never parsed, so tool_calls stays empty and agents silently produce no tool actions — unlike the clear guard llama.cpp users get.

Steps to replicate: On Apple Silicon with the default MLX model, run a tool-bearing agent; no tool calls ever happen, with no actionable error.

Trace: assertToolCallsAvailable early-returns unless backend is 'llama_cpp' (local-sidecar.provider.ts:31-39). buildMlxArgs launches with no tool/jinja flags (sidecar-process.service.ts:358-360). OpenAIProvider still attaches body.tools and parses tool_calls; with none returned, toolCalls is [].

Suggested Fix: Extend assertToolCallsAvailable to reject/warn when backend==='mlx' and options.tools?.length, mirroring the llama.cpp guard.


3. config.contextSize dropped on MLX (medium)

How it breaks the pipeline: buildMlxArgs never translates contextSize to an MLX flag, so mlx_lm.server runs at its built-in default while the client budgets prompts to the configured window. Worse, contextSize is omitted from the MLX restart signature, so changing it never restarts the server.

Steps to replicate: On MLX, raise contextSize and run a long scene/tracker; it truncates/rejects, and the running server is not restarted by the change.

Trace: buildMlxArgs returns only -m/--model/--host/--port (sidecar-process.service.ts:358-360); the MLX signature is {backend, pythonPath, modelRef} with no contextSize (411-418), so the early-return guard (273) skips the restart. The chat path budgets to config.contextSize via OpenAIProvider.fitMessagesToContext (local-sidecar.provider.ts:20-21).

Suggested Fix: Map contextSize to the appropriate mlx_lm.server argument (and include it in the MLX restart signature so a change triggers a restart), or clamp Marinara's prompt budget to mlx_lm.server's actual default.


4. MLX startup-failure auto-restart re-download loop (low)

How it breaks the pipeline: Because MLX markReady() fires on the early /v1/models 200 (before the model loads), a load-time crash (OOM, slow partial HF download) lands >30s after ready, so the crashedSoonAfterReady guard resets unexpectedCrashCount to 1 every cycle and never trips the >1 cap — an unbounded restart/re-fetch loop instead of a stable error.

Steps to replicate: On MLX, cause a slow load failure (OOM after a multi-GB load); the sidecar keeps re-launching and re-fetching weights.

Trace: crashedSoonAfterReady = lastReadyAt>0 && now-lastReadyAt<30_000 (sidecar-process.service.ts:721); unexpectedCrashCount = crashedSoonAfterReady ? +1 : 1 (722); if (>1) server_error; return; (724) never trips; line 731 restarts. markReady refreshes lastReadyAt each cycle.

Suggested Fix: Tie readiness to a real MLX load so lastReadyAt reflects a loaded model, and/or use a wall-clock/backoff repeated-failure guard that accounts for MLX's long load window.


5. MLX request bodies not backend-aware (low)

How it breaks the pipeline: Scene/tracker/test bodies send llama.cpp-shaped params verbatim to mlx_lm.server. The decisive defect is the structured-output envelope: analyzeScene sends {type:'json_schema', schema} (schema at top level), and mlx_lm.server has no structured-output support at all, so the constraint is dropped and scene analysis degrades to unconstrained JSON on MLX.

Steps to replicate: On Apple Silicon run Game-Mode scene analysis; output is unconstrained prose-ish JSON that intermittently fails to parse.

Trace: runTestMessage always sends reasoning_format:'none' + chat_template_kwargs (sidecar-inference.service.ts:282-283); analyzeScene passes {type:'json_schema', schema: SCENE_ANALYSIS_SCHEMA} (499-502); streamChatCompletion forwards verbatim with no backend branch (170). mlx_lm.server (upstream main) never reads response_format.

Suggested Fix: Branch request bodies on getResolvedBackend(); for MLX emit only supported params and either the standard OpenAI envelope or document that schema enforcement is unavailable so callers degrade gracefully.


Affected files

  • packages/server/src/services/llm/providers/openai.provider.ts
  • packages/server/src/services/llm/base-provider.ts
  • packages/server/src/services/llm/providers/local-sidecar.provider.ts
  • packages/server/src/services/sidecar/sidecar-process.service.ts
  • packages/server/src/services/sidecar/sidecar-inference.service.ts
  • packages/server/src/services/sidecar/sidecar-launch-plan.ts

Audit provenance

Found by a multi-agent static audit of the sidecar/local-model subsystem (Round 1 + round-2 gap sweep + completeness critic, each finding adversarially verified). Severity: MEDIUM. Line numbers are against the staging working tree.

Originally created by @kolacheee on GitHub (Jun 21, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2719 Originally assigned to: @SpicyMarinara on GitHub. ## Summary Local request building is not parameter-complete or backend-aware. `top_k` is plumbed for the local backend but its sibling sampler `min_p` is dropped; and the MLX backend is handed tool requests, llama.cpp-specific params, and a non-standard json_schema envelope it cannot honor, plus its context-size setting and restart signature ignore the user's config. --- ### 1. Preset min_p silently dropped for the local sidecar (medium) **How it breaks the pipeline:** Min-P is a primary sampler for local models, but `ChatOptions` has no `minP` field and `OpenAIProvider` never emits `body.min_p`, so a user's preset Min-P is ignored on the only backend (llama-server `/v1/chat/completions`) that natively honors it — diverging from SillyTavern and the preset display. **Steps to replicate:** Set Min-P in a preset, generate via the local sidecar; sampling ignores it (top_k, the sibling sampler, is honored). **Trace:** `ChatOptions` declares `topK` but no `minP` (base-provider.ts:85-135). The body special-cases `top_k` for local via `shouldSendTopK()` (openai.provider.ts:871/1104, true for `apiKey==='local-sidecar'`) but has no `min_p` branch. `applyRuntimeSettings` only forwards maxTokens/temperature/topP/topK (local-sidecar.provider.ts:41-56). The preset value is salvaged (generate-route-utils.ts:829) and imported (st-prompt.importer.ts:97) but never read back out. **Suggested Fix:** Add `minP` to `ChatOptions`, plumb it through `applyRuntimeSettings`, and emit `body.min_p` guarded by a `shouldSendMinP()` (true for local-sidecar) when `options.minP` is finite in [0,1]. --- ### 2. MLX accepts tool requests with no tool support (low) **How it breaks the pipeline:** `assertToolCallsAvailable` only blocks tools for `llama_cpp`; for `mlx` it returns without checking, so tools flow to `mlx_lm.server` (launched with no jinja/tools flags). For the curated default Gemma model, emitted tool delimiters are never parsed, so `tool_calls` stays empty and agents silently produce no tool actions — unlike the clear guard llama.cpp users get. **Steps to replicate:** On Apple Silicon with the default MLX model, run a tool-bearing agent; no tool calls ever happen, with no actionable error. **Trace:** `assertToolCallsAvailable` early-returns unless backend is 'llama_cpp' (local-sidecar.provider.ts:31-39). `buildMlxArgs` launches with no tool/jinja flags (sidecar-process.service.ts:358-360). `OpenAIProvider` still attaches `body.tools` and parses `tool_calls`; with none returned, `toolCalls` is `[]`. **Suggested Fix:** Extend `assertToolCallsAvailable` to reject/warn when `backend==='mlx'` and `options.tools?.length`, mirroring the llama.cpp guard. --- ### 3. config.contextSize dropped on MLX (medium) **How it breaks the pipeline:** `buildMlxArgs` never translates `contextSize` to an MLX flag, so `mlx_lm.server` runs at its built-in default while the client budgets prompts to the configured window. Worse, `contextSize` is omitted from the MLX restart signature, so changing it never restarts the server. **Steps to replicate:** On MLX, raise contextSize and run a long scene/tracker; it truncates/rejects, and the running server is not restarted by the change. **Trace:** `buildMlxArgs` returns only `-m/--model/--host/--port` (sidecar-process.service.ts:358-360); the MLX signature is `{backend, pythonPath, modelRef}` with no contextSize (411-418), so the early-return guard (273) skips the restart. The chat path budgets to `config.contextSize` via `OpenAIProvider.fitMessagesToContext` (local-sidecar.provider.ts:20-21). **Suggested Fix:** Map `contextSize` to the appropriate `mlx_lm.server` argument (and include it in the MLX restart signature so a change triggers a restart), or clamp Marinara's prompt budget to mlx_lm.server's actual default. --- ### 4. MLX startup-failure auto-restart re-download loop (low) **How it breaks the pipeline:** Because MLX `markReady()` fires on the early `/v1/models` 200 (before the model loads), a load-time crash (OOM, slow partial HF download) lands >30s after ready, so the `crashedSoonAfterReady` guard resets `unexpectedCrashCount` to 1 every cycle and never trips the >1 cap — an unbounded restart/re-fetch loop instead of a stable error. **Steps to replicate:** On MLX, cause a slow load failure (OOM after a multi-GB load); the sidecar keeps re-launching and re-fetching weights. **Trace:** `crashedSoonAfterReady = lastReadyAt>0 && now-lastReadyAt<30_000` (sidecar-process.service.ts:721); `unexpectedCrashCount = crashedSoonAfterReady ? +1 : 1` (722); `if (>1) server_error; return;` (724) never trips; line 731 restarts. `markReady` refreshes `lastReadyAt` each cycle. **Suggested Fix:** Tie readiness to a real MLX load so `lastReadyAt` reflects a loaded model, and/or use a wall-clock/backoff repeated-failure guard that accounts for MLX's long load window. --- ### 5. MLX request bodies not backend-aware (low) **How it breaks the pipeline:** Scene/tracker/test bodies send llama.cpp-shaped params verbatim to `mlx_lm.server`. The decisive defect is the structured-output envelope: `analyzeScene` sends `{type:'json_schema', schema}` (schema at top level), and mlx_lm.server has no structured-output support at all, so the constraint is dropped and scene analysis degrades to unconstrained JSON on MLX. **Steps to replicate:** On Apple Silicon run Game-Mode scene analysis; output is unconstrained prose-ish JSON that intermittently fails to parse. **Trace:** `runTestMessage` always sends `reasoning_format:'none'` + `chat_template_kwargs` (sidecar-inference.service.ts:282-283); `analyzeScene` passes `{type:'json_schema', schema: SCENE_ANALYSIS_SCHEMA}` (499-502); `streamChatCompletion` forwards verbatim with no backend branch (170). mlx_lm.server (upstream main) never reads `response_format`. **Suggested Fix:** Branch request bodies on `getResolvedBackend()`; for MLX emit only supported params and either the standard OpenAI envelope or document that schema enforcement is unavailable so callers degrade gracefully. --- ### Affected files - `packages/server/src/services/llm/providers/openai.provider.ts` - `packages/server/src/services/llm/base-provider.ts` - `packages/server/src/services/llm/providers/local-sidecar.provider.ts` - `packages/server/src/services/sidecar/sidecar-process.service.ts` - `packages/server/src/services/sidecar/sidecar-inference.service.ts` - `packages/server/src/services/sidecar/sidecar-launch-plan.ts` ### Audit provenance Found by a multi-agent static audit of the sidecar/local-model subsystem (Round 1 + round-2 gap sweep + completeness critic, each finding adversarially verified). Severity: **MEDIUM**. Line numbers are against the `staging` working tree.
Author
Owner

@SpicyMarinara commented on GitHub (Jun 21, 2026):

Addressed in f7a371da on the issue-sweep branch. Current code already had ChatOptions.minP and OpenAI/local min_p emission; this change makes the local sidecar wrapper preserve Min-P explicitly, blocks MLX tool calls with a clear error, strips unsupported structured-output envelopes from MLX requests, removes llama.cpp-only thinking-disable fields from MLX smoke tests, includes contextSize in the MLX runtime signature so config changes are not treated as the same process, and adds a repeated-crash window so ready/crash/restart loops are capped. I did not add a fake MLX context-size CLI flag: upstream MLX server docs list supported request fields and do not expose a context-size server option.

<!-- gh-comment-id:4761712603 --> @SpicyMarinara commented on GitHub (Jun 21, 2026): Addressed in f7a371da on the issue-sweep branch. Current code already had ChatOptions.minP and OpenAI/local min_p emission; this change makes the local sidecar wrapper preserve Min-P explicitly, blocks MLX tool calls with a clear error, strips unsupported structured-output envelopes from MLX requests, removes llama.cpp-only thinking-disable fields from MLX smoke tests, includes contextSize in the MLX runtime signature so config changes are not treated as the same process, and adds a repeated-crash window so ready/crash/restart loops are capped. I did not add a fake MLX context-size CLI flag: upstream MLX server docs list supported request fields and do not expose a context-size server option.
Author
Owner

@kolacheee commented on GitHub (Jun 21, 2026):

Reopening — partially fixed by #2730. A post-merge verification against the merged staging branch confirms the main fix landed, but a cited part of this issue remains unfixed. Residual below, verified by direct read at file:line.

Claim 3's headline defect persists on the MLX backend: the client budgets prompts to config.contextSize while mlx_lm.server runs at its built-in default. buildMlxArgs (C:/Users/Alyssa/Documents/GitHub/_marinara_staging_verify/packages/server/src/services/sidecar/sidecar-process.service.ts:433-435) sends only -m/--model/--host/--port — no context flag. Both prompt-budget paths remain backend-agnostic: inference at sidecar-inference.service.ts:209-212 (maxContext:config.contextSize) and chat at local-sidecar.provider.ts:20-21 (delegate built with config.contextSize). No MLX clamp exists in sidecar-model.service.ts getConfig() (494-496). The maintainer justifiably declined the nonexistent MLX context CLI flag but did not implement the offered alternative (clamp the prompt budget to mlx_lm.server's default), so long scenes/trackers on MLX can still over-budget and truncate/reject. Only the restart-signature sub-part is fixed (contextSize added to MLX signature at sidecar-process.service.ts:522).

<!-- gh-comment-id:4762835270 --> @kolacheee commented on GitHub (Jun 21, 2026): > **Reopening — partially fixed by #2730.** A post-merge verification against the merged staging branch confirms the main fix landed, but a cited part of this issue remains unfixed. Residual below, verified by direct read at file:line. Claim 3's headline defect persists on the MLX backend: the client budgets prompts to config.contextSize while mlx_lm.server runs at its built-in default. buildMlxArgs (C:/Users/Alyssa/Documents/GitHub/_marinara_staging_verify/packages/server/src/services/sidecar/sidecar-process.service.ts:433-435) sends only -m/--model/--host/--port — no context flag. Both prompt-budget paths remain backend-agnostic: inference at sidecar-inference.service.ts:209-212 (maxContext:config.contextSize) and chat at local-sidecar.provider.ts:20-21 (delegate built with config.contextSize). No MLX clamp exists in sidecar-model.service.ts getConfig() (494-496). The maintainer justifiably declined the nonexistent MLX context CLI flag but did not implement the offered alternative (clamp the prompt budget to mlx_lm.server's default), so long scenes/trackers on MLX can still over-budget and truncate/reject. Only the restart-signature sub-part is fixed (contextSize added to MLX signature at sidecar-process.service.ts:522).
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#1364
No description provided.