mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #3014] [Issue]: save_lorebook_entry coerces any unrecognized mode value to the destructive 'replace' default #1586
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#1586
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/3014
Originally assigned to: @SpicyMarinara on GitHub.
What's wrong
normalizeLorebookWriteModereturns the value only if it is exactly"create","append", or"replace"; any other value falls through to"replace". The manifest enum is["create","replace","append"]and its description reads "Create or update an entry", which invites near-miss values likemode:"update","add", or"new"from a model — especially non-native-tool-calling models whose tool calls are parsed from text and not enum-validated. Such a near-miss is silently mapped toreplace(the destructive overwrite path) rather than rejected. A model intending to add to or create an entry can thus overwrite an existing same-named entry, losing its prior content, while the tool reports a successful save.How to reproduce (try it yourself)
save_lorebook_entry({ name:"Aldric", content:"new partial note", mode:"update" })where an entry named "Aldric" already exists.You'll see:
normalizeLorebookWriteMode("update")returns"replace"; the existing entry's content is overwritten (not appended/merged) and the prior content is lost; the tool returns{applied:true, action:"replaced"}.Expected: an explicit-but-invalid mode is rejected with a correctable validation error, so the destructive overwrite is not triggered by a hallucinated value.
Where it is
packages/server/src/services/tools/tool-executor.ts:633-635(normalizeLorebookWriteMode), used at:665insaveLorebookEntry. The destructive overwrite path is inpackages/server/src/services/generation/tool-resolution-runtime.ts:453-459,463.What's happening
Unknown mode strings are silently coerced to the destructive default
"replace"instead of being rejected or treated as non-destructive. Args are not enum-validated before reaching this function (a rawJSON.parseof the tool arguments passes the value straight through), so a near-miss mode from a text-parsed model reaches the coercion and triggers an overwrite.Suggested fix
Validate
modeinsaveLorebookEntryso an explicit-but-invalid mode is rejected while an omitted mode still defaults to the documented"replace".Replace the normalizer:
Then in
saveLorebookEntry, before building the save payload:and change the payload field at line 665 to use the validated
mode.Regression avoided: an OMITTED mode (undefined/null/empty) still maps to the documented
"replace"default, so existing callers relying on the default are unaffected; valid values pass through unchanged. Doing the check insaveLorebookEntry(which can early-return{ error }) rather than inside the normalizer keeps the established error-surfacing convention this function already uses, and explicitly treating undefined/null/"" as omission also catches non-string near-misses. Both downstream writers receiveentry.modealready typed to the union, so nothing else is touched.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.