[GH-ISSUE #2771] [Issue]: Provider/model switch keeps stale fields; API key carried across a provider switch #1408

Closed
opened 2026-10-21 05:33:19 +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/2771

Originally assigned to: @SpicyMarinara on GitHub.

Summary

The provider/model-switch handlers in ConnectionEditor reset some fields but leave others stale, producing wrong context budgets, wrong auth, or stale output caps after a switch.

Sub-bug 1: Provider switch keeps stale maxContext (new-bug / missed-instance of #2660)

(a) The provider-button onClick clears model and resets maxTokensOverride, but only re-seeds localMaxContext for the xai branch. Switching from a large-window model to a smaller provider, then typing a model id in the manual input (which bypasses selectModel), saves the old maxContext. Server-side resolveModelAccessPolicy caps it down for KNOWN models, so impact is limited to UNKNOWN/custom models where the stale window disables trimming -> over-budget request / provider 400.
(c) ConnectionEditor.tsx:884-904 (xai-only re-seed at 895-897), compare selectModel 709-716; manual input 1304-1307/1406-1418. Kind: missed-instance (low/medium).

Sub-bug 2: Stale API key across provider switch (new-bug)

(a) On load the key field is blanked (masked). The provider switch clears the key only for claude_subscription/openai_chatgpt; for any other key-based provider it leaves the field blank, so handleSave omits apiKey and the server keeps the OLD provider's encrypted key under the new provider -> 401 on first generation (e.g. an OpenAI sk- key sent as Anthropic x-api-key). The key is masked/encrypted, so no leak — a misleading-state/wrong-request bug, self-correcting once a new key is typed.
(c) ConnectionEditor.tsx:221 (blank on load), 884-904 (clears key only for 2 providers at 900-902), 412-415 (apiKey omitted when blank); connections.storage.ts:114-204 (only writes apiKeyEncrypted when provided, no provider-change revalidation). Kind: new-bug (medium).

Sub-bug 3: Stale remote maxOutput override after manual model change (new-bug)

(a) selectModel writes model.maxOutput into the hard maxTokensOverride for remote models; the manual model-id input only sets localModel, so the override stays pinned to the previous model's cap (server Math.min), silently capping the new model's output. Field is visible/editable -> low.
(c) ConnectionEditor.tsx:709-716, 1407-1419; server applyProviderMaxTokensOverride generation-parameters.ts:15-17. Kind: new-bug (low).

Suggested Fix

  • On provider switch, also reset localMaxContext (seed from MODEL_LISTS[key][0]?.context or a conservative default), mirroring the maxTokensOverride reset.
  • On provider switch to a different key-based provider, clear localApiKey (and surface a 'enter a new key for this provider' hint).
  • Clear/recompute maxTokensOverride when the model changes via the manual text input (or treat maxOutput as a soft hint).

Template

  • Provider switch resets maxContext
  • Provider switch clears the API key for key-based providers
  • Manual model change reconciles maxTokensOverride
  • pnpm check passes

Affected files

  • packages/client/src/components/connections/ConnectionEditor.tsx
  • packages/server/src/services/storage/connections.storage.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: MEDIUM.

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/2771 Originally assigned to: @SpicyMarinara on GitHub. ## Summary The provider/model-switch handlers in ConnectionEditor reset some fields but leave others stale, producing wrong context budgets, wrong auth, or stale output caps after a switch. ## Sub-bug 1: Provider switch keeps stale maxContext (new-bug / missed-instance of #2660) **(a)** The provider-button onClick clears model and resets `maxTokensOverride`, but only re-seeds `localMaxContext` for the xai branch. Switching from a large-window model to a smaller provider, then typing a model id in the manual input (which bypasses `selectModel`), saves the old maxContext. Server-side `resolveModelAccessPolicy` caps it down for KNOWN models, so impact is limited to UNKNOWN/custom models where the stale window disables trimming -> over-budget request / provider 400. **(c)** ConnectionEditor.tsx:884-904 (xai-only re-seed at 895-897), compare selectModel 709-716; manual input 1304-1307/1406-1418. Kind: missed-instance (low/medium). ## Sub-bug 2: Stale API key across provider switch (new-bug) **(a)** On load the key field is blanked (masked). The provider switch clears the key only for claude_subscription/openai_chatgpt; for any other key-based provider it leaves the field blank, so handleSave omits apiKey and the server keeps the OLD provider's encrypted key under the new provider -> 401 on first generation (e.g. an OpenAI `sk-` key sent as Anthropic x-api-key). The key is masked/encrypted, so no leak — a misleading-state/wrong-request bug, self-correcting once a new key is typed. **(c)** ConnectionEditor.tsx:221 (blank on load), 884-904 (clears key only for 2 providers at 900-902), 412-415 (apiKey omitted when blank); connections.storage.ts:114-204 (only writes apiKeyEncrypted when provided, no provider-change revalidation). Kind: new-bug (medium). ## Sub-bug 3: Stale remote maxOutput override after manual model change (new-bug) **(a)** `selectModel` writes `model.maxOutput` into the hard `maxTokensOverride` for remote models; the manual model-id input only sets `localModel`, so the override stays pinned to the previous model's cap (server `Math.min`), silently capping the new model's output. Field is visible/editable -> low. **(c)** ConnectionEditor.tsx:709-716, 1407-1419; server applyProviderMaxTokensOverride generation-parameters.ts:15-17. Kind: new-bug (low). ## Suggested Fix - On provider switch, also reset `localMaxContext` (seed from MODEL_LISTS[key][0]?.context or a conservative default), mirroring the maxTokensOverride reset. - On provider switch to a different key-based provider, clear `localApiKey` (and surface a 'enter a new key for this provider' hint). - Clear/recompute `maxTokensOverride` when the model changes via the manual text input (or treat maxOutput as a soft hint). ## Template - [ ] Provider switch resets maxContext - [ ] Provider switch clears the API key for key-based providers - [ ] Manual model change reconciles maxTokensOverride - [ ] `pnpm check` passes --- ### Affected files - `packages/client/src/components/connections/ConnectionEditor.tsx` - `packages/server/src/services/storage/connections.storage.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: **MEDIUM**. > 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- Provider switches now reset maxContext from the new provider's first known model, or the app default when there is no known model.\n- Provider switches clear the visible API key field and mark the stored encrypted key to be cleared on the next save, unless the user types a replacement key.\n- Clicking the already-selected provider no longer resets fields.\n- Manual model ID edits now clear stale maxTokensOverride values, while selecting a known/fetched model still applies its context/output hints.\n\nDeferred pnpm/check validation until the end of the issue sweep per maintainer request.

<!-- gh-comment-id:4763406863 --> @SpicyMarinara commented on GitHub (Jun 21, 2026): Fixed in PR #2747.\n\nWhat changed:\n- Provider switches now reset maxContext from the new provider's first known model, or the app default when there is no known model.\n- Provider switches clear the visible API key field and mark the stored encrypted key to be cleared on the next save, unless the user types a replacement key.\n- Clicking the already-selected provider no longer resets fields.\n- Manual model ID edits now clear stale maxTokensOverride values, while selecting a known/fetched model still applies its context/output hints.\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#1408
No description provided.