[GH-ISSUE #2768] [Issue]: Connection/preset editors silently discard unsaved edits via background refetch / spurious effect deps #1406

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

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Three editor data-loss bugs where in-progress, unsaved edits are silently reverted by a background refetch or a stale-state reset, with the dirty flag staying true so the user has no warning.

Sub-bug 1: PresetEditor Overview edits wiped by unrelated mutations (data-loss/new-bug)

(a) The useEffect([data]) that hydrates localName/description/wrapFormat/author/params has NO dirty guard. Any section/group/variable mutation auto-saves and invalidates presetKeys.full, the refetch yields a new data reference, the effect fires and overwrites the user's pending Overview edit with stale server values. The reorder optimistic setQueryData clobbers instantly, before any round-trip. dirty stays true so Save then persists the reverted value.
(b) Rename the preset (don't Save) -> add/reorder/edit any section -> the rename silently reverts; Save persists the old name.
(c) PresetEditor.tsx:215-227 (effect, no guard), 237-256 (handleSave); use-presets.ts:220-224 (invalidate), 244-253 (optimistic setQueryData). Kind: new-bug.

Sub-bug 2: AgentEditor reset on connections refetch (data-loss/new-bug)

(a) The populate effect sets ~50 local fields and ends with setDirty(false), and its deps array includes connections — which is NEVER read in the effect body. Any connectionKeys.list() invalidation (rename/delete/move/default-toggle/save-defaults a connection) refetches, yields a new array reference, re-runs the effect, and resets all unsaved agent edits while dbConfig is unchanged. (Window-focus does NOT trigger it — refetchOnWindowFocus:false — but explicit invalidations do.)
(b) Open the Connections panel; open an agent; make unsaved edits; rename/toggle a connection in the panel -> agent edits vanish and Save goes un-dirty.
(c) AgentEditor.tsx:498-693 (effect body, ends setDirty(false)), 693 (deps includes connections); use-connections.ts invalidations (63/72/94/102/174); use-connection-folders.ts:71. Kind: new-bug.

Sub-bug 3: PresetEditor parse-failure resets params to {} (data-loss/new-bug)

(a) If stored parameters fails JSON.parse, the populate effect catch sets localParams to {}; handleSave unconditionally sends parameters: localParams, so the next Save (even just a rename) overwrites the stored sampler overrides with {}. There is no parameter-editing UI, so localParams only diverges via this reset. Requires a genuinely malformed stored blob (corruption/legacy), so low-probability but real silent loss.
(c) PresetEditor.tsx:222-226 (catch -> {}), 246 (always sends parameters). Kind: new-bug.

Suggested Fix

  • PresetEditor: hydrate Overview/params from data only when not dirty / only on first load (ref keyed on preset id), or give Overview fields the focusedRef local-draft pattern used by SectionContentTextarea.
  • AgentEditor: remove connections from the populate effect deps (it is unused there), or key the reset on agent identity only (agentDetailId/dbConfig).
  • PresetEditor: on parse failure preserve the raw stored value (or omit parameters from the PATCH unless actually edited).

Template

  • PresetEditor Overview edits survive a background refetch/reorder
  • AgentEditor edits survive a connections-list refetch
  • Parse-failure no longer zeroes stored preset params on next save
  • pnpm check passes

Affected files

  • packages/client/src/components/presets/PresetEditor.tsx
  • packages/client/src/components/agents/AgentEditor.tsx
  • packages/client/src/hooks/use-presets.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/2768 Originally assigned to: @SpicyMarinara on GitHub. ## Summary Three editor data-loss bugs where in-progress, unsaved edits are silently reverted by a background refetch or a stale-state reset, with the dirty flag staying true so the user has no warning. ## Sub-bug 1: PresetEditor Overview edits wiped by unrelated mutations (data-loss/new-bug) **(a)** The `useEffect([data])` that hydrates localName/description/wrapFormat/author/params has NO dirty guard. Any section/group/variable mutation auto-saves and invalidates `presetKeys.full`, the refetch yields a new `data` reference, the effect fires and overwrites the user's pending Overview edit with stale server values. The reorder optimistic `setQueryData` clobbers instantly, before any round-trip. `dirty` stays true so Save then persists the reverted value. **(b)** Rename the preset (don't Save) -> add/reorder/edit any section -> the rename silently reverts; Save persists the old name. **(c)** PresetEditor.tsx:215-227 (effect, no guard), 237-256 (handleSave); use-presets.ts:220-224 (invalidate), 244-253 (optimistic setQueryData). Kind: new-bug. ## Sub-bug 2: AgentEditor reset on connections refetch (data-loss/new-bug) **(a)** The populate effect sets ~50 local fields and ends with `setDirty(false)`, and its deps array includes `connections` — which is NEVER read in the effect body. Any `connectionKeys.list()` invalidation (rename/delete/move/default-toggle/save-defaults a connection) refetches, yields a new array reference, re-runs the effect, and resets all unsaved agent edits while `dbConfig` is unchanged. (Window-focus does NOT trigger it — `refetchOnWindowFocus:false` — but explicit invalidations do.) **(b)** Open the Connections panel; open an agent; make unsaved edits; rename/toggle a connection in the panel -> agent edits vanish and Save goes un-dirty. **(c)** AgentEditor.tsx:498-693 (effect body, ends setDirty(false)), 693 (deps includes `connections`); use-connections.ts invalidations (63/72/94/102/174); use-connection-folders.ts:71. Kind: new-bug. ## Sub-bug 3: PresetEditor parse-failure resets params to {} (data-loss/new-bug) **(a)** If stored `parameters` fails JSON.parse, the populate effect catch sets localParams to {}; handleSave unconditionally sends `parameters: localParams`, so the next Save (even just a rename) overwrites the stored sampler overrides with {}. There is no parameter-editing UI, so localParams only diverges via this reset. Requires a genuinely malformed stored blob (corruption/legacy), so low-probability but real silent loss. **(c)** PresetEditor.tsx:222-226 (catch -> {}), 246 (always sends parameters). Kind: new-bug. ## Suggested Fix - PresetEditor: hydrate Overview/params from `data` only when not dirty / only on first load (ref keyed on preset id), or give Overview fields the focusedRef local-draft pattern used by SectionContentTextarea. - AgentEditor: remove `connections` from the populate effect deps (it is unused there), or key the reset on agent identity only (agentDetailId/dbConfig). - PresetEditor: on parse failure preserve the raw stored value (or omit `parameters` from the PATCH unless actually edited). ## Template - [ ] PresetEditor Overview edits survive a background refetch/reorder - [ ] AgentEditor edits survive a connections-list refetch - [ ] Parse-failure no longer zeroes stored preset params on next save - [ ] `pnpm check` passes --- ### Affected files - `packages/client/src/components/presets/PresetEditor.tsx` - `packages/client/src/components/agents/AgentEditor.tsx` - `packages/client/src/hooks/use-presets.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- PresetEditor now skips same-preset hydration while local overview edits are dirty, so unrelated refetches/reorders do not wipe drafts.\n- The dirty guard uses a ref so saving does not briefly rehydrate stale cached data before the fresh refetch arrives.\n- PresetEditor tracks parameter parse failure and omits parameters from PATCH in that case, preventing an unrelated save from overwriting malformed stored params with {}.\n- AgentEditor no longer depends on the connections array in its populate/reset effect, so connection-list refetches do not reset unsaved agent edits.\n\nDeferred pnpm/check validation until the end of the issue sweep per maintainer request.

<!-- gh-comment-id:4763393712 --> @SpicyMarinara commented on GitHub (Jun 21, 2026): Fixed in PR #2747.\n\nWhat changed:\n- PresetEditor now skips same-preset hydration while local overview edits are dirty, so unrelated refetches/reorders do not wipe drafts.\n- The dirty guard uses a ref so saving does not briefly rehydrate stale cached data before the fresh refetch arrives.\n- PresetEditor tracks parameter parse failure and omits parameters from PATCH in that case, preventing an unrelated save from overwriting malformed stored params with {}.\n- AgentEditor no longer depends on the connections array in its populate/reset effect, so connection-list refetches do not reset unsaved agent edits.\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#1406
No description provided.