[GH-ISSUE #6131] Turning a spent one-shot lorebook entry back on for a chat makes it fire on every turn forever #3408

Closed
opened 2026-10-21 06:02:48 +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/6131

Originally assigned to: @SpicyMarinara on GitHub.

A lorebook entry set to fire a limited number of times (the Ephemeral field) turns its own chat switch off once it has fired that many times. If you turn that switch back on, the entry stops being limited: it fires on every single turn for the rest of that chat, and nothing turns it off again. Going back to the lorebook and setting Ephemeral again has no effect in that chat either, so there is no way to get the one-shot behaviour back.

How to reproduce (try it yourself)

  1. Sidebar -> Lorebooks. Create a lorebook named Docks lore and turn ON its Global switch.
  2. Add an entry: name Dockmaster rumor, Keys dock, Content THE DOCKMASTER WHISPERS ABOUT THE TIDE. (all caps so you can spot it in the prompt). Expand the entry and, in the Timing group (Sticky / Cooldown / Delay / Ephemeral), set Ephemeral to 1, leave Sticky at 0. Save.
  3. Open a chat the book applies to. Send: I walk to the dock. The entry fires - the all-caps line appears in the world-info block of the prompt inspector.
  4. Send I walk to the dock. again. It does not fire. Correct - it was a one-shot.
  5. Reload the page (F5). This step is needed: an ordinary turn does not refresh the chat's cached settings, so a drawer left open can still show the switch as on.
  6. Open the chat settings gear -> Lorebooks -> the pencil button on Docks lore (Edit lorebook entries). The Dockmaster rumor switch is now OFF, with no explanation of why.
  7. Click that switch back ON.
  8. Send I walk to the dock. four more times.
  9. Then go back to the shared lorebook and set that entry's Ephemeral to 1 again. Return to the chat and send I walk to the dock. twice more.

What you'll see: from step 8 onward the entry fires on every turn, the switch never turns itself off again, and the re-authored Ephemeral value in step 9 changes nothing - it still fires every turn.

What should happen: an entry the author marked Ephemeral 1 should fire at most once more after being re-enabled and then switch itself off again, or the switch should tell the player that turning it on makes this entry constant for the chat. Re-setting Ephemeral in the lorebook should at minimum take effect.

Where it is

At staging 52799569c:

  • packages/server/src/services/lorebook/index.ts:1296-1303 - when the countdown runs out the chat override is written as { ephemeral: 0, enabled: false }, and the decrement guard is a.entry.ephemeral > 0.
  • packages/server/src/services/lorebook/index.ts:1135-1137 - if (ov && ov.ephemeral !== undefined) return { ...e, ephemeral: ov.ephemeral } - the per-chat value replaces the authored one unconditionally.
  • packages/server/src/routes/chats.routes.ts:1379-1384 - PATCH /api/chats/:id/lorebook-entries/:entryId merges only enabled: { ...overrides[entryId], enabled: parsed.data.enabled }, so ephemeral: 0 stays behind.
  • packages/client/src/features/chat-settings/inline-editors/InlineLorebookEntriesEditor.tsx:177-180 - the chat switch that the player clicks, which calls that route.

What's happening

Each chat keeps its own copy of an entry's remaining activations. When the budget runs out, the chat's copy is saved as "0 left, off". The switch in chat settings only ever writes the on/off flag, so turning it back on leaves the remaining count at 0. On every later turn, that 0 replaces the author's value before the countdown code looks at it; the code only counts down when the number is above zero, so it never counts down and never switches the entry off again. Nothing else in the lorebook service reads that number, and nothing anywhere in the app can clear or edit a chat's copy - which is why re-setting Ephemeral in the shared lorebook is silently ignored in that chat.

The same route already returns a 409 ("Enable this entry in its lorebook first") specifically so a chat-level override can never overrule the shared lorebook's on/off state - but the same override does permanently overrule the shared lorebook's Ephemeral value, which looks unintended rather than designed.

Suggested fix

On a manual per-chat enable, the route should stop leaving a stale remaining count behind. The maintainer call to make is which of these:

  • (a) delete the ephemeral key from the chat override so the authored value is read fresh from the lorebook - this also fixes the "author's edits are ignored in that chat" half;
  • (b) reset it to the entry's authored value, matching what already happens correctly when a player toggles an entry off and on mid-countdown;
  • (c) leave the behaviour and instead say on the switch itself (visible label, not a tooltip) that the entry's limited budget is spent and turning it on makes it constant for this chat.

Note that (a) and (b) both change the contract stated in PR #5981 ("the server merges one flag atomically so ephemeral counters survive"), so this is a deliberate decision, not a silent patch. Whichever is chosen, the existing regression lane needs a case at zero: scripts/regressions/chat-lorebook-entry-scope.regression.ts only ever seeds ephemeral: 3 / 2 (lines 42, 50, 60, 63), which is the case that already works.

Context

Introduced by PR #5981 ("keep chat entry toggles scoped to their chat", merged 2026-09-09), which implemented FR #5954. #5954 only asked for a per-chat enable/disable and says nothing about limited-activation entries, so this case was never specified; PR #5981's own regression and end-to-end lanes never seed a spent counter, so they pass while this is live. Related: #2975 (an entry firing fewer times than authored) was accepted and fixed - this is the same class in the other direction. Unreleased on staging (latest release tag is v2.4.4; PR #5981 landed after it). Chat-local: the shared lorebook row is never modified and other chats are unaffected, and the player can still turn the entry off again.

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/6131 Originally assigned to: @SpicyMarinara on GitHub. A lorebook entry set to fire a limited number of times (the Ephemeral field) turns its own chat switch off once it has fired that many times. If you turn that switch back on, the entry stops being limited: it fires on every single turn for the rest of that chat, and nothing turns it off again. Going back to the lorebook and setting Ephemeral again has no effect in that chat either, so there is no way to get the one-shot behaviour back. ## How to reproduce (try it yourself) 1. Sidebar -> Lorebooks. Create a lorebook named `Docks lore` and turn ON its Global switch. 2. Add an entry: name `Dockmaster rumor`, Keys `dock`, Content `THE DOCKMASTER WHISPERS ABOUT THE TIDE.` (all caps so you can spot it in the prompt). Expand the entry and, in the Timing group (Sticky / Cooldown / Delay / Ephemeral), set `Ephemeral` to `1`, leave `Sticky` at `0`. Save. 3. Open a chat the book applies to. Send: `I walk to the dock.` The entry fires - the all-caps line appears in the world-info block of the prompt inspector. 4. Send `I walk to the dock.` again. It does not fire. Correct - it was a one-shot. 5. Reload the page (F5). This step is needed: an ordinary turn does not refresh the chat's cached settings, so a drawer left open can still show the switch as on. 6. Open the chat settings gear -> Lorebooks -> the pencil button on `Docks lore` (`Edit lorebook entries`). The `Dockmaster rumor` switch is now OFF, with no explanation of why. 7. Click that switch back ON. 8. Send `I walk to the dock.` four more times. 9. Then go back to the shared lorebook and set that entry's `Ephemeral` to `1` again. Return to the chat and send `I walk to the dock.` twice more. **What you'll see:** from step 8 onward the entry fires on every turn, the switch never turns itself off again, and the re-authored Ephemeral value in step 9 changes nothing - it still fires every turn. **What should happen:** an entry the author marked `Ephemeral 1` should fire at most once more after being re-enabled and then switch itself off again, or the switch should tell the player that turning it on makes this entry constant for the chat. Re-setting Ephemeral in the lorebook should at minimum take effect. ## Where it is At staging `52799569c`: - `packages/server/src/services/lorebook/index.ts:1296-1303` - when the countdown runs out the chat override is written as `{ ephemeral: 0, enabled: false }`, and the decrement guard is `a.entry.ephemeral > 0`. - `packages/server/src/services/lorebook/index.ts:1135-1137` - `if (ov && ov.ephemeral !== undefined) return { ...e, ephemeral: ov.ephemeral }` - the per-chat value replaces the authored one unconditionally. - `packages/server/src/routes/chats.routes.ts:1379-1384` - `PATCH /api/chats/:id/lorebook-entries/:entryId` merges only `enabled`: `{ ...overrides[entryId], enabled: parsed.data.enabled }`, so `ephemeral: 0` stays behind. - `packages/client/src/features/chat-settings/inline-editors/InlineLorebookEntriesEditor.tsx:177-180` - the chat switch that the player clicks, which calls that route. ## What's happening Each chat keeps its own copy of an entry's remaining activations. When the budget runs out, the chat's copy is saved as "0 left, off". The switch in chat settings only ever writes the on/off flag, so turning it back on leaves the remaining count at 0. On every later turn, that 0 replaces the author's value before the countdown code looks at it; the code only counts down when the number is above zero, so it never counts down and never switches the entry off again. Nothing else in the lorebook service reads that number, and nothing anywhere in the app can clear or edit a chat's copy - which is why re-setting Ephemeral in the shared lorebook is silently ignored in that chat. The same route already returns a 409 ("Enable this entry in its lorebook first") specifically so a chat-level override can never overrule the shared lorebook's on/off state - but the same override does permanently overrule the shared lorebook's Ephemeral value, which looks unintended rather than designed. ## Suggested fix On a manual per-chat enable, the route should stop leaving a stale remaining count behind. The maintainer call to make is which of these: - (a) delete the `ephemeral` key from the chat override so the authored value is read fresh from the lorebook - this also fixes the "author's edits are ignored in that chat" half; - (b) reset it to the entry's authored value, matching what already happens correctly when a player toggles an entry off and on mid-countdown; - (c) leave the behaviour and instead say on the switch itself (visible label, not a tooltip) that the entry's limited budget is spent and turning it on makes it constant for this chat. Note that (a) and (b) both change the contract stated in PR #5981 ("the server merges one flag atomically so ephemeral counters survive"), so this is a deliberate decision, not a silent patch. Whichever is chosen, the existing regression lane needs a case at zero: `scripts/regressions/chat-lorebook-entry-scope.regression.ts` only ever seeds `ephemeral: 3` / `2` (lines 42, 50, 60, 63), which is the case that already works. ## Context Introduced by PR #5981 ("keep chat entry toggles scoped to their chat", merged 2026-09-09), which implemented FR #5954. #5954 only asked for a per-chat enable/disable and says nothing about limited-activation entries, so this case was never specified; PR #5981's own regression and end-to-end lanes never seed a spent counter, so they pass while this is live. Related: #2975 (an entry firing fewer times than authored) was accepted and fixed - this is the same class in the other direction. Unreleased on staging (latest release tag is v2.4.4; PR #5981 landed after it). Chat-local: the shared lorebook row is never modified and other chats are unaffected, and the player can still turn the entry off again. 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:48 +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:5651924123 --> @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). Re-enabling an exhausted lore entry resets its authored activation limit instead of making it unlimited.

<!-- gh-comment-id:5652785101 --> @SpicyMarinara commented on GitHub (Sep 13, 2026): Fixed in #6137, now merged to staging (`e044997a2`). Re-enabling an exhausted lore entry resets its authored activation limit instead of making it unlimited.
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#3408
No description provided.