mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #5760] [MERGED] fix(prompt): insert each lorebook position at most once across lorebook markers #6920
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#6920
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5760
Author: @Romuromylus
Created: 9/2/2026
Status: ✅ Merged
Merged: 9/2/2026
Merged by: @Romuromylus
Base:
staging← Head:fix/5716-lorebook-marker-duplication📝 Commits (4)
49c79b2fix(prompt): insert each lorebook position at most once across lorebook markersc411ab8docs(prompt): keep MarkerContext JSDoc attached and spell out lorebook marker claim orderd958ee0Merge branch 'staging' into fix/5716-lorebook-marker-duplication5420b07docs(prompt): document expandLorebook📊 Changes
3 files changed (+89 additions, -4 deletions)
View changed files
📝
CHANGELOG.md(+1 -0)📝
packages/server/src/services/prompt/marker-expander.ts(+31 -4)📝
scripts/regressions/prompt.regression.ts(+57 -0)📄 Description
Linked issue
Closes #5716
Why this change
A lorebook entry set to insert Before Char was showing up under both the "Before Char" and "After Char" placeholders of the preset in the chat's prompt inspection. That happens when a preset carries more than one lorebook marker covering the same world-info position: every
Lorebook Marker (All)section expands to the full before + after content, so two of them (or an "All" marker sitting after a "Before" marker) repeat the same entries in the sent prompt. The dedicated Before / After markers were already fine on their own; the duplication comes from the combined marker not knowing that another marker already placed those entries.Reproduced on my private deploy against current
stagingwith a constant position-0 entry: a preset withLorebook Marker (Before)+Lorebook Marker (After)inserts the entry once, while a preset with twoLorebook Marker (All)sections named "Before Char" / "After Char" inserts it twice.What changed
packages/server/src/services/prompt/marker-expander.ts:expandLorebooknow records which world-info positions (before/after) a lorebook marker has already placed on the sharedMarkerContextfor the current prompt build (lorebookPositionsEmitted). The first marker that covers a position owns it; a later marker covering the same position expands without it. Dedicated Before + After markers keep their own position each, and the set lives on the per-build context, so preview and generation each start clean. Same once-guard shapeensureLorebookScanalready uses for depth entries.scripts/regressions/prompt.regression.ts: new case "lorebook markers insert each world-info position at most once per prompt build" covering two "All" markers, Before-then-All, the typed Before + After pair (including a repeated Before), and a fresh build. Fails on the previous expander, passes with this change.CHANGELOG.md: Unreleased › Fixed entry.Out of scope: the SillyTavern preset importer still consolidates
worldInfoBefore+worldInfoAfterinto a single combined marker by design; this PR only stops duplicates when a preset ends up with several lorebook markers.Validation
pnpm checkpasses locallyCONTRIBUTING.mdManual verification notes
node ./scripts/run-regressions.mjs --filter scripts/regressions/prompt.regression.tspasses with the fix; the new case fails against the previousmarker-expander.ts(stash-verified).tsc --noEmitclean forpackages/server; Prettier clean on the touched files.<character_info>), and the typed Before/After pair stayed at 1 copy in the same spot. Manually re-verify in the browser prompt inspection.Lorebook Marker (All)still receive their lorebook entries once.Docs and release impact
docs-i18nbranch updated to match, or a[docs-i18n]follow-up issue opened (see CONTRIBUTING.md § Translated documentation)UI evidence (if applicable)
Not a UI change. Evidence is the Peek Prompt modal on the deployed branch for the two-"All" preset (sections named Intro / Before Char / Character Info / After Char / Chat History): the assembled prompt now lists INTRO, BEFORE CHAR (containing the single lorebook entry), CHARACTER INFO, SYSTEM, LAST MESSAGE - the "After Char" placeholder expands to nothing and is dropped, where before the fix it repeated the entry. The dedicated Before/After preset renders identically.
Summary by CodeRabbit
Bug Fixes
Tests
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.