[GH-ISSUE #2983] [Issue]: Agents pinned to "Local Model" silently fall back to the paid default connection when the sidecar is unavailable #1557

Closed
opened 2026-10-21 05:39:03 +07:00 by bsakaguchi · 1 comment
Owner

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

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong
When you explicitly set an agent's connection to "Local Model (sidecar)" and the local sidecar is unavailable, the agent does not get skipped as documented. If a default agent connection is configured (the common, recommended setup), the agent is silently routed to that default connection instead. If that default is a paid API provider, you get billed for an agent you pinned to local to avoid cost, and chat/prompt data you wanted kept on-device is sent to the cloud. Only the generic "default agent connection active" warning fires; the specific Local-Model skip warning never appears. This directly contradicts the v2.0 contract in CHANGELOG.md line 509: "Agents explicitly set to Local Model are skipped with a visible warning when the sidecar is unavailable instead of silently falling back to a paid API connection."

How to reproduce (try it yourself)

  1. Mark a paid API connection as the default agent connection (defaultForAgents).
  2. Edit an agent (EditAgentModal) and set its connection to "Local Model (sidecar)".
  3. Make the sidecar unavailable (or turn its useForTrackers toggle off) so localSidecarAvailableForTrackers is false.
  4. Enable that agent for a chat and generate (also affects the retry path).

You'll see: the agent runs on the paid default connection, prompt/chat data is sent to that cloud provider, and only the generic default_agent_connection_active warning appears.
Expected: the agent is skipped with the local_sidecar_unavailable warning, exactly as the CHANGELOG states.

Where it is
packages/server/src/routes/generate/agent-connection-guards.ts:17-27, function resolveAgentConnectionId — the buggy fallback is at line 23 (return args.defaultAgentConnectionId ?? "skip-local-sidecar";). Consumed at packages/server/src/services/generation/agent-resolution.ts:298-312 (the effectiveConnectionId === "skip-local-sidecar" skip branch is bypassed) and shared on the retry path at packages/server/src/routes/generate/retry-agents-route.ts:1101-1114.

What's happening
In the sidecar-unavailable branch, resolveAgentConnectionId prefers defaultAgentConnectionId over the skip-local-sidecar sentinel. So it only returns the skip sentinel when no default agent connection exists. With a default configured, it returns that default connection's id, the skip branch at agent-resolution.ts:304 is never reached, and the agent runs on the (potentially paid) default provider. The intended contract is to ALWAYS skip when an agent explicitly requested Local Model and the sidecar is unavailable, regardless of whether a default exists.

Suggested fix
Make the sidecar-unavailable branch always skip instead of falling back. In agent-connection-guards.ts, change the body of the existing if block so it returns the sentinel unconditionally:

  if (isLocalSidecarConnectionId(args.requestedConnectionId) && !args.localSidecarAvailable) {
    return "skip-local-sidecar";
  }

  return args.requestedConnectionId ?? args.defaultAgentConnectionId ?? null;

No call-site changes are needed — both consumers (agent-resolution.ts:304, retry-agents-route.ts:1107) already handle the sentinel identically (push to skipped list, warn, continue). Verified non-regressive: non-sidecar agents and the sidecar-available happy path never enter this branch; defaultAgentConn.id can never equal the synthetic LOCAL_SIDECAR_CONNECTION_ID, so the removed fallback was always to a real stored connection. The only behavior change is the exact buggy case (sidecar-pinned + unavailable + default exists) now skips correctly.


AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.

Originally created by @kolacheee on GitHub (Jun 29, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2983 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** When you explicitly set an agent's connection to "Local Model (sidecar)" and the local sidecar is unavailable, the agent does not get skipped as documented. If a default agent connection is configured (the common, recommended setup), the agent is silently routed to that default connection instead. If that default is a paid API provider, you get billed for an agent you pinned to local to avoid cost, and chat/prompt data you wanted kept on-device is sent to the cloud. Only the generic "default agent connection active" warning fires; the specific Local-Model skip warning never appears. This directly contradicts the v2.0 contract in CHANGELOG.md line 509: "Agents explicitly set to Local Model are skipped with a visible warning when the sidecar is unavailable instead of silently falling back to a paid API connection." **How to reproduce (try it yourself)** 1. Mark a paid API connection as the default agent connection (defaultForAgents). 2. Edit an agent (EditAgentModal) and set its connection to "Local Model (sidecar)". 3. Make the sidecar unavailable (or turn its useForTrackers toggle off) so localSidecarAvailableForTrackers is false. 4. Enable that agent for a chat and generate (also affects the retry path). You'll see: the agent runs on the paid default connection, prompt/chat data is sent to that cloud provider, and only the generic `default_agent_connection_active` warning appears. Expected: the agent is skipped with the `local_sidecar_unavailable` warning, exactly as the CHANGELOG states. **Where it is** `packages/server/src/routes/generate/agent-connection-guards.ts:17-27`, function `resolveAgentConnectionId` — the buggy fallback is at line 23 (`return args.defaultAgentConnectionId ?? "skip-local-sidecar";`). Consumed at `packages/server/src/services/generation/agent-resolution.ts:298-312` (the `effectiveConnectionId === "skip-local-sidecar"` skip branch is bypassed) and shared on the retry path at `packages/server/src/routes/generate/retry-agents-route.ts:1101-1114`. **What's happening** In the sidecar-unavailable branch, `resolveAgentConnectionId` prefers `defaultAgentConnectionId` over the `skip-local-sidecar` sentinel. So it only returns the skip sentinel when no default agent connection exists. With a default configured, it returns that default connection's id, the skip branch at agent-resolution.ts:304 is never reached, and the agent runs on the (potentially paid) default provider. The intended contract is to ALWAYS skip when an agent explicitly requested Local Model and the sidecar is unavailable, regardless of whether a default exists. **Suggested fix** Make the sidecar-unavailable branch always skip instead of falling back. In `agent-connection-guards.ts`, change the body of the existing `if` block so it returns the sentinel unconditionally: ```ts if (isLocalSidecarConnectionId(args.requestedConnectionId) && !args.localSidecarAvailable) { return "skip-local-sidecar"; } return args.requestedConnectionId ?? args.defaultAgentConnectionId ?? null; ``` No call-site changes are needed — both consumers (agent-resolution.ts:304, retry-agents-route.ts:1107) already handle the sentinel identically (push to skipped list, warn, continue). Verified non-regressive: non-sidecar agents and the sidecar-available happy path never enter this branch; `defaultAgentConn.id` can never equal the synthetic LOCAL_SIDECAR_CONNECTION_ID, so the removed fallback was always to a real stored connection. The only behavior change is the exact buggy case (sidecar-pinned + unavailable + default exists) now skips correctly. --- *AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.*
bsakaguchi 2026-10-21 05:39:03 +07:00
Author
Owner

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

Fixed in merged staging PR #3004.

<!-- gh-comment-id:4832277909 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Fixed in merged staging PR #3004.
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#1557
No description provided.