[GH-ISSUE #2683] [Issue]: Agent connection resolution silently misroutes — deleted/empty-baseUrl falls back to main chat; empty model sends model="" #1331

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

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

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Agent connection resolution has two silent failure modes that misroute agent API calls: (1) a per-agent connection that was deleted, or has an empty/unresolvable base URL, silently falls back to the main chat connection/model with no warning; (2) a default-for-agents connection with an empty model is used anyway, sending agent requests with model="".

Expected behavior

  • A per-agent connection that is deleted or unusable should produce a visible warning and either skip the agent or fall back to the default-for-agents connection (with the existing default_agent_connection_active warning) — not silently run on the user's main (often paid) chat connection/model.
  • A connection with no model should be treated as unusable for agents, not dispatched with model="".

Actual behavior

(1) resolveAgentConnectionProvider loads the agent's connection via connections.getWithKey(connectionId). Both a deleted connection (getWithKey returns null) and an empty resolved base URL fall through to return { provider: fallbackProvider, model: fallbackModel, ... } (the main chat provider/model) silently — the provider is only built inside an if (agentBaseUrl) guard, and the default_agent_connection_active warning is only emitted when the effective connection is the default-for-agents one. A dangling connectionId is trivial to produce (agent.schema.ts connectionId is z.string().nullable() with no existence validation).

(2) getDefaultForAgents returns the first non-image connection flagged defaultForAgents regardless of an empty model column (schema default ''); resolveAgentPipelineAgents caches a provider with model: defaultAgentConn.model (no empty guard), and the executor passes model='' straight into provider.chatComplete.

How it breaks the pipeline

Code trace (staging @ b826f8f4):

  • (1) packages/server/src/services/generation/agent-resolution.ts:130-155 (resolveAgentConnectionProvider; fallback at :151-155; provider built only inside if (agentBaseUrl) :132-133); warning gated at :260-262. connections.getWithKey null at connections.storage.ts:25-29. Empty baseUrl via resolveBaseUrl (generate-route-utils.ts:769-778). connectionId nullable at agent.schema.ts:49.
  • (2) connections.storage.ts:37-42 (getDefaultForAgents, no model check); agent-resolution.ts:198-215 (caches model: defaultAgentConn.model, :211); agent-executor.ts:333-344/:696-707 pass model unvalidated. Empty model → provider 400; if batched, executeAgentBatch catch marks all batch members failed.

Steps to reproduce

Deleted connection: assign a custom agent to per-agent connection A (e.g. a local model), delete A while the agent still references its id, generate → getWithKey returns null → the agent silently runs on the main chat provider/model.

Empty model: mark a connection default-for-agents but leave its model blank, enable a built-in agent with no per-agent connection → the agent request goes out with model='' and the provider rejects it (and 400s the whole batch if batched).

Suggested fix

Distinguish "no connection requested" from "connection found but unusable." When a non-null requested connectionId resolves to null (deleted), an empty base URL, or an empty/whitespace model: do not silently fall back to the main chat connection — skip the agent with an AgentConnectionWarning, or fall back to the default-for-agents connection and emit default_agent_connection_active. At minimum logger.warn the dangling/unusable connection id and skip dispatching model=''.

Environment

  • Marinara Engine version: 2.0.0 (staging @ b826f8f4)
  • Install type: source
  • OS + version: All (code-level defect, platform-independent)
  • Browser or app shell: All

Additional context

Found via a systematic multi-agent audit of the agent subsystem. Distinct from the blank-key bug (#2656): here the key is fine, but the connection identity/model is wrong. Part of a set of agent-pipeline issues filed together.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @kolacheee on GitHub (Jun 20, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2683 Originally assigned to: @SpicyMarinara on GitHub. ## Summary Agent connection resolution has two silent failure modes that misroute agent API calls: **(1)** a per-agent connection that was deleted, or has an empty/unresolvable base URL, silently falls back to the **main chat** connection/model with no warning; **(2)** a default-for-agents connection with an empty `model` is used anyway, sending agent requests with `model=""`. ## Expected behavior - A per-agent connection that is deleted or unusable should produce a visible warning and either skip the agent or fall back to the *default-for-agents* connection (with the existing `default_agent_connection_active` warning) — not silently run on the user's main (often paid) chat connection/model. - A connection with no model should be treated as unusable for agents, not dispatched with `model=""`. ## Actual behavior **(1)** `resolveAgentConnectionProvider` loads the agent's connection via `connections.getWithKey(connectionId)`. Both a deleted connection (`getWithKey` returns null) and an empty resolved base URL fall through to `return { provider: fallbackProvider, model: fallbackModel, ... }` (the main chat provider/model) silently — the provider is only built inside an `if (agentBaseUrl)` guard, and the `default_agent_connection_active` warning is only emitted when the effective connection *is* the default-for-agents one. A dangling `connectionId` is trivial to produce (`agent.schema.ts` `connectionId` is `z.string().nullable()` with no existence validation). **(2)** `getDefaultForAgents` returns the first non-image connection flagged `defaultForAgents` regardless of an empty `model` column (schema default `''`); `resolveAgentPipelineAgents` caches a provider with `model: defaultAgentConn.model` (no empty guard), and the executor passes `model=''` straight into `provider.chatComplete`. ## How it breaks the pipeline Code trace (staging @ `b826f8f4`): - (1) `packages/server/src/services/generation/agent-resolution.ts:130-155` (`resolveAgentConnectionProvider`; fallback at `:151-155`; provider built only inside `if (agentBaseUrl)` `:132-133`); warning gated at `:260-262`. `connections.getWithKey` null at `connections.storage.ts:25-29`. Empty baseUrl via `resolveBaseUrl` (`generate-route-utils.ts:769-778`). `connectionId` nullable at `agent.schema.ts:49`. - (2) `connections.storage.ts:37-42` (`getDefaultForAgents`, no model check); `agent-resolution.ts:198-215` (caches `model: defaultAgentConn.model`, `:211`); `agent-executor.ts:333-344`/`:696-707` pass `model` unvalidated. Empty model → provider 400; if batched, `executeAgentBatch` catch marks **all** batch members failed. ## Steps to reproduce **Deleted connection:** assign a custom agent to per-agent connection A (e.g. a local model), delete A while the agent still references its id, generate → `getWithKey` returns null → the agent silently runs on the main chat provider/model. **Empty model:** mark a connection `default-for-agents` but leave its `model` blank, enable a built-in agent with no per-agent connection → the agent request goes out with `model=''` and the provider rejects it (and 400s the whole batch if batched). ## Suggested fix Distinguish "no connection requested" from "connection found but unusable." When a non-null requested `connectionId` resolves to null (deleted), an empty base URL, or an empty/whitespace model: do **not** silently fall back to the main chat connection — skip the agent with an `AgentConnectionWarning`, or fall back to the default-for-agents connection and emit `default_agent_connection_active`. At minimum `logger.warn` the dangling/unusable connection id and skip dispatching `model=''`. ## Environment - Marinara Engine version: 2.0.0 (staging @ `b826f8f4`) - Install type: source - OS + version: All (code-level defect, platform-independent) - Browser or app shell: All ## Additional context Found via a systematic multi-agent audit of the agent subsystem. Distinct from the blank-key bug (#2656): here the key is fine, but the connection identity/model is wrong. Part of a set of agent-pipeline issues filed together. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
Author
Owner

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

Addressed on the issue-sweep branch. Main generation and manual agent retry now distinguish no agent connection requested from a requested/default agent connection that is deleted, has no resolvable Base URL, or has no selected model. Unusable requested/default agent connections skip the affected agents with an SSE warning instead of silently falling back to the chat model or dispatching model=""; valid default-for-agents usage still emits the existing default-agent warning. Final repo checks will run after the sweep.

<!-- gh-comment-id:4761463629 --> @SpicyMarinara commented on GitHub (Jun 21, 2026): Addressed on the issue-sweep branch. Main generation and manual agent retry now distinguish no agent connection requested from a requested/default agent connection that is deleted, has no resolvable Base URL, or has no selected model. Unusable requested/default agent connections skip the affected agents with an SSE warning instead of silently falling back to the chat model or dispatching model=""; valid default-for-agents usage still emits the existing default-agent warning. Final repo checks will run after the sweep.
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#1331
No description provided.