[GH-ISSUE #1129] [Issue]: Deleting a connection leaves agents pointing at the dead ID, then silently runs them on the chat's connection #560

Closed
opened 2026-10-20 17:30:11 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @etherious1804 on GitHub (May 24, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1129

Originally assigned to: @cha1latte on GitHub.

Summary

DELETE /api/connections/:id removes a connection without checking or updating agent/chat records that reference it. Agents whose connectionId becomes dangling then silently fall back to the chat's connection at runtime, which can route paid-API traffic to a connection the user thought they had migrated away from.

Expected behavior

Either:

  • Block the delete with 409 Conflict and return the list of referencing agents/chats so the user can repoint them first (preferred — explicit user intent), or
  • Cascade the delete by nulling referencing connectionIds and surfacing a clear warning that those agents now use the chat connection.

In addition, at generation time, an agent whose connectionId no longer resolves should emit a visible warning (the existing AgentConnectionWarning channel already exists for related cases — local_sidecar_unavailable, default_agent_connection_active).

Actual behavior

  1. DELETE /api/connections/:id succeeds with 204 regardless of how many agents reference it (packages/server/src/routes/connections.routes.ts:222-225).
  2. On the next generation turn, resolveAgentConnectionId(...) happily returns the dangling ID (packages/server/src/routes/generate/agent-connection-guards.ts:17-27 — it doesn't validate existence).
  3. The call site at packages/server/src/routes/generate.routes.ts:3120-3144 looks up the connection with connections.getWithKey(effectiveConnectionId). When that returns null for a dangling ID, the if (agentConn) { ... } block is skipped silently. agentProvider/agentModel keep the chat connection's values that were initialized just above, so the agent transparently runs on the chat's connection — including its API key, model, and rate-limit profile.

User-visible symptom: agents start failing with errors like OpenAI API error 429: Provider returned error from a provider the user thought they had stopped using. No warning, no log line tying the failure to a missing connection ID.

Steps to reproduce

  1. Create two API connections, e.g. local (OAI-compatible/local model) and default (OpenRouter or any rate-limited paid API).
  2. In Agent settings, point one or more enabled agents at default.
  3. Delete the default connection from Settings → Connections (or curl -X DELETE /api/connections/:id).
  4. (Optional) Use the UI to switch the agents to local. Verify in the network/storage layer that the change actually persisted to agentConfigs.connectionId — in my case it did not, leaving the dangling reference.
  5. Send a chat message. Post-processing agents fire.
  6. Observe: agents that were "pointed at local" actually run on the chat connection (e.g. kimmi/OpenRouter). No warning is shown. If the chat connection is rate-limited, you get [agent-pipeline] Group REJECTED in phase "post_processing": [...] err: OpenAI API error 429.

Confirmed locally on my install by inspecting the agents via the API: 20 agents all had connectionId: "1QqiMpyBCCaRVd4Scjm30"; GET /api/connections/1QqiMpyBCCaRVd4Scjm30 returns {"error":"Connection not found"}.

Environment

  • Marinara Engine version: 1.6.0
  • Install type: source (staging)
  • Browser: Chrome
  • OS: macOS

Notes for a fix

Two layers should change together:

  1. Connection delete (packages/server/src/routes/connections.routes.ts:222): before removing, count references in agentConfigs.connectionId (and the equivalent default-agent-connection setting if applicable). If > 0, return 409 with the list of referencing agent names/IDs. Accept ?force=true to override; on force, null out the references and emit a warning in the response. This mirrors typical FK ON-DELETE-RESTRICT semantics.

  2. Runtime resolution (packages/server/src/routes/generate.routes.ts around line 3120): when connections.getWithKey(effectiveConnectionId) returns null, add an AgentConnectionWarning (new code, e.g. dangling_agent_connection) to agentConnectionWarnings and either skip the agent or fall back explicitly to the chat connection — but never silently. The user must see that the configured connection no longer exists.

Happy to put up a PR for the above approach if it sounds right.

Originally created by @etherious1804 on GitHub (May 24, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1129 Originally assigned to: @cha1latte on GitHub. ## Summary `DELETE /api/connections/:id` removes a connection without checking or updating agent/chat records that reference it. Agents whose `connectionId` becomes dangling then silently fall back to the chat's connection at runtime, which can route paid-API traffic to a connection the user thought they had migrated away from. ## Expected behavior Either: - Block the delete with `409 Conflict` and return the list of referencing agents/chats so the user can repoint them first (preferred — explicit user intent), **or** - Cascade the delete by nulling referencing `connectionId`s and surfacing a clear warning that those agents now use the chat connection. In addition, at generation time, an agent whose `connectionId` no longer resolves should emit a visible warning (the existing `AgentConnectionWarning` channel already exists for related cases — `local_sidecar_unavailable`, `default_agent_connection_active`). ## Actual behavior 1. `DELETE /api/connections/:id` succeeds with `204` regardless of how many agents reference it (`packages/server/src/routes/connections.routes.ts:222-225`). 2. On the next generation turn, `resolveAgentConnectionId(...)` happily returns the dangling ID (`packages/server/src/routes/generate/agent-connection-guards.ts:17-27` — it doesn't validate existence). 3. The call site at `packages/server/src/routes/generate.routes.ts:3120-3144` looks up the connection with `connections.getWithKey(effectiveConnectionId)`. When that returns `null` for a dangling ID, the `if (agentConn) { ... }` block is skipped silently. `agentProvider`/`agentModel` keep the chat connection's values that were initialized just above, so the agent transparently runs on the chat's connection — including its API key, model, and rate-limit profile. User-visible symptom: agents start failing with errors like `OpenAI API error 429: Provider returned error` from a provider the user thought they had stopped using. No warning, no log line tying the failure to a missing connection ID. ## Steps to reproduce 1. Create two API connections, e.g. `local` (OAI-compatible/local model) and `default` (OpenRouter or any rate-limited paid API). 2. In Agent settings, point one or more enabled agents at `default`. 3. Delete the `default` connection from Settings → Connections (or `curl -X DELETE /api/connections/:id`). 4. (Optional) Use the UI to switch the agents to `local`. Verify in the network/storage layer that the change actually persisted to `agentConfigs.connectionId` — in my case it did not, leaving the dangling reference. 5. Send a chat message. Post-processing agents fire. 6. Observe: agents that were "pointed at local" actually run on the chat connection (e.g. `kimmi`/OpenRouter). No warning is shown. If the chat connection is rate-limited, you get `[agent-pipeline] Group REJECTED in phase "post_processing": [...] err: OpenAI API error 429`. Confirmed locally on my install by inspecting the agents via the API: 20 agents all had `connectionId: "1QqiMpyBCCaRVd4Scjm30"`; `GET /api/connections/1QqiMpyBCCaRVd4Scjm30` returns `{"error":"Connection not found"}`. ## Environment - Marinara Engine version: 1.6.0 - Install type: source (staging) - Browser: Chrome - OS: macOS ## Notes for a fix Two layers should change together: 1. **Connection delete** (`packages/server/src/routes/connections.routes.ts:222`): before removing, count references in `agentConfigs.connectionId` (and the equivalent default-agent-connection setting if applicable). If `> 0`, return `409` with the list of referencing agent names/IDs. Accept `?force=true` to override; on force, null out the references and emit a warning in the response. This mirrors typical FK ON-DELETE-RESTRICT semantics. 2. **Runtime resolution** (`packages/server/src/routes/generate.routes.ts` around line 3120): when `connections.getWithKey(effectiveConnectionId)` returns null, add an `AgentConnectionWarning` (new code, e.g. `dangling_agent_connection`) to `agentConnectionWarnings` and either skip the agent or fall back explicitly to the chat connection — but never silently. The user must see that the configured connection no longer exists. Happy to put up a PR for the above approach if it sounds right.
Author
Owner

@cha1latte commented on GitHub (May 25, 2026):

Closed in #1206

<!-- gh-comment-id:4537138605 --> @cha1latte commented on GitHub (May 25, 2026): Closed in #1206
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#560
No description provided.