mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2974] [Issue]: Per-lorebook maxRecursionDepth below 3 is silently ignored because the recursion-depth reduce is floored at 3 #1548
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#1548
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/2974
Originally assigned to: @SpicyMarinara on GitHub.
What's wrong
A user who configures a recursive lorebook with
maxRecursionDepthof 1 or 2 (to deliberately limit how deep recursive activation chains go) gets 3 recursion passes anyway. Their setting is silently overridden upward, activating more entries, pulling in more chained content, and consuming more tokens than they asked for. Only values >= 3 are honored.How to reproduce (try it yourself)
recursiveScanning = trueandmaxRecursionDepth = 1(valid per schema; range 1-10).You'll see: B, C, and D all activate (effective depth 3).
Expected with
maxRecursionDepth = 1: A activates, one recursion pass activates B, then it stops — C and D do not activate.Where it is
packages/server/src/services/lorebook/index.ts:934-940— thereducecomputing the effective recursion depth seeds its accumulator with the literal3and combines withMath.max(max, b.maxRecursionDepth ?? 3).:947as themaxDepthargument (param at:697); loop break at:742(if (depth >= maxDepth) break;).packages/shared/src/schemas/lorebook.schema.ts:81(.min(1).max(10).default(3)).What's happening
The reduce seeds its accumulator with
3(the default) and combines values withMath.max. Since the seed equals the default andMath.maxnever drops below it, any per-lorebookmaxRecursionDepthless than 3 is discarded:Math.max(3, 1) === 3.Suggested fix
Seed the reduce with a neutral lower bound and apply the per-lorebook default only to lorebooks that actually have recursion on, while preserving the depth-3 default for the global
enableRecursivepath:This honors an explicit
maxRecursionDepthof 1 or 2 while still defaulting unset per-lorebook values to 3, and keeps the depth-3 default for theenableRecursive(recurse-everything) option, which has no per-lorebook book to read a value from.AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.
@SpicyMarinara commented on GitHub (Jun 29, 2026):
Fixed in the v2.0.7 branch: recursive depth is now reduced from recursive-enabled lorebooks with a floor of 1, so maxRecursionDepth values of 1 or 2 are honored instead of being raised to 3. Validated with pnpm check and pnpm regression:prompt.