mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #3013] [Issue]: save_lorebook_entry caps keys to 24 BEFORE de-duplicating, silently dropping valid distinct keys #1585
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#1585
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 @kolacheee on GitHub (Jun 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3013
Originally assigned to: @SpicyMarinara on GitHub.
What's wrong
normalizeLorebookEntryKeystrims/filters the raw keys array, thenslice(0, MAX_LOREBOOK_ENTRY_KEYS=24), and ONLY THEN de-duplicates withArray.from(new Set(...)). Because the cap is applied before dedup, leading duplicate keys consume slots in the cap window and push distinct, valid keys past index 24 out of the result entirely. The model can supply 24+ unique trigger keys yet end up with far fewer — or even a single key — when duplicates appear early in the array. Trigger keys silently missing from a lorebook entry means the entry will not activate on those keywords.How to reproduce (try it yourself)
save_lorebook_entry({ name:"X", content:"...", keys:["a","a","a", ...22 more "a"..., "important_key", "another_key"] })so the 24-element slice window is filled entirely by the duplicate"a"before reaching the distinct keys.You'll see: the result entry's
keys = ["a"](after slice-then-dedup);important_keyandanother_keyare dropped, even though there were only 3 distinct keys total.Expected: up to 24 DISTINCT keys are retained regardless of duplicate ordering, so all 3 distinct keys are kept.
Where it is
packages/server/src/services/tools/tool-executor.ts:625-629(normalizeLorebookEntryKeys), used at:665insaveLorebookEntry;MAX_LOREBOOK_ENTRY_KEYS = 24at line 72.What's happening
De-duplication is performed after the cap (
.slice(0, MAX_LOREBOOK_ENTRY_KEYS)) instead of before it, so duplicates count against the limit and can crowd out distinct keys.Suggested fix
Move de-duplication ahead of the cap while keeping the existing non-string handling and the fallback-to-name branch:
This dedups distinct trimmed keys first, then caps to 24, so up to 24 distinct keys are always retained.
Regression avoided: the original one-line suggestion, taken as a full-function replacement, would (1) lose the fallback-to-name (returning
[]for empty/invalid input, producing entries with zero trigger keys — the same class of bug being fixed) and (2) lose non-string safety (a bareraw.map(trim)throws when the model supplies a non-string key). The corrected version only reorders dedup before the cap and preserves both thetypeof entry === "string"guard and the[fallbackName]fallback.AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.
@SpicyMarinara commented on GitHub (Jun 29, 2026):
Fixed in merged staging PR #3018.