mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #2542] [MERGED] perf(lorebook): bound the default per-turn keyword-scan window #5645
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#5645
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/2542
Author: @Romuromylus
Created: 6/9/2026
Status: ✅ Merged
Merged: 6/9/2026
Merged by: @SpicyMarinara
Base:
staging← Head:fix/lorebook-scan-depth-cap📝 Commits (2)
2c98c1dperf(lorebook): bound the default per-turn keyword-scan window491c85aMerge branch 'staging' into fix/lorebook-scan-depth-cap📊 Changes
3 files changed (+24 additions, -9 deletions)
View changed files
📝
packages/server/src/services/lorebook/index.ts(+6 -2)📝
packages/server/src/services/lorebook/keyword-scanner.ts(+12 -7)📝
packages/shared/src/constants/defaults.ts(+6 -0)📄 Description
Linked issue
Closes #2526
Why this change
The generate-path lorebook scan set
scanOpts.scanDepth = 0("scan all messages"). Inkeyword-scanner.ts, an entry whose effectivescanDepthresolved tonullfell back tocombinedText, which — with the globalscanDepthof 0 — was the entire chat history. So each turn re-scanned the full transcript for those entries (O(history × entries)), and the cost grew with transcript length.The common case is already bounded: a lorebook's
scanDepthDB-defaults to 2 andapplyLorebookDefaultspropagates it to null-scanDepthentries before the scan, so those slice to the last 2 messages. The unbounded full-history scan only fires for an entry whose effective depth is genuinely unset (null) or an explicit0.What changed
LIMITS.LOREBOOK_DEFAULT_SCAN_DEPTH = 10(packages/shared/src/constants/defaults.ts).packages/server/src/services/lorebook/index.ts: the generate-pathscanOpts.scanDepthnow usesLIMITS.LOREBOOK_DEFAULT_SCAN_DEPTHinstead of0, so an entry that leavesscanDepthunset caps its scan to the last 10 messages instead of the whole history.packages/server/src/services/lorebook/keyword-scanner.ts: the per-entry scan-window selection now distinguishes the three cases explicitly:scanDepth === 0→ scan full history (a deliberate "scan all" choice, preserved),scanDepth > 0→ scan that many recent messages (unchanged),scanDepth === null→ inherit the now-bounded global default.So a user who intentionally sets a lorebook/entry to
scanDepth 0is unaffected; only the genuinely-unset fallback is bounded. The knowledge-router scan path passes noscanDepthand keeps the scanner's own default, so it is unchanged.Not a regression: byte-identical on
main; long-standing shared-code perf characteristic.Validation
pnpm checkpasses locallyCONTRIBUTING.mdManual verification notes
pnpm checkpasses locally. Added a local-only node:test (scan-depth.test.ts, gitignored) drivingscanForActivatedEntriesdirectly with a keyword present only in the oldest of 15 messages and the new bounded global default:scanDepth→ keyword 10+ messages back is not scanned (the fix),scanDepth 0→ still reaches the oldest message (deliberate scan-all preserved),scanDepthlarger than history → scans everything (override honored),Local run: 4/4 pass.
Still to verify manually against the deploy:
scanDepth 0still matches keywords far back in history.Docs and release impact
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.