mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2278] [Issue]: Budget-dropped lorebook entries leak setvar mutations into the shared macro context (no variable-snapshot rollback) #1115
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#1115
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 @Romuromylus on GitHub (Jun 5, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2278
Originally assigned to: @cha1latte on GitHub.
Summary
When a lorebook entry that runs {{setvar}}/{{addvar}} is dropped because it is over the token budget, the refactor still applies that dropped entry's variable mutation to the shared macro context. Main rolls this back so only injected entries affect variables.
Expected behavior
Only the lorebook entries that are actually kept and injected should mutate macro variables. An entry that is budget-dropped should leave no variable side effect, so a later kept entry's {{getvar}} reads the value it would have read on main.
Actual behavior
The refactor resolves an entry's macros (mutating shared
ctx.variablesin place) before the budget check, then drops the entry without restoring the variables. Later entries and prompt sections that read those variables see a value set by an entry that was never injected.Steps to reproduce
Impact area
Regression notes
Worked on main. Main wraps content resolution in a variable-snapshot transaction:
resolveMacrosWithVariableSnapshot(packages/server/src/services/prompt/macro-context.ts:50-58) andselectBudgetedLorebookEntryBatchrollback (packages/server/src/services/lorebook/index.ts:514-545), wired atassembler.ts:304,generate.routes.ts:2328,game.routes.ts:3222. The refactor'sselectBudgetedLorebookEntries(src/engine/generation/active-lorebook-scanner.ts:595-627) resolves before the budget check (line 599) andcontinues an over-budget entry (line 626) with no rollback; the resolver shares one macros object (src/engine/generation/prompt-assembly.ts:2862,2885-2887) andresolveMacrosmutatesctx.variablesin place (src/engine/shared/macros/macro-engine.ts:729-730,851-868). Grepping the whole tree (src + src-tauri + crates) found no macro-variable snapshot/rollback; the only rollbacks are storage/import. The chosen entry set is byte-identical, so this is purely the variable side effect, hence minor.Environment
5ddb9840(compared against main @b4ab97f)Template check
Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked: