[GH-ISSUE #2770] [Issue]: Connection/preset save-failure swallowing — handleSave never re-throws, so close/test/save-and-close proceed on a failed save (silent data loss) #1409

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/2770

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Multiple editors treat await handleSave() / .mutate(...) as if a failed save aborts the next action, but the save handlers catch their own error and resolve normally (or fire-and-forget), so close/test/export proceed on a failed save and edits are silently lost with no error surfaced.

Sub-bug 1: ConnectionEditor test actions run after a swallowed save (new-bug)

(a) All five action handlers gate on if (dirty) { try { await handleSave(); } catch { return; } }, but handleSave catches its mutation error and only calls setSaveError then returns — never re-throws. So the catch { return } is dead code and Test/Message/Fetch-Models/Diagnose/Test-Image run against the UN-updated server record, reporting success for settings that were never persisted.
(b) Set maxContext=0 (or a bad Base URL), click Test Connection -> save 400s silently, a green 'Success' card appears for unsaved settings.
(c) ConnectionEditor.tsx:379-441 (handleSave catch at 439-441, no re-throw), 583-707 (the five handlers). Kind: new-bug.

Sub-bug 2: ConnectionEditor 'Save & close' closes on failed save (new-bug)

(a) async () => { await handleSave(); closeConnectionDetail(); } — since handleSave never throws, close runs unconditionally; the editor unmounts before the saveError banner shows and all local edits are discarded.
(c) ConnectionEditor.tsx:830-838, 439-441. Kind: new-bug.

Sub-bug 3: PresetEditor 'Save & close' closes before mutation resolves (data-loss/new-bug)

(a) Save & close calls handleSave() (fire-and-forget .mutate, onSuccess only, no onError) then closePresetDetail() synchronously. On a 400 (e.g. empty name) nothing persists, the editor unmounts, and all unsaved Overview edits are lost with no error. (Success path is harmless — the in-flight PATCH still completes.)
(c) PresetEditor.tsx:436-444, 237-256. Kind: new-bug.

Sub-bug 4: Empty/invalid name & variable fields fail silently (validation/new-bug)

(a) Clearing the preset name, or emptying/over-filling a variable name/question/separator, sends a PATCH the server rejects (min(1)/max(...)); useUpdatePreset/useUpdateVariable have only onSuccess (no onError), and the global QueryClient has no mutation error handler, so the failure is silent. The success-path invalidation never runs, so other unsaved edits are also dropped and the bad value sticks in the controlled input.
(c) PresetEditor.tsx:363-372 (name input), 2050-2071 (var name), 2134-2156 (question), 1813-1819 (separator); prompt.schema.ts:149/103-112; use-presets.ts:86-97/289-303; main.tsx:13-21. Kind: new-bug (validation).

Suggested Fix

  • Make handleSave signal failure: setSaveError(msg); throw err; (or return a boolean) so the existing catch { return } / close guards work. Gate close on success.
  • PresetEditor: use mutateAsync and only close on success; keep editor open + toast on failure.
  • Add onError toasts to useUpdatePreset/useUpdateVariable (and/or a global MutationCache onError). Guard empty/over-long name client-side (disable Save / revert-on-empty like SectionNameInput); add maxLength to variable name/question/separator inputs.

Template

  • handleSave re-throws / returns failure; callers abort on failed save
  • Save & close keeps editor open on failure
  • Empty/invalid name & variable fields surface an error (no silent drop)
  • Manually verify a failed connection save no longer shows a green test 'Success'
  • pnpm check passes

Affected files

  • packages/client/src/components/connections/ConnectionEditor.tsx
  • packages/client/src/components/presets/PresetEditor.tsx
  • packages/client/src/hooks/use-presets.ts
  • packages/client/src/hooks/use-connections.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/2770 Originally assigned to: @SpicyMarinara on GitHub. ## Summary Multiple editors treat `await handleSave()` / `.mutate(...)` as if a failed save aborts the next action, but the save handlers catch their own error and resolve normally (or fire-and-forget), so close/test/export proceed on a failed save and edits are silently lost with no error surfaced. ## Sub-bug 1: ConnectionEditor test actions run after a swallowed save (new-bug) **(a)** All five action handlers gate on `if (dirty) { try { await handleSave(); } catch { return; } }`, but `handleSave` catches its mutation error and only calls `setSaveError` then returns — never re-throws. So the `catch { return }` is dead code and Test/Message/Fetch-Models/Diagnose/Test-Image run against the UN-updated server record, reporting success for settings that were never persisted. **(b)** Set maxContext=0 (or a bad Base URL), click Test Connection -> save 400s silently, a green 'Success' card appears for unsaved settings. **(c)** ConnectionEditor.tsx:379-441 (handleSave catch at 439-441, no re-throw), 583-707 (the five handlers). Kind: new-bug. ## Sub-bug 2: ConnectionEditor 'Save & close' closes on failed save (new-bug) **(a)** `async () => { await handleSave(); closeConnectionDetail(); }` — since handleSave never throws, close runs unconditionally; the editor unmounts before the saveError banner shows and all local edits are discarded. **(c)** ConnectionEditor.tsx:830-838, 439-441. Kind: new-bug. ## Sub-bug 3: PresetEditor 'Save & close' closes before mutation resolves (data-loss/new-bug) **(a)** Save & close calls `handleSave()` (fire-and-forget `.mutate`, onSuccess only, no onError) then `closePresetDetail()` synchronously. On a 400 (e.g. empty name) nothing persists, the editor unmounts, and all unsaved Overview edits are lost with no error. (Success path is harmless — the in-flight PATCH still completes.) **(c)** PresetEditor.tsx:436-444, 237-256. Kind: new-bug. ## Sub-bug 4: Empty/invalid name & variable fields fail silently (validation/new-bug) **(a)** Clearing the preset name, or emptying/over-filling a variable name/question/separator, sends a PATCH the server rejects (min(1)/max(...)); `useUpdatePreset`/`useUpdateVariable` have only onSuccess (no onError), and the global QueryClient has no mutation error handler, so the failure is silent. The success-path invalidation never runs, so other unsaved edits are also dropped and the bad value sticks in the controlled input. **(c)** PresetEditor.tsx:363-372 (name input), 2050-2071 (var name), 2134-2156 (question), 1813-1819 (separator); prompt.schema.ts:149/103-112; use-presets.ts:86-97/289-303; main.tsx:13-21. Kind: new-bug (validation). ## Suggested Fix - Make handleSave signal failure: `setSaveError(msg); throw err;` (or return a boolean) so the existing `catch { return }` / close guards work. Gate close on success. - PresetEditor: use mutateAsync and only close on success; keep editor open + toast on failure. - Add onError toasts to useUpdatePreset/useUpdateVariable (and/or a global MutationCache onError). Guard empty/over-long name client-side (disable Save / revert-on-empty like SectionNameInput); add maxLength to variable name/question/separator inputs. ## Template - [ ] handleSave re-throws / returns failure; callers abort on failed save - [ ] Save & close keeps editor open on failure - [ ] Empty/invalid name & variable fields surface an error (no silent drop) - [ ] Manually verify a failed connection save no longer shows a green test 'Success' - [ ] `pnpm check` passes --- ### Affected files - `packages/client/src/components/connections/ConnectionEditor.tsx` - `packages/client/src/components/presets/PresetEditor.tsx` - `packages/client/src/hooks/use-presets.ts` - `packages/client/src/hooks/use-connections.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- ConnectionEditor handleSave now rethrows after setting saveError, so Test Connection/Test Message/Diagnose/Test Image/Fetch Models and Save & close abort when the save fails.\n- ConnectionEditor Save & close catches failed saves and keeps the editor open.\n- PresetEditor handleSave now uses mutateAsync, validates empty preset names client-side, and only shows the saved state after the PATCH succeeds.\n- PresetEditor Save & close awaits save success before closing and keeps the editor open on failure.\n- Preset update and variable create/update mutations now surface validation failures with toast errors instead of failing silently.\n\nDeferred pnpm/check validation until the end of the issue sweep per maintainer request.

<!-- gh-comment-id:4763402426 --> @SpicyMarinara commented on GitHub (Jun 21, 2026): Fixed in PR #2747.\n\nWhat changed:\n- ConnectionEditor handleSave now rethrows after setting saveError, so Test Connection/Test Message/Diagnose/Test Image/Fetch Models and Save & close abort when the save fails.\n- ConnectionEditor Save & close catches failed saves and keeps the editor open.\n- PresetEditor handleSave now uses mutateAsync, validates empty preset names client-side, and only shows the saved state after the PATCH succeeds.\n- PresetEditor Save & close awaits save success before closing and keeps the editor open on failure.\n- Preset update and variable create/update mutations now surface validation failures with toast errors instead of failing silently.\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#1409
No description provided.