[GH-ISSUE #2466] [Issue]: Setting a connection as default does not clear the previous default (multiple isDefault connections) #1210

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

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

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Severity: Medium — correctness regression. Marking a connection as the global default (isDefault) never clears the previous default, so multiple connections end up with isDefault: true and the no-connection fallback resolves to whichever sorts first — not the one the user just picked.

Expected behavior

isDefault is a singleton: setting a new default should unset isDefault on every other connection, so exactly one connection is the fallback. Main enforces this on both create and update.

Actual behavior

storage_create and storage_update for connections call only clear_other_default_agent_connections, which de-duplicates defaultForAgents (a per-agent-category flag) — it never touches the general isDefault:

// src-tauri/src/commands/storage/commands/entities.rs:717 (create) / :778 (update)
clear_other_default_agent_connections(state, &created)?;  // only clears defaultForAgents (:1356-1392)
// no helper clears other connections' isDefault anywhere in the storage tree

isDefault is the fallback used whenever a request supplies no connectionId: resolve_llm_connection_for_request (llm.rs) returns the first isDefault match in storage order, and many frontend services do the same first-match-wins pick (generation/context.ts, scene-service.ts, use-chats.ts, combat-init, schedule.service, auto-summary, use-magic-rewrite, encounter-service). With two isDefault:true rows the resolution is order-dependent, so background/auto operations can silently use the stale connection (wrong provider/model/key).

Steps to reproduce

  1. Mark connection A as default.
  2. Mark connection B as default (create-as-default or update isDefault → true).
  3. Both rows now have isDefault: true; the no-connectionId fallback resolves to whichever sorts first (A), not B.

Impact area

  • App shell, navigation, startup, or providers
  • Catalog resources
  • Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime

Environment

  • Branch or commit: refactor @ 1fae2c42
  • Run mode: Tauri desktop
  • OS + version: found via static source audit (not runtime-reproduced)
  • Node + pnpm versions: n/a (static audit)
  • Rust version, if relevant: n/a (static audit)
  • Remote Runtime URL configured? not relevant
  • Provider, model, or integration, if relevant: any multi-connection setup

Logs, screenshots, or video

Static trace: entities.rs:716-721 (create), :772-779 (update), clear_other_default_agent_connections :1356-1392 (only defaultForAgents), fallback resolver llm.rs resolve_llm_connection_for_request.

Regression notes

Regression vs main. packages/server/src/services/storage/connections.storage.ts (create ~48-49, update ~113-117) runs db.update(apiConnections).set({ isDefault: "false" }) before setting the new default. The refactor dropped that singleton enforcement for isDefault (it kept it for defaultForAgents).

Additional context

Fix (fix-pattern-already-in-repo): add a clear_other_default_connections helper mirroring clear_other_default_agent_connections but patching isDefault: false on every other connection, invoked from the create/update branches when the saved connection has truthy isDefault. The prompt-preset singleton path already follows this pattern in prompts.rs.

Template check

Please uncheck 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 @Romuromylus on GitHub (Jun 6, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2466 Originally assigned to: @SpicyMarinara on GitHub. ## Summary **Severity: Medium — correctness regression.** Marking a connection as the global default (`isDefault`) never clears the previous default, so multiple connections end up with `isDefault: true` and the no-connection fallback resolves to whichever sorts first — not the one the user just picked. ## Expected behavior `isDefault` is a singleton: setting a new default should unset `isDefault` on every other connection, so exactly one connection is the fallback. Main enforces this on both create and update. ## Actual behavior `storage_create` and `storage_update` for connections call only `clear_other_default_agent_connections`, which de-duplicates `defaultForAgents` (a per-agent-category flag) — it never touches the general `isDefault`: ```rust // src-tauri/src/commands/storage/commands/entities.rs:717 (create) / :778 (update) clear_other_default_agent_connections(state, &created)?; // only clears defaultForAgents (:1356-1392) // no helper clears other connections' isDefault anywhere in the storage tree ``` `isDefault` is the fallback used whenever a request supplies no `connectionId`: `resolve_llm_connection_for_request` (`llm.rs`) returns the first `isDefault` match in storage order, and many frontend services do the same first-match-wins pick (`generation/context.ts`, `scene-service.ts`, `use-chats.ts`, `combat-init`, `schedule.service`, `auto-summary`, `use-magic-rewrite`, `encounter-service`). With two `isDefault:true` rows the resolution is order-dependent, so background/auto operations can silently use the stale connection (wrong provider/model/key). ## Steps to reproduce 1. Mark connection A as default. 2. Mark connection B as default (create-as-default or update `isDefault → true`). 3. Both rows now have `isDefault: true`; the no-`connectionId` fallback resolves to whichever sorts first (A), not B. ## Impact area - [x] App shell, navigation, startup, or providers - [x] Catalog resources - [x] Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime ## Environment - Branch or commit: refactor @ 1fae2c42 - Run mode: Tauri desktop - OS + version: found via static source audit (not runtime-reproduced) - Node + pnpm versions: n/a (static audit) - Rust version, if relevant: n/a (static audit) - Remote Runtime URL configured? not relevant - Provider, model, or integration, if relevant: any multi-connection setup ## Logs, screenshots, or video Static trace: `entities.rs:716-721` (create), `:772-779` (update), `clear_other_default_agent_connections` `:1356-1392` (only `defaultForAgents`), fallback resolver `llm.rs` `resolve_llm_connection_for_request`. ## Regression notes Regression vs main. `packages/server/src/services/storage/connections.storage.ts` (create ~48-49, update ~113-117) runs `db.update(apiConnections).set({ isDefault: "false" })` before setting the new default. The refactor dropped that singleton enforcement for `isDefault` (it kept it for `defaultForAgents`). ## Additional context Fix (fix-pattern-already-in-repo): add a `clear_other_default_connections` helper mirroring `clear_other_default_agent_connections` but patching `isDefault: false` on every other connection, invoked from the create/update branches when the saved connection has truthy `isDefault`. The prompt-preset singleton path already follows this pattern in `prompts.rs`. ## Template check Please uncheck 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.
bsakaguchi 2026-10-21 05:29:06 +07:00
Author
Owner

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

Fixed on refactor in 038b7220.

Setting a connection as default now clears isDefault/default on the other connections before saving the new default.

Verification: pnpm typecheck; pnpm build; pnpm check:architecture; cargo check --manifest-path src-tauri/Cargo.toml --workspace; focused Rust backup/profile tests; git diff --check; no .test.ts/.test.tsx files present.

<!-- gh-comment-id:4638721454 --> @SpicyMarinara commented on GitHub (Jun 6, 2026): Fixed on refactor in 038b7220. Setting a connection as default now clears isDefault/default on the other connections before saving the new default. Verification: pnpm typecheck; pnpm build; pnpm check:architecture; cargo check --manifest-path src-tauri/Cargo.toml --workspace; focused Rust backup/profile tests; git diff --check; no .test.ts/.test.tsx files present.
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#1210
No description provided.