[GH-ISSUE #6120] Duplicating a lorebook entry you switched off for one chat creates a copy that is switched off everywhere #3396

Closed
opened 2026-10-21 06:02:40 +07:00 by bsakaguchi · 2 comments
Owner

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

Originally assigned to: @SpicyMarinara on GitHub.

When you turn a lorebook entry off for a single chat and then duplicate that entry from inside the chat's lorebook list, the copy is created switched off in the shared lorebook itself - so it is dead in every other chat and for every character using that book. The switch you touched was labelled as affecting this chat only.

How to reproduce (try it yourself)

Use a throwaway lorebook - the last step writes to the shared book.

  1. Open Lorebooks in the left nav and create a lorebook called Harbor Lore. Add an entry: Name Dockmaster, Keys dockmaster, Content The dockmaster knows every hull. Its toggle is on - that is the shared/global flag, used by every chat and character bound to this book.
  2. Open any chat that has Harbor Lore attached (any chat mode works).
  3. In that chat, open Chat Settings, expand Lorebooks, and click Edit on Harbor Lore so the entry list appears. The Dockmaster row's switch is on, and its tooltip reads "Only affects this chat".
  4. Click that switch off. Its label is "Disable entry for this chat".
  5. Checkpoint: open the global Lorebooks page in another tab - Dockmaster is still on there. The chat switch correctly left the shared entry alone.
  6. Back in the chat's entry list, on that same Dockmaster row, click Duplicate (the copy icon at the right of the row; hover the row to reveal it on desktop, always visible on a narrow window).

What you'll see: a new row Dockmaster (Copy) appears with its switch off and greyed out, tooltip "Disabled in the shared lorebook. Enable it there before using it in this chat." You cannot turn it on from here. Open the global Lorebooks page (or any other chat using Harbor Lore) and Dockmaster (Copy) is switched off for everyone, everywhere.

What should happen: the copy should be created with the original's shared/global state - on - exactly as Dockmaster looks on the global Lorebooks page. The per-chat off state should not follow it into the shared book.

Two controls worth running: duplicating the same row from the global Lorebooks page produces an enabled copy, and duplicating from the chat with the switch left on also produces an enabled copy. Only the globally-on plus chat-off combination leaks.

Where it is

At staging 52799569c:

  • packages/client/src/components/lorebooks/LorebookEntryRow.tsx:240 - const [localEnabled, setLocalEnabled] = useState(entry.enabled && (chatEnabled?.enabled ?? true)); (re-synced the same way at :280-281)
  • packages/client/src/components/lorebooks/LorebookEntryRow.tsx:470 - enabled: localEnabled, inside the handleDuplicate payload. This is the bug.
  • packages/client/src/hooks/use-lorebooks.ts:343-355 - useDuplicateLorebookEntry forwards that payload verbatim to the shared create route POST /lorebooks/{id}/entries.
  • e2e/chat-lorebook-entry-scope.e2e.ts:117 - the existing sibling guard ("content edits cannot leak the chat's disabled flag"); there is no duplicate counterpart in the file.

What's happening

Inside a chat, the row's localEnabled is a combined value: the shared flag AND the chat's own override. The chat switch writes only the chat override (LorebookEntryRow.tsx:390-393), so the shared flag stays on while localEnabled goes off. handleDuplicate then reads that combined value and puts it in a field named enabled, which is posted straight to the shared create route - turning a chat-only choice into a permanent flag on a shared entry. The copy's own switch is then rendered disabled (:649, because the new entry is globally off), so the chat surface that caused it cannot repair it.

The rest of the duplicate payload deliberately reads live row state (name, position, depth, order, probability, regex, outlet), which is correct - those fields are single-scope and their inline edits already go to the shared entry. enabled is the only field in that payload that became dual-scope.

Suggested fix

Make the duplicate carry the source entry's shared flag rather than the row's combined display state: use entry.enabled instead of localEnabled in the handleDuplicate payload. The new entry gets a fresh id and therefore no per-chat override, so a copy of a globally-enabled entry lands enabled. Add a short comment next to the payload noting that enabled is the one dual-scope field here, so it is not "fixed" back for consistency with the other live-state reads.

Ship the coverage with it: add a case in e2e/chat-lorebook-entry-scope.e2e.ts beside the existing content-edit guard - with the chat toggle off, click Duplicate and assert the created entry's shared enabled is true. Same fixture, no extra setup. The code fix and the guard belong in one change.

Context

Introduced by PR #5981 ("keep chat entry toggles scoped to their chat"), which implemented issue #5954. The duplicate line was harmless before that PR, because the row's local state used to mean the shared flag; #5981 changed what it means and the audit of its readers stopped at the content-edit path - which is why that PR's own end-to-end test guards the content-edit leak and not this one. Unreleased on staging (latest release is v2.4.4). No existing tracker covers this.

Found by an AI-assisted sweep of merged PR #5981 against issue #5954, then re-verified against staging 52799569c on 2026-09-13. Please verify before fixing.

Originally created by @kolacheee on GitHub (Sep 13, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6120 Originally assigned to: @SpicyMarinara on GitHub. When you turn a lorebook entry off for a single chat and then duplicate that entry from inside the chat's lorebook list, the copy is created switched off in the shared lorebook itself - so it is dead in every other chat and for every character using that book. The switch you touched was labelled as affecting this chat only. ## How to reproduce (try it yourself) Use a throwaway lorebook - the last step writes to the shared book. 1. Open **Lorebooks** in the left nav and create a lorebook called `Harbor Lore`. Add an entry: Name `Dockmaster`, Keys `dockmaster`, Content `The dockmaster knows every hull.` Its toggle is on - that is the shared/global flag, used by every chat and character bound to this book. 2. Open any chat that has `Harbor Lore` attached (any chat mode works). 3. In that chat, open **Chat Settings**, expand **Lorebooks**, and click **Edit** on `Harbor Lore` so the entry list appears. The `Dockmaster` row's switch is on, and its tooltip reads "Only affects this chat". 4. Click that switch **off**. Its label is "Disable entry for this chat". 5. Checkpoint: open the global **Lorebooks** page in another tab - `Dockmaster` is still on there. The chat switch correctly left the shared entry alone. 6. Back in the chat's entry list, on that same `Dockmaster` row, click **Duplicate** (the copy icon at the right of the row; hover the row to reveal it on desktop, always visible on a narrow window). **What you'll see:** a new row `Dockmaster (Copy)` appears with its switch off and greyed out, tooltip "Disabled in the shared lorebook. Enable it there before using it in this chat." You cannot turn it on from here. Open the global Lorebooks page (or any other chat using `Harbor Lore`) and `Dockmaster (Copy)` is switched off for everyone, everywhere. **What should happen:** the copy should be created with the original's shared/global state - on - exactly as `Dockmaster` looks on the global Lorebooks page. The per-chat off state should not follow it into the shared book. Two controls worth running: duplicating the same row from the global Lorebooks page produces an enabled copy, and duplicating from the chat with the switch left on also produces an enabled copy. Only the globally-on plus chat-off combination leaks. ## Where it is At staging 52799569c: - `packages/client/src/components/lorebooks/LorebookEntryRow.tsx:240` - `const [localEnabled, setLocalEnabled] = useState(entry.enabled && (chatEnabled?.enabled ?? true));` (re-synced the same way at :280-281) - `packages/client/src/components/lorebooks/LorebookEntryRow.tsx:470` - `enabled: localEnabled,` inside the `handleDuplicate` payload. This is the bug. - `packages/client/src/hooks/use-lorebooks.ts:343-355` - `useDuplicateLorebookEntry` forwards that payload verbatim to the shared create route `POST /lorebooks/{id}/entries`. - `e2e/chat-lorebook-entry-scope.e2e.ts:117` - the existing sibling guard ("content edits cannot leak the chat's disabled flag"); there is no duplicate counterpart in the file. ## What's happening Inside a chat, the row's `localEnabled` is a combined value: the shared flag AND the chat's own override. The chat switch writes only the chat override (`LorebookEntryRow.tsx:390-393`), so the shared flag stays on while `localEnabled` goes off. `handleDuplicate` then reads that combined value and puts it in a field named `enabled`, which is posted straight to the shared create route - turning a chat-only choice into a permanent flag on a shared entry. The copy's own switch is then rendered disabled (`:649`, because the new entry is globally off), so the chat surface that caused it cannot repair it. The rest of the duplicate payload deliberately reads live row state (name, position, depth, order, probability, regex, outlet), which is correct - those fields are single-scope and their inline edits already go to the shared entry. `enabled` is the only field in that payload that became dual-scope. ## Suggested fix Make the duplicate carry the source entry's shared flag rather than the row's combined display state: use `entry.enabled` instead of `localEnabled` in the `handleDuplicate` payload. The new entry gets a fresh id and therefore no per-chat override, so a copy of a globally-enabled entry lands enabled. Add a short comment next to the payload noting that `enabled` is the one dual-scope field here, so it is not "fixed" back for consistency with the other live-state reads. Ship the coverage with it: add a case in `e2e/chat-lorebook-entry-scope.e2e.ts` beside the existing content-edit guard - with the chat toggle off, click Duplicate and assert the created entry's shared `enabled` is true. Same fixture, no extra setup. The code fix and the guard belong in one change. ## Context Introduced by PR #5981 ("keep chat entry toggles scoped to their chat"), which implemented issue #5954. The duplicate line was harmless before that PR, because the row's local state used to mean the shared flag; #5981 changed what it means and the audit of its readers stopped at the content-edit path - which is why that PR's own end-to-end test guards the content-edit leak and not this one. Unreleased on staging (latest release is v2.4.4). No existing tracker covers this. Found by an AI-assisted sweep of merged PR #5981 against issue #5954, then re-verified against staging 52799569c on 2026-09-13. Please verify before fixing.
bsakaguchi 2026-10-21 06:02:40 +07:00
Author
Owner

@SpicyMarinara commented on GitHub (Sep 13, 2026):

@SpicyMarinara is taking this report through the issue sweep in draft PR #6137, with Codex assisting. The affected current-code path has been checked; implementation and focused regression verification are in progress.

<!-- gh-comment-id:5651922969 --> @SpicyMarinara commented on GitHub (Sep 13, 2026): @SpicyMarinara is taking this report through the issue sweep in draft PR #6137, with Codex assisting. The affected current-code path has been checked; implementation and focused regression verification are in progress.
Author
Owner

@SpicyMarinara commented on GitHub (Sep 13, 2026):

Fixed in #6137, now merged to staging (e044997a2). Duplicated lore entries preserve shared enabled state and pending shared edits without copying chat overrides.

<!-- gh-comment-id:5652782724 --> @SpicyMarinara commented on GitHub (Sep 13, 2026): Fixed in #6137, now merged to staging (`e044997a2`). Duplicated lore entries preserve shared enabled state and pending shared edits without copying chat overrides.
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#3396
No description provided.