[PR #1206] [MERGED] Fix dangling connection deletes #4980

Closed
opened 2026-10-22 04:12:12 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/1206
Author: @cha1latte
Created: 5/25/2026
Status: ✅ Merged
Merged: 5/25/2026
Merged by: @cha1latte

Base: staging ← Head: fix/issue-1129-dangling-connections


📝 Commits (2)

  • 003963b Fix dangling connection deletes
  • d252c28 Address connection delete review feedback

📊 Changes

5 files changed (+201 additions, -51 deletions)

View changed files

📝 packages/server/src/routes/connections.routes.ts (+26 -2)
📝 packages/server/src/routes/generate.routes.ts (+57 -32)
📝 packages/server/src/routes/generate/agent-connection-guards.ts (+15 -1)
📝 packages/server/src/routes/generate/retry-agents-route.ts (+30 -16)
➕ packages/server/src/services/storage/connection-references.storage.ts (+73 -0)

📄 Description

Linked issue

Closes #1129

Why this change

Deleting a connection that is still referenced by agents or chats left dead connectionId values behind. During generation/retry, those dead agent references could silently fall through to the chat connection, which could route agent calls to a provider the user thought they had moved away from.

This is the staging-port equivalent of the behavior already merged to the refactor branch in #1130.

What changed

  • Added a server-side connection reference helper for agent_configs.connection_id and chats.connection_id.
  • Changed DELETE /api/connections/:id to return 409 connection_in_use with referencing agents/chats unless ?force=true is supplied.
  • Changed forced connection delete to clear referencing agent/chat connectionId values before deleting the connection.
  • Added a dangling_agent_connection warning and skip path in normal generation, smart Response Orchestrator resolution, and retry-agent resolution so missing agent connections no longer silently use the chat connection.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Codex-run proof:

  • Before fix: packages\server\node_modules\.bin\tsx.cmd scratch\issue-1129-repro.ts reproduced the bug: delete returned 204, connection lookup returned 404, and the agent/chat still stored the deleted ID.
  • After fix: packages\server\node_modules\.bin\tsx.cmd scratch\issue-1129-repro.ts --expect-fixed passed: referenced delete returns 409 connection_in_use, lists the agent/chat references, and leaves the connection intact.
  • Edge: packages\server\node_modules\.bin\tsx.cmd scratch\issue-1129-repro.ts --expect-force passed: ?force=true clears the agent/chat references and deletes the connection.
  • Edge: packages\server\node_modules\.bin\tsx.cmd scratch\issue-1129-repro.ts --expect-no-refs passed: unreferenced delete still returns 204 and removes the connection.
  • Edge: packages\server\node_modules\.bin\tsx.cmd scratch\issue-1129-runtime-warning.ts passed: retry-agent resolution emits dangling_agent_connection and skips the missing-connection agent without emitting an agent_result.
  • pnpm check passed locally.
  • pnpm --filter @marinara-engine/server test passed locally: 51 tests.
  • node C:\Users\celia\.codex\tools\marinara-proof-gate.mjs scratch\bugfix-verification.json passed.
  • Bunny review pass completed before opening the PR.

Manual verification notes

  • No browser-only verification is required for the core claim; the changed behavior is server API/storage/runtime resolution and was exercised with Fastify/file-storage scratch harnesses.
  • Optional human spot-check: in the app, assign an agent to a connection, try deleting that connection from Settings → Connections, and confirm the delete surfaces the server conflict instead of removing the connection.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Version/release files updated (only if this PR includes a version bump)

No docs, schema, dependency, version, or release metadata changes.

UI evidence (if applicable)

N/A - backend API/storage/runtime fix with command proof above.

Summary by CodeRabbit

  • New Features
    • Added ability to force-delete connections while clearing all references; API now returns conflict error with reference list when deletion would affect dependent agents/chats.
    • Improved detection and handling of misconfigured agents with unavailable connections; system now skips these agents with informative warnings instead of failing silently.

Review Change Stack


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/1206 **Author:** [@cha1latte](https://github.com/cha1latte) **Created:** 5/25/2026 **Status:** ✅ Merged **Merged:** 5/25/2026 **Merged by:** [@cha1latte](https://github.com/cha1latte) **Base:** `staging` ← **Head:** `fix/issue-1129-dangling-connections` --- ### 📝 Commits (2) - [`003963b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/003963be9e168b7f4e0f2e75c48d044c3cb200c2) Fix dangling connection deletes - [`d252c28`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d252c28b91529c31c4ab818e6cd47c25a321779a) Address connection delete review feedback ### 📊 Changes **5 files changed** (+201 additions, -51 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/routes/connections.routes.ts` (+26 -2) 📝 `packages/server/src/routes/generate.routes.ts` (+57 -32) 📝 `packages/server/src/routes/generate/agent-connection-guards.ts` (+15 -1) 📝 `packages/server/src/routes/generate/retry-agents-route.ts` (+30 -16) ➕ `packages/server/src/services/storage/connection-references.storage.ts` (+73 -0) </details> ### 📄 Description <!-- Target branch: `staging`. The default base in this UI is `main` (release branch). --> <!-- Change the base to `staging` before submitting unless this is a maintainer-approved mainline change. --> <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Closes #1129 ## Why this change Deleting a connection that is still referenced by agents or chats left dead `connectionId` values behind. During generation/retry, those dead agent references could silently fall through to the chat connection, which could route agent calls to a provider the user thought they had moved away from. This is the staging-port equivalent of the behavior already merged to the `refactor` branch in #1130. ## What changed - Added a server-side connection reference helper for `agent_configs.connection_id` and `chats.connection_id`. - Changed `DELETE /api/connections/:id` to return `409 connection_in_use` with referencing agents/chats unless `?force=true` is supplied. - Changed forced connection delete to clear referencing agent/chat `connectionId` values before deleting the connection. - Added a `dangling_agent_connection` warning and skip path in normal generation, smart Response Orchestrator resolution, and retry-agent resolution so missing agent connections no longer silently use the chat connection. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` Codex-run proof: - Before fix: `packages\server\node_modules\.bin\tsx.cmd scratch\issue-1129-repro.ts` reproduced the bug: delete returned `204`, connection lookup returned `404`, and the agent/chat still stored the deleted ID. - After fix: `packages\server\node_modules\.bin\tsx.cmd scratch\issue-1129-repro.ts --expect-fixed` passed: referenced delete returns `409 connection_in_use`, lists the agent/chat references, and leaves the connection intact. - Edge: `packages\server\node_modules\.bin\tsx.cmd scratch\issue-1129-repro.ts --expect-force` passed: `?force=true` clears the agent/chat references and deletes the connection. - Edge: `packages\server\node_modules\.bin\tsx.cmd scratch\issue-1129-repro.ts --expect-no-refs` passed: unreferenced delete still returns `204` and removes the connection. - Edge: `packages\server\node_modules\.bin\tsx.cmd scratch\issue-1129-runtime-warning.ts` passed: retry-agent resolution emits `dangling_agent_connection` and skips the missing-connection agent without emitting an `agent_result`. - `pnpm check` passed locally. - `pnpm --filter @marinara-engine/server test` passed locally: 51 tests. - `node C:\Users\celia\.codex\tools\marinara-proof-gate.mjs scratch\bugfix-verification.json` passed. - Bunny review pass completed before opening the PR. ### Manual verification notes - No browser-only verification is required for the core claim; the changed behavior is server API/storage/runtime resolution and was exercised with Fastify/file-storage scratch harnesses. - Optional human spot-check: in the app, assign an agent to a connection, try deleting that connection from Settings → Connections, and confirm the delete surfaces the server conflict instead of removing the connection. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Version/release files updated (only if this PR includes a version bump) No docs, schema, dependency, version, or release metadata changes. ## UI evidence (if applicable) N/A - backend API/storage/runtime fix with command proof above. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added ability to force-delete connections while clearing all references; API now returns conflict error with reference list when deletion would affect dependent agents/chats. * Improved detection and handling of misconfigured agents with unavailable connections; system now skips these agents with informative warnings instead of failing silently. <!-- review_stack_entry_start --> [![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/Pasta-Devs/Marinara-Engine/pull/1206?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack) <!-- review_stack_entry_end --> <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:12:12 +07:00
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#4980
No description provided.