mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2690] [Issue]: SillyTavern lorebook import mis-maps position, selectiveLogic, recursion flags, order, regex keys & vectorized mode (entries mis-trigger and mis-place) #1337
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#1337
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 21, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2690
Originally assigned to: @SpicyMarinara on GitHub.
Summary
st-lorebook.importer.tsmaps several core SillyTavern World Info fields incorrectly, so an imported ST world book triggers under the wrong conditions and lands in the wrong place in Marinara. This is the most likely cause of widespread "my ST lorebook works in ST but behaves weirdly here" reports. Six distinct field mappings are wrong, all in one importer.Expected behavior
Importing an ST world book should preserve each entry's triggering and placement semantics (position, selective logic, recursion behavior, vector-only mode, priority order, regex keys) so it behaves the same as in SillyTavern.
Actual behavior (six distinct mismaps)
resolvePositiononly passes numeric ST positions0..2and returns0for everything else. ST's enum is0=before_char, 1=after_char, 2=ANTop, 3=ANBottom, 4=at_depth(@D), 5=EMTop, 6=EMBottom; Marinara has only0=before, 1=after, 2=at-depth. So ST@D(4) →0 (before_char)(at-depth lost), ST ANTop (2) → Marinara at-depth, ST 3/5/6 → before_char. At-depth is extremely common in ST books, so they silently land at the top of the prompt with depth/role inert.selectiveLogicenum inverted.resolveSelectiveLogicuses{0:'and', 1:'or', 2:'not'}, but ST isAND_ANY=0, NOT_ALL=1, NOT_ANY=2, AND_ALL=3. So STAND_ANY(require any secondary) →and(require all); STNOT_ALL(suppress when all present) →or(activate when any present — a logical inversion); STAND_ALL(3) is unrecognized → falls back toand. The selective gate fires under the wrong condition.prevent_recursion(this entry can't be a recursion source) andexclude_recursion(this entry can't be activated by recursion) — plusdelayUntilRecursion. The importer collapses them into onepreventRecursionand dropsdelayUntilRecursion, so recursion activates entries ST would suppress.vectorizedmode dropped.STWorldInfoEntry.vectorizedis declared but never applied; the entry keeps its keys, so an ST vector-only entry keyword-triggers here when ST would only match it semantically.orderfalls back touid/id.asNumber(entry.order ?? entry.insertion_order ?? entry.uid ?? entry.id, 100)— when an ST entry has noorder(common), it uses the sequentialuid(0,1,2,…) as priority, imposing an arbitrary injection order/group tie-break ST never had./regex/keys import as literals. ST infers regex from a slash-delimited key (/pattern/flags) at match time; the importer setsuseRegexonly from a (usually absent)entry.useRegex/entry.regexboolean, so a/dragon(s)?/key is matched as the literal string and never fires.How it breaks the pipeline
Code trace (staging @
b826f8f4) —packages/server/src/services/import/st-lorebook.importer.ts:resolvePosition:214-222(consumed:380/:404).resolveSelectiveLogic:208-212(consumed:398); the round-trip exporter mirrors the wrong table (lorebooks.routes.ts:105,backup.routes.ts:200).preventRecursion;delayUntilRecursionunimplemented. Scanner recursion atkeyword-scanner.ts:537-572.:49declared,:388-421never applied.:378(asNumber(... ?? uid ?? id, 100)), consumed:406; priority sort atkeyword-scanner.ts:498/529, group tie-break:341.:403(Boolean(entry.useRegex ?? entry.regex ?? false)); matcherlorebook-keyword-matching.tstestKeyword.Steps to reproduce
Import an ST
world_infoJSON with: a numericposition:4(@D) entry, aselective:true, keysecondary:['x'], selectiveLogic:1(NOT_ALL) entry, avectorized:trueentry, an entry with onlyuidand noorder, and an entry whose key is'/dragon(s)?/'. Compare placement/triggering to SillyTavern — each diverges as described above.Suggested fix
{0:0,1:1,2:0,3:1,4:2,5:0,6:1}(at minimum4→2); decide deliberate targets for AN/EM.0 AND_ANY→'or',3 AND_ALL→'and',1/2 NOT_*→'not'(closest); fix the exporter too. (Full parity needs a 4-mode SelectiveLogic — see the companion scanner issue.)prevent_recursionandexclude_recursionto distinct flags (add the missing "cannot be activated by recursion" field); implement or explicitly skipdelayUntilRecursion.entry.vectorized(clear keys / add a vector-only flag) instead of dropping it.uid/idfrom the fallback chain →asNumber(entry.order ?? entry.insertion_order, 100)./pattern/flagskeys on import, strip slashes, setuseRegex=true.Environment
b826f8f4)Additional context
Found via a systematic multi-agent audit of conditional prompt insertion (ST-parity focus). These six mismaps share one file and are the highest-impact lorebook parity win. Related: the scanner-side
selectiveLogicmode count and the at-depth placement hoist are filed separately.Template check
Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:
@kolacheee commented on GitHub (Jun 21, 2026):
Four clarifications for accuracy/actionability (the six core mismaps are all confirmed present at the cited lines on the current tree):
Regex-keys fix (Claim #6) is unsafe as written.
useRegexis a single per-ENTRY boolean: the scanner setsmatchOptions.useRegex = entry.useRegex(keyword-scanner.ts:473) andtestKeywordapplies it to EVERY primary and secondary key (lorebook-keyword-matching.ts:36-46). ST instead infers regex per-KEY at match time. Blindly settinguseRegex=truebecause one/pattern/key is present forces the entry's other literal keys throughnew RegExp(literalKey)— literal keys containing regex metacharacters (e.g.(parens),a+b,$5) then match differently or throw and silently fall back to substring. Recommend either (a) per-key handling: strip^/(.+)/([gimsuy]*)$into the stored key and only set entry-leveluseRegex=truewhen it is safe for the remaining keys (e.g. by escaping the literals), or (b) explicitly document that mixed literal+regex entries are partially lossy until per-key regex support exists.Field-name precision (Claim #3): ST's exported world_info JSON uses camelCase
preventRecursion/excludeRecursion/delayUntilRecursion, NOT snake_caseprevent_recursion/exclude_recursion. The importer already reads the camelCase names (st-lorebook.importer.ts:419:entry.preventRecursion ?? entry.excludeRecursion); a fixer adding the missing flag must keep reading camelCase. The real defect stands: the two distinct ST flags collapse into one, anddelayUntilRecursionis referenced nowhere in the importer. Marinara's schema has only one recursion flag (preventRecursion, lorebook.ts:193), which gates recursion SOURCES at keyword-scanner.ts:550 — there is no "cannot be activated by recursion" concept, so the fix needs a new schema column plus a scanner change, not just an import remap.Frequency note (Claim #5): ST exports almost always include
order(default 100; Marinara's own compatible exporter always writesordertoo), so the?? uid ?? idfallback (st-lorebook.importer.ts:378) fires only for entries genuinely missingorder. The fix is correct, but impact is lower-frequency than "common."Scope: the position round-trip is broken symmetrically, same as the selectiveLogic exporter you already flagged. Both compatible exporters write position raw — lorebooks.routes.ts:144 and backup.routes.ts:221 (
position: Number(entry.position ?? 0)) — so Marinara at-depth (2) exports as ST ANTop (2). Fix the exporters' position mapping alongside the importer's. (lorebooks.routes.ts:186/199 are the internal Marinara→Marinara transfer helperbuildTransferredEntryInput, not an exporter, and are out of scope.)@SpicyMarinara commented on GitHub (Jun 21, 2026):
Fixed in branch
codex/spicy-issue-sweep-2026-06-21.What changed:
excludeRecursionanddelayUntilRecursion, so the imported ST recursion semantics are actually enforced.Final repo checks will run after the full issue sweep.
@kolacheee commented on GitHub (Jun 21, 2026):
Claim #4 (vectorized mode) is not fixed: an ST
vectorized:true(vector/semantic-only) entry still keyword-triggers in the merged worktree. st-lorebook.importer.ts:481 maps STvectorizedontoexcludeFromVectorization, the wrong axis (embedding eligibility, not triggering mode); forvectorized:trueit yieldsexcludeFromVectorization=false. Keys are preserved unconditionally (importer :434/:452, never cleared) and the scanner's main keyword loop (keyword-scanner.ts:469-532) never checks vectorization, so the entry keyword-triggers.excludeFromVectorizationonly gates the semantic fallback (keyword-scanner.ts:540). No vector-only/semantic-only flag exists anywhere. Notably this regressed: PR #2730's original commit3118174bcorrectly cleared keys for vector-only entries, but follow-up commite6a967f8reverted that. Suggested fix: restore the key-clearing (vectorizedOnly => keys=[]) or add a true vector-only/semantic-only entry flag and gate the main keyword loop on it. The other 5 core mismaps and all 4 veracity refinements are correctly fixed.