mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #1978] Prioritize latest user-message lorebook matches during budget selection #970
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#970
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?
Originally created by @Xelvanis on GitHub (Jun 2, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1978
Originally assigned to: @cha1latte on GitHub.
Problem
Target 7 lorebooks parityscan found a budget-selection regression for lorebook entries that match the current user turn.
Legacy marked entries whose primary key matched the latest user message and selected those ahead of older-context matches under lorebook token budget. Refactor no longer carries that match metadata and sorts budget candidates only by constant status, then entry order.
Refactor evidence
src/engine/generation-core/lorebooks/keyword-scanner.ts:33-43definesActivatedEntrywithout latest-user match metadata.src/engine/generation-core/lorebooks/prompt-injector.ts:162-166sorts budget candidates by constant status, thenentry.order.matchedLatestUserMessageequivalent before budget selection.Legacy behavior
packages/server/src/services/lorebook/keyword-scanner.ts:45-46storedmatchedLatestUserMessageon activated entries.packages/server/src/services/lorebook/keyword-scanner.ts:412-478computed the flag from the latest user message.packages/server/src/services/lorebook/index.ts:319-324sorted latest-user matches ahead of older-context matches during budget selection.Impact
When the lorebook budget is tight, an entry matched only by older chat context can consume budget before an entry that directly matches the newest user message. This can make current-turn lore fail to inject even though legacy prioritized it.
Expected behavior
Budget selection should preserve the legacy priority: constants first, latest-user-message primary-key matches next, then entry insertion order.
Suggested fix
Reintroduce latest-user match metadata in the scanner and include it in
applyTokenBudgetWithSkippedordering beforeentry.order. Add focused local proof with two activated non-constant entries where only the later-order entry matches the latest user message and budget allows one entry.Parent: #1904 target 7 lorebooks parityscan.