[GH-ISSUE #2978] [Issue]: Entry-row inline toggles (enabled / status / regex) never roll back optimistic state on a failed PATCH #1552

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

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

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong

The entry row keeps optimistic local mirrors (localEnabled, localStatus, localUseRegex, etc.) and flips them immediately, then calls updateEntry.mutate with no onError handler. If the PATCH fails, the entries query is never invalidated (that only happens onSuccess), so the entry prop reference doesn't change and the re-sync effect never fires — the local mirror is stuck on the optimistic value with no error indication. For enabled, the toggle shows ON while the server still has it OFF, so the entry silently won't activate during a chat scan. The folder row deliberately guards this exact case with an onError rollback; the entry row's analogous activation-affecting toggle has no such guard.

How to reproduce (try it yourself)

  1. In the lorebook editor, toggle an entry's enable switch (or change its status dot, or flip the row regex button) at a moment the PATCH fails (transient network/server error, or a validation rejection).
  2. The mutation rejects; onSuccess (which invalidates lorebookKeys.entries) does not run, so the entry is not refetched.

You'll see: the row keeps displaying the optimistic value (e.g. enabled = ON) while the server kept the old value (enabled = OFF); during the next generation the entry does not activate, with no indication the change failed.
Expected: the toggle rolls back to the server value (and ideally surfaces an error), as the folder row does.

Where it is

  • packages/client/src/components/lorebooks/LorebookEntryRow.tsx:324-329 (patch, no onError), :331-338 (handleStatusChange), :348-354 (handleEnabledChange), :356-364 (handleUseRegexToggle).
  • Re-sync effect (reference-gated, never fires on a failed mutation): :231-243.
  • packages/client/src/hooks/use-lorebooks.ts:179-190 (useUpdateLorebookEntry — no onMutate/onError, only invalidates onSuccess).
  • Guarded counterpart: packages/client/src/components/lorebooks/LorebookFolderRow.tsx:97-116 (captures previous, passes onError: () => setLocalEnabled(previous)).

What's happening

patch() calls updateEntry.mutate without an onError, and the only path that reverts local state is the useEffect re-sync keyed on the entry reference. On a failed mutation the entry query is not invalidated, so entry is unchanged and the stale optimistic local value is never corrected.

Suggested fix

Mirror the folder-row pattern: capture the previous value before the optimistic flip and pass an onError that restores it (and optionally surfaces a toast), at minimum for the activation-affecting toggles (enabled, status, useRegex), e.g. const previous = localEnabled; setLocalEnabled(next); updateEntry.mutate({...}, { onError: () => setLocalEnabled(previous) });.


AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.

Originally created by @kolacheee on GitHub (Jun 29, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2978 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** The entry row keeps optimistic local mirrors (`localEnabled`, `localStatus`, `localUseRegex`, etc.) and flips them immediately, then calls `updateEntry.mutate` with no `onError` handler. If the PATCH fails, the entries query is never invalidated (that only happens onSuccess), so the `entry` prop reference doesn't change and the re-sync effect never fires — the local mirror is stuck on the optimistic value with no error indication. For `enabled`, the toggle shows ON while the server still has it OFF, so the entry silently won't activate during a chat scan. The folder row deliberately guards this exact case with an `onError` rollback; the entry row's analogous activation-affecting toggle has no such guard. **How to reproduce (try it yourself)** 1. In the lorebook editor, toggle an entry's enable switch (or change its status dot, or flip the row regex button) at a moment the PATCH fails (transient network/server error, or a validation rejection). 2. The mutation rejects; onSuccess (which invalidates `lorebookKeys.entries`) does not run, so the entry is not refetched. **You'll see:** the row keeps displaying the optimistic value (e.g. enabled = ON) while the server kept the old value (enabled = OFF); during the next generation the entry does not activate, with no indication the change failed. **Expected:** the toggle rolls back to the server value (and ideally surfaces an error), as the folder row does. **Where it is** - `packages/client/src/components/lorebooks/LorebookEntryRow.tsx:324-329` (`patch`, no `onError`), `:331-338` (`handleStatusChange`), `:348-354` (`handleEnabledChange`), `:356-364` (`handleUseRegexToggle`). - Re-sync effect (reference-gated, never fires on a failed mutation): `:231-243`. - `packages/client/src/hooks/use-lorebooks.ts:179-190` (`useUpdateLorebookEntry` — no `onMutate`/`onError`, only invalidates onSuccess). - Guarded counterpart: `packages/client/src/components/lorebooks/LorebookFolderRow.tsx:97-116` (captures `previous`, passes `onError: () => setLocalEnabled(previous)`). **What's happening** `patch()` calls `updateEntry.mutate` without an `onError`, and the only path that reverts local state is the `useEffect` re-sync keyed on the `entry` reference. On a failed mutation the entry query is not invalidated, so `entry` is unchanged and the stale optimistic local value is never corrected. **Suggested fix** Mirror the folder-row pattern: capture the previous value before the optimistic flip and pass an `onError` that restores it (and optionally surfaces a toast), at minimum for the activation-affecting toggles (`enabled`, status, `useRegex`), e.g. `const previous = localEnabled; setLocalEnabled(next); updateEntry.mutate({...}, { onError: () => setLocalEnabled(previous) });`. --- *AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.*
Author
Owner

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

Fixed in the v2.0.7 branch: inline entry toggles now roll back their local optimistic state when the PATCH fails, and drawer autosave no longer races the row-owned fields. Validated with pnpm check.

<!-- gh-comment-id:4831163680 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Fixed in the v2.0.7 branch: inline entry toggles now roll back their local optimistic state when the PATCH fails, and drawer autosave no longer races the row-owned fields. Validated with pnpm check.
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#1552
No description provided.