[GH-ISSUE #2772] [Issue]: Connection & agent transfer/import — dangling/stale connection ids and hijacked routing flags (isDefault/defaultForAgents) #1412

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

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

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Connection import/export and agent connection-override handling carry machine-local routing state across transfers and never reconcile deleted/invalid connection ids, producing hijacked defaults, dangling references, and silently re-saved dead ids.

Sub-bug 1: Import hijacks isDefault/defaultForAgents/useForRandom onto a keyless import (new-bug)

(a) Export emits these routing flags; import passes them through verbatim while forcing apiKey:'' . storage.create honors isDefault (unsets all other defaults) and defaultForAgents, so re-importing your default connection silently demotes your real key-bearing default and points global/agent default at a keyless connection -> next generation/agent 401s.
(c) connection-transfer.ts:106-108/142-146; ImportConnectionModal.tsx:47; connections.storage.ts:55-80. Kind: new-bug (high).

Sub-bug 2: Import carries promptPresetId/embeddingConnectionId (missed-instance)

(a) These machine-local relational ids survive transfer; on another machine they dangle, so the connection appears to have a preset but generation falls back (warn), and embeddings point at a missing connection.
(c) connection-transfer.ts:113/119/140/149; stored with no FK validation. Kind: missed-instance (low).

Sub-bug 3: Deleting active chat's connection leaves dangling chat.connectionId (new-bug)

(a) Row/bulk delete only invalidates the connections list; it never clears the chat's connectionId. The main generate path then can't resolve the dead id and returns HTTP 400 'API connection not found' (no default fallback) until the user reassigns.
(c) ConnectionsPanel.tsx:667/852/1065; use-connections.ts:98-104; connections.routes.ts:311-314; generate.routes.ts:1281-1302. Kind: new-bug (medium).

Sub-bug 4-6: AgentEditor stale/invalid connection-override ids (new-bug/missed-instance)

(a) Image override (Illustrator/Tracker/Background) loads imageConnectionId with no validation; a deleted id has no matching so the select shows 'None' while state keeps the dead id, and Save re-persists it -> server throws a hard agent error. Text override has the identical pattern (re-saves dead id; runtime safely skips). On lite builds a hidden __local_sidecar__ id is re-saved while the UI shows 'Use chat connection'.
(c) AgentEditor.tsx:516/822/937 (image), 507/902 (text), 1733 (lite sidecar gate). Kind: missed-instance/new-bug.

Sub-bug 7-10: duplicate/import edge cases

  • duplicate() copies useForRandom (forces isDefault/defaultForAgents false but not this), silently doubling a pool member's selection weight (connections.storage.ts:222) — low/ux.
  • Import maxParallelJobs uses unbounded asPositiveInteger; >16 fails the server .max(16) and, because the file loop shares one try, discards every other entry in the file (connection-transfer.ts:121/226-230; ImportConnectionModal.tsx:43-71) — low/validation.
  • An entry that creates the connection then fails saving defaultParameters orphans the created connection and aborts remaining entries (ImportConnectionModal.tsx:43-58) — low/validation.
  • Export scrubSecrets recurses into user customParameters and deletes keys named secret/password/authorization/etc., dropping legitimate request params on round-trip (connection-transfer.ts:171-200) — low/new-bug.

Suggested Fix

  • On import, force isDefault:false, defaultForAgents:false, useForRandom:false, promptPresetId:null, embeddingConnectionId:null (machine-local routing/relational state must not transfer).
  • On connection delete, if it equals the active chat's connectionId, clear it (or fall back to default) and invalidate the chat query.
  • AgentEditor: on populate, validate connection/image-connection override ids against the live list and clear/disable-option a missing id (also normalize __local_sidecar__ away on lite builds).
  • Clamp import maxParallelJobs to MAX_PARALLEL_JOBS; wrap each import entry in its own try/catch (per-entry accounting; roll back or save defaults before marking imported).
  • duplicate(): force useForRandom:false. Limit secret scrubbing to top-level auth fields, not nested customParameters.

Template

  • Import resets routing/relational flags (no default hijack, no dangling preset/embed refs)
  • Deleting the active chat's connection reconciles chat.connectionId
  • Agent override stale/deleted/sidecar ids reconciled in the editor
  • Import maxParallelJobs clamped; per-entry error isolation; no orphans
  • customParameters survive export/import; duplicate is inert in the random pool
  • pnpm check passes

Affected files

  • packages/client/src/lib/connection-transfer.ts
  • packages/client/src/components/modals/ImportConnectionModal.tsx
  • packages/client/src/components/agents/AgentEditor.tsx
  • packages/client/src/hooks/use-connections.ts
  • packages/server/src/services/storage/connections.storage.ts
  • packages/server/src/routes/connections.routes.ts

Audit provenance

Found by a multi-agent re-review of the connection/preset subsystem (editors UI + send-pipeline) against the merged staging tree (Round 1 + round-2 gap sweep + completeness critic, each finding adversarially verified). The prior #2656-#2668 fixes were re-verified as HELD on their primary paths. Severity: HIGH.

AI-drafted from a static read; validation/test-plan boxes intentionally left UNCHECKED for a human to verify before close.

Originally created by @kolacheee on GitHub (Jun 21, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2772 Originally assigned to: @SpicyMarinara on GitHub. ## Summary Connection import/export and agent connection-override handling carry machine-local routing state across transfers and never reconcile deleted/invalid connection ids, producing hijacked defaults, dangling references, and silently re-saved dead ids. ## Sub-bug 1: Import hijacks isDefault/defaultForAgents/useForRandom onto a keyless import (new-bug) **(a)** Export emits these routing flags; import passes them through verbatim while forcing apiKey:'' . `storage.create` honors `isDefault` (unsets all other defaults) and `defaultForAgents`, so re-importing your default connection silently demotes your real key-bearing default and points global/agent default at a keyless connection -> next generation/agent 401s. **(c)** connection-transfer.ts:106-108/142-146; ImportConnectionModal.tsx:47; connections.storage.ts:55-80. Kind: new-bug (high). ## Sub-bug 2: Import carries promptPresetId/embeddingConnectionId (missed-instance) **(a)** These machine-local relational ids survive transfer; on another machine they dangle, so the connection appears to have a preset but generation falls back (warn), and embeddings point at a missing connection. **(c)** connection-transfer.ts:113/119/140/149; stored with no FK validation. Kind: missed-instance (low). ## Sub-bug 3: Deleting active chat's connection leaves dangling chat.connectionId (new-bug) **(a)** Row/bulk delete only invalidates the connections list; it never clears the chat's connectionId. The main generate path then can't resolve the dead id and returns HTTP 400 'API connection not found' (no default fallback) until the user reassigns. **(c)** ConnectionsPanel.tsx:667/852/1065; use-connections.ts:98-104; connections.routes.ts:311-314; generate.routes.ts:1281-1302. Kind: new-bug (medium). ## Sub-bug 4-6: AgentEditor stale/invalid connection-override ids (new-bug/missed-instance) **(a)** Image override (Illustrator/Tracker/Background) loads `imageConnectionId` with no validation; a deleted id has no matching <option> so the select shows 'None' while state keeps the dead id, and Save re-persists it -> server throws a hard agent error. Text override has the identical pattern (re-saves dead id; runtime safely skips). On lite builds a hidden `__local_sidecar__` id is re-saved while the UI shows 'Use chat connection'. **(c)** AgentEditor.tsx:516/822/937 (image), 507/902 (text), 1733 (lite sidecar gate). Kind: missed-instance/new-bug. ## Sub-bug 7-10: duplicate/import edge cases - duplicate() copies `useForRandom` (forces isDefault/defaultForAgents false but not this), silently doubling a pool member's selection weight (connections.storage.ts:222) — low/ux. - Import `maxParallelJobs` uses unbounded `asPositiveInteger`; >16 fails the server `.max(16)` and, because the file loop shares one try, discards every other entry in the file (connection-transfer.ts:121/226-230; ImportConnectionModal.tsx:43-71) — low/validation. - An entry that creates the connection then fails saving defaultParameters orphans the created connection and aborts remaining entries (ImportConnectionModal.tsx:43-58) — low/validation. - Export `scrubSecrets` recurses into user `customParameters` and deletes keys named secret/password/authorization/etc., dropping legitimate request params on round-trip (connection-transfer.ts:171-200) — low/new-bug. ## Suggested Fix - On import, force `isDefault:false, defaultForAgents:false, useForRandom:false, promptPresetId:null, embeddingConnectionId:null` (machine-local routing/relational state must not transfer). - On connection delete, if it equals the active chat's connectionId, clear it (or fall back to default) and invalidate the chat query. - AgentEditor: on populate, validate connection/image-connection override ids against the live list and clear/disable-option a missing id (also normalize `__local_sidecar__` away on lite builds). - Clamp import `maxParallelJobs` to MAX_PARALLEL_JOBS; wrap each import entry in its own try/catch (per-entry accounting; roll back or save defaults before marking imported). - duplicate(): force `useForRandom:false`. Limit secret scrubbing to top-level auth fields, not nested customParameters. ## Template - [ ] Import resets routing/relational flags (no default hijack, no dangling preset/embed refs) - [ ] Deleting the active chat's connection reconciles chat.connectionId - [ ] Agent override stale/deleted/sidecar ids reconciled in the editor - [ ] Import maxParallelJobs clamped; per-entry error isolation; no orphans - [ ] customParameters survive export/import; duplicate is inert in the random pool - [ ] `pnpm check` passes --- ### Affected files - `packages/client/src/lib/connection-transfer.ts` - `packages/client/src/components/modals/ImportConnectionModal.tsx` - `packages/client/src/components/agents/AgentEditor.tsx` - `packages/client/src/hooks/use-connections.ts` - `packages/server/src/services/storage/connections.storage.ts` - `packages/server/src/routes/connections.routes.ts` ### Audit provenance Found by a multi-agent re-review of the connection/preset subsystem (editors UI + send-pipeline) against the merged `staging` tree (Round 1 + round-2 gap sweep + completeness critic, each finding adversarially verified). The prior #2656-#2668 fixes were re-verified as HELD on their primary paths. Severity: **HIGH**. > AI-drafted from a static read; validation/test-plan boxes intentionally left UNCHECKED for a human to verify before close.
Author
Owner

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

Fixed in PR #2747.\n\nWhat changed:\n- Connection imports now force machine-local routing/relationship fields to safe values: isDefault/defaultForAgents/useForRandom false, promptPresetId and embeddingConnectionId null.\n- Imported maxParallelJobs is clamped to the server-supported maximum.\n- Connection import processes entries independently, reports skipped entries, and rolls back a newly-created connection if saving its defaultParameters fails.\n- Connection defaultParameters export/import no longer recursively strips nested customParameters keys named like secrets; only top-level secret-ish fields are scrubbed.\n- Duplicated connections no longer copy useForRandom.\n- Deleting the active chat's assigned connection clears that chat's connectionId and updates/invalidate chat cache.\n- AgentEditor normalizes stale text/image connection override IDs on hydrate and save, including clearing the hidden local-sidecar ID on lite builds.\n\nDeferred pnpm/check validation until the end of the issue sweep per maintainer request.

<!-- gh-comment-id:4763416650 --> @SpicyMarinara commented on GitHub (Jun 21, 2026): Fixed in PR #2747.\n\nWhat changed:\n- Connection imports now force machine-local routing/relationship fields to safe values: isDefault/defaultForAgents/useForRandom false, promptPresetId and embeddingConnectionId null.\n- Imported maxParallelJobs is clamped to the server-supported maximum.\n- Connection import processes entries independently, reports skipped entries, and rolls back a newly-created connection if saving its defaultParameters fails.\n- Connection defaultParameters export/import no longer recursively strips nested customParameters keys named like secrets; only top-level secret-ish fields are scrubbed.\n- Duplicated connections no longer copy useForRandom.\n- Deleting the active chat's assigned connection clears that chat's connectionId and updates/invalidate chat cache.\n- AgentEditor normalizes stale text/image connection override IDs on hydrate and save, including clearing the hidden local-sidecar ID on lite builds.\n\nDeferred pnpm/check validation until the end of the issue sweep per maintainer request.
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#1412
No description provided.