[PR #7329] [MERGED] fix(lorebooks): stop reporting empty entries as budget-skipped and name the budget #7683

Closed
opened 2026-10-24 04:06:30 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7329
Author: @SpicyMarinara
Created: 10/9/2026
Status: ✅ Merged
Merged: 10/9/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/7325-lorebook-skipped-entries


📝 Commits (8)

  • fe7d5dc fix(lorebooks): stop reporting empty entries as budget-skipped and name the budget
  • b4216c1 Merge origin/staging into fix/7325-lorebook-skipped-entries
  • 7516d05 fix(lorebooks): keep {{setvar}} from entries that macros empty
  • f044a27 Merge origin/staging into fix/7325-lorebook-skipped-entries
  • 6020ba1 fix(lorebooks): say the current-location lore limit is fixed
  • 05c3203 Merge origin/staging into fix/7325-lorebook-skipped-entries
  • 2f758d3 Move the CHANGELOG entry away from other open PRs
  • b49b967 Merge origin/staging into fix/7325-lorebook-skipped-entries

📊 Changes

6 files changed (+204 additions, -15 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 docs/lorebooks/token-budgets.md (+4 -1)
📝 packages/client/src/components/chat/ChatRoleplayPanels.tsx (+39 -10)
📝 packages/client/src/localization/locales/en.json (+3 -0)
📝 packages/server/src/services/lorebook/index.ts (+29 -4)
➕ scripts/regressions/lorebook-budget-skips.regression.ts (+128 -0)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #7325

Why this change

  • A user had the chat's Lorebook Token Budget at 0 and their lorebook's own Token Budget at 0, yet Active Context said "1 matching lore entry was skipped by token budget". The notice did not say which budget, so nobody could tell whether a lorebook budget or the model's context was to blame.
  • Root cause (packages/server/src/services/lorebook/index.ts, trySelectBudgetedLorebookEntry): an entry whose text is blank, or that macros resolve to nothing (for example a {{setvar}}-only entry or an {{#if}} branch not taken), fails fitLorebookEntryToBudget because it has no text. The skip reason then fell back to "chat" in getBudgetSkipReason, so the panel showed it as blocked by the chat budget with "3 / 0". With every budget off, such entries were the only way to get a chat/lorebook skip. Reproduced on staging with budgets 0 and 0: blank and macro-emptied entries came back as blockedBy: "chat".
  • Same shape for image-only entries: the text pass recorded them as text skips even when the images pass then added them, so they could show up as "skipped" while their images were in the prompt.
  • Answer to "is this the lorebook budget or the model's budget?": the notice only ever comes from the lorebook selection (chat Lorebook Token Budget, the lorebook's Token Budget, or the 2,048-token limit on lore attached to the current location). Context fitting for the model's context size never adds to it.

What changed

  • Server: an entry with no text to add is no longer recorded as budget-skipped (chat/lorebook pass and current-location pass). Image-only entries are judged only by the images pass, and when their images do not fit, the skip now names the budget they hit. Such entries still add no text, but their macros now apply again: a {{setvar}}-only entry sets its variable, so entries that read it (for example {{#if {{getvar::x}}}}…{{/if}}) keep their text. Since #6809 the budget pass rolled those macros back, which silently dropped the dependent lore.
  • Client: the skipped-entries notice now has one plain line per budget that skipped entries, naming it and where to change it (Chat Settings → Lorebooks, the lorebook editor, or the fixed current-location limit). It now uses the steady theme accent (--marinara-app-accent-static) and theme tokens instead of hard-coded amber, so it never pulses with Accent Pulse.
  • New English strings only: chat.activeContext.budgetHint.chat, .lorebook, .location.
  • Regression: scripts/regressions/lorebook-budget-skips.regression.ts (fails on staging, passes here). It also pins that real chat, lorebook and image skips are still reported with the right budget.
  • Docs: docs/lorebooks/token-budgets.md (notice color, budget line, location reason, empty entries). Translations tracked in #7328.
  • CHANGELOG entry under [Unreleased].

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

  • Manually verify: in a Roleplay chat with Lorebook Token Budget 0 and a lorebook with Token Budget 0, add an entry whose keyword matches and whose text is only {{setvar::x::1}} (or empty). After a new reply, Active Context shows no skipped-entries notice.
  • Manually verify: set the chat's Lorebook Token Budget to a small value (for example 50) with a long matching entry. After a new reply the notice reads "Skipped by this chat's Lorebook Token Budget: raise it or set it to 0 in Chat Settings → Lorebooks."
  • Manually verify: set the lorebook's own Token Budget small instead. The notice names that lorebook and points to the lorebook editor.
  • Manually verify: add one entry {{setvar::met::yes}} and a second entry with the same keyword whose text is {{#if {{getvar::met}} == "yes"}}Vibrance trusts you.{{/if}}. After a new reply, Active Context lists the second entry with that text and Chat Variables shows met = yes.
  • Manually verify the notice in light and dark themes, with Accent Pulse on (the border and icon stay steady), and on a phone-width viewport (lines wrap, no horizontal scroll).

Agent-run checks: node ./scripts/run-regressions.mjs --filter for lorebook-budget-skips (also run against staging's lorebook/index.ts to confirm it fails there), experience-lore-entries, lorebook-image-prompt, lorebook-images, lorebook-decision-activation, lorebook-include-macro, chat-lorebook-entry-scope, lorebook-scan-compaction, lorebook-test-scan; pnpm localization:check. pnpm check and pnpm regression:prompt results are added in a comment below once they finish.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

UI evidence (if applicable)

None captured by the agent; see the manual checks above.

Summary by CodeRabbit

  • Improvements
    • Lorebook skip notices identify whether the chat budget, a named lorebook budget, or the current-location limit blocked an entry, and where to adjust the relevant budget. They clarify that the location limit is fixed and entries can still activate through their own keywords.
    • Skipped-entry rows show estimated tokens and activation sources. Notices and rows use neutral theme colors instead of amber.
  • Bug Fixes
    • Blank entries and entries emptied by macros are no longer listed as budget-skipped, including when both chat and lorebook budgets are set to 0. Their macros still run, so variable-setting entries can affect other entries.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/7329 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/9/2026 **Status:** ✅ Merged **Merged:** 10/9/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/7325-lorebook-skipped-entries` --- ### 📝 Commits (8) - [`fe7d5dc`](https://github.com/Pasta-Devs/Marinara-Engine/commit/fe7d5dc6f6186be09e45151bad1dbf33c3af1b3b) fix(lorebooks): stop reporting empty entries as budget-skipped and name the budget - [`b4216c1`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b4216c1e5580a11fe3c4f9dab522609e32883f62) Merge origin/staging into fix/7325-lorebook-skipped-entries - [`7516d05`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7516d0569ed3a87e7f0d30a2410ec0c3ffd9a5bb) fix(lorebooks): keep {{setvar}} from entries that macros empty - [`f044a27`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f044a270e581696efaba5a100df19d3cc0e62374) Merge origin/staging into fix/7325-lorebook-skipped-entries - [`6020ba1`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6020ba19b0b59775590c9739b733efecb3d48d4e) fix(lorebooks): say the current-location lore limit is fixed - [`05c3203`](https://github.com/Pasta-Devs/Marinara-Engine/commit/05c320386f5207c1ddfb87f7dff1787201401f0c) Merge origin/staging into fix/7325-lorebook-skipped-entries - [`2f758d3`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2f758d302173f3dc80a86d685ded30b66a1f09a3) Move the CHANGELOG entry away from other open PRs - [`b49b967`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b49b96754fa20261a205ddc86b24f16197f6f61e) Merge origin/staging into fix/7325-lorebook-skipped-entries ### 📊 Changes **6 files changed** (+204 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `docs/lorebooks/token-budgets.md` (+4 -1) 📝 `packages/client/src/components/chat/ChatRoleplayPanels.tsx` (+39 -10) 📝 `packages/client/src/localization/locales/en.json` (+3 -0) 📝 `packages/server/src/services/lorebook/index.ts` (+29 -4) ➕ `scripts/regressions/lorebook-budget-skips.regression.ts` (+128 -0) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Closes #7325 ## Why this change - A user had the chat's **Lorebook Token Budget** at 0 and their lorebook's own **Token Budget** at 0, yet **Active Context** said "1 matching lore entry was skipped by token budget". The notice did not say which budget, so nobody could tell whether a lorebook budget or the model's context was to blame. - Root cause (`packages/server/src/services/lorebook/index.ts`, `trySelectBudgetedLorebookEntry`): an entry whose text is blank, or that macros resolve to nothing (for example a `{{setvar}}`-only entry or an `{{#if}}` branch not taken), fails `fitLorebookEntryToBudget` because it has no text. The skip reason then fell back to `"chat"` in `getBudgetSkipReason`, so the panel showed it as blocked by the chat budget with "3 / 0". With every budget off, such entries were the only way to get a chat/lorebook skip. Reproduced on staging with budgets 0 and 0: blank and macro-emptied entries came back as `blockedBy: "chat"`. - Same shape for image-only entries: the text pass recorded them as text skips even when the images pass then added them, so they could show up as "skipped" while their images were in the prompt. - Answer to "is this the lorebook budget or the model's budget?": the notice only ever comes from the lorebook selection (chat Lorebook Token Budget, the lorebook's Token Budget, or the 2,048-token limit on lore attached to the current location). Context fitting for the model's context size never adds to it. ## What changed - Server: an entry with no text to add is no longer recorded as budget-skipped (chat/lorebook pass and current-location pass). Image-only entries are judged only by the images pass, and when their images do not fit, the skip now names the budget they hit. Such entries still add no text, but their macros now apply again: a `{{setvar}}`-only entry sets its variable, so entries that read it (for example `{{#if {{getvar::x}}}}…{{/if}}`) keep their text. Since #6809 the budget pass rolled those macros back, which silently dropped the dependent lore. - Client: the skipped-entries notice now has one plain line per budget that skipped entries, naming it and where to change it (Chat Settings → Lorebooks, the lorebook editor, or the fixed current-location limit). It now uses the steady theme accent (`--marinara-app-accent-static`) and theme tokens instead of hard-coded amber, so it never pulses with Accent Pulse. - New English strings only: `chat.activeContext.budgetHint.chat`, `.lorebook`, `.location`. - Regression: `scripts/regressions/lorebook-budget-skips.regression.ts` (fails on staging, passes here). It also pins that real chat, lorebook and image skips are still reported with the right budget. - Docs: `docs/lorebooks/token-budgets.md` (notice color, budget line, location reason, empty entries). Translations tracked in #7328. - CHANGELOG entry under [Unreleased]. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes - Manually verify: in a Roleplay chat with **Lorebook Token Budget** 0 and a lorebook with **Token Budget** 0, add an entry whose keyword matches and whose text is only `{{setvar::x::1}}` (or empty). After a new reply, **Active Context** shows no skipped-entries notice. - Manually verify: set the chat's **Lorebook Token Budget** to a small value (for example 50) with a long matching entry. After a new reply the notice reads "Skipped by this chat's Lorebook Token Budget: raise it or set it to 0 in Chat Settings → Lorebooks." - Manually verify: set the lorebook's own **Token Budget** small instead. The notice names that lorebook and points to the lorebook editor. - Manually verify: add one entry `{{setvar::met::yes}}` and a second entry with the same keyword whose text is `{{#if {{getvar::met}} == "yes"}}Vibrance trusts you.{{/if}}`. After a new reply, **Active Context** lists the second entry with that text and **Chat Variables** shows `met = yes`. - Manually verify the notice in light and dark themes, with **Accent Pulse** on (the border and icon stay steady), and on a phone-width viewport (lines wrap, no horizontal scroll). Agent-run checks: `node ./scripts/run-regressions.mjs --filter` for `lorebook-budget-skips` (also run against staging's `lorebook/index.ts` to confirm it fails there), `experience-lore-entries`, `lorebook-image-prompt`, `lorebook-images`, `lorebook-decision-activation`, `lorebook-include-macro`, `chat-lorebook-entry-scope`, `lorebook-scan-compaction`, `lorebook-test-scan`; `pnpm localization:check`. `pnpm check` and `pnpm regression:prompt` results are added in a comment below once they finish. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) ## UI evidence (if applicable) None captured by the agent; see the manual checks above. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Improvements** * Lorebook skip notices identify whether the chat budget, a named lorebook budget, or the current-location limit blocked an entry, and where to adjust the relevant budget. They clarify that the location limit is fixed and entries can still activate through their own keywords. * Skipped-entry rows show estimated tokens and activation sources. Notices and rows use neutral theme colors instead of amber. * **Bug Fixes** * Blank entries and entries emptied by macros are no longer listed as budget-skipped, including when both chat and lorebook budgets are set to 0. Their macros still run, so variable-setting entries can affect other entries. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-24 04:06:30 +07:00
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#7683
No description provided.