[GH-ISSUE #2704] [Issue]: ST-compatible lorebook export omits useRegex/recursion/vectorized and mis-encodes at-depth position #1349

Closed
opened 2026-10-21 05:31:58 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @kolacheee on GitHub (Jun 21, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2704

Originally assigned to: @SpicyMarinara on GitHub.

Summary

The "SillyTavern-compatible" lorebook export (format=compatible) omits several per-entry fields and mis-encodes at-depth placement, so a Marinara lorebook exported for ST loses regex-key matching, recursion gating, and vectorization opt-out, and at-depth entries land in the wrong place. This is the export-side companion to the import mismaps in #2690 — even a Marinara→ST round-trip isn't lossless.

Expected behavior

The compatible export should emit a faithful SillyTavern World Info file: at-depth entries encoded as ST's at-depth form (position 4 + role + depth), and per-entry useRegex, recursion, and vectorization flags preserved so the entry behaves the same after re-import.

Actual behavior

buildCompatibleLorebookExport (lorebooks.routes.ts:130-169) writes each entry's fields but:

  1. At-depth mis-encoded. It writes position: Number(entry.position ?? 0) directly. Marinara's position=2 means at-depth, but ST's position=2 means Author's-Note-Top (ST at-depth is position=4 + role + depth). So every Marinara at-depth entry exports as ST AN-Top — wrong placement, and its depth/role are ignored by ST. The export can never produce ST's at-depth form.
  2. useRegex/regex omitted. Never emitted, so a regex-key entry re-imports as useRegex=false and matches its pattern literally.
  3. preventRecursion/excludeRecursion omitted. Never emitted, so a non-recursable entry re-imports as recursable, changing which lore fires.
  4. vectorized/excludeFromVectorization omitted. Never emitted, so a vectorization opt-out is reset to default on re-import.

How it breaks the pipeline

Code trace (staging @ b826f8f4) — packages/server/src/routes/lorebooks.routes.ts, buildCompatibleLorebookExport (:130-169, per-entry object :133-156):

  • Position: position: Number(entry.position ?? 0) (:144); Marinara enum shared/types/lorebook.ts:159-160; importer resolvePosition maps at_depth→2 (st-lorebook.importer.ts:214-222).
  • useRegex omitted; importer reads Boolean(entry.useRegex ?? entry.regex ?? false) (st-lorebook.importer.ts:403).
  • preventRecursion omitted; importer reads Boolean(entry.preventRecursion ?? entry.excludeRecursion ?? false) (:419).
  • excludeFromVectorization omitted; ST vectorized field recognized (st-lorebook.importer.ts:49).

Steps to reproduce

  1. Create a lorebook entry with position=2 (at-depth), depth=6, role=assistant, useRegex=true (regex key), preventRecursion=true, excludeFromVectorization=true.
  2. GET /lorebooks/:id/export?format=compatible, then re-import the file.
  3. The entry returns as: at top of Author's Note (not depth 6), useRegex=false (literal match), preventRecursion=false, vectorization re-enabled.

Suggested fix

Make the compatible export the inverse of the importer: emit Marinara position=2 as ST position=4 with numeric role + depth (and 0→0, 1→1); add useRegex (+ regex alias), excludeRecursion: entry.preventRecursion === true, and vectorized: entry.excludeFromVectorization !== true to each entry object, so import/export round-trips losslessly.

Environment

  • Marinara Engine version: 2.0.0 (staging @ b826f8f4)
  • Install type: source
  • OS + version: All (code-level defect, platform-independent)
  • Browser or app shell: All

Additional context

Found via a systematic multi-agent audit of import/export round-trips. Export-side companion to the import mismaps in #2690 (and the at-depth placement in #2691/#2676). Part of a set of import/export fidelity issues filed together.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @kolacheee on GitHub (Jun 21, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2704 Originally assigned to: @SpicyMarinara on GitHub. ## Summary The "SillyTavern-compatible" lorebook export (`format=compatible`) omits several per-entry fields and mis-encodes at-depth placement, so a Marinara lorebook exported for ST loses regex-key matching, recursion gating, and vectorization opt-out, and at-depth entries land in the wrong place. This is the **export-side** companion to the import mismaps in #2690 — even a Marinara→ST round-trip isn't lossless. ## Expected behavior The compatible export should emit a faithful SillyTavern World Info file: at-depth entries encoded as ST's at-depth form (position 4 + role + depth), and per-entry `useRegex`, recursion, and vectorization flags preserved so the entry behaves the same after re-import. ## Actual behavior `buildCompatibleLorebookExport` (`lorebooks.routes.ts:130-169`) writes each entry's fields but: 1. **At-depth mis-encoded.** It writes `position: Number(entry.position ?? 0)` directly. Marinara's `position=2` means at-depth, but ST's `position=2` means **Author's-Note-Top** (ST at-depth is `position=4` + `role` + `depth`). So every Marinara at-depth entry exports as ST AN-Top — wrong placement, and its `depth`/`role` are ignored by ST. The export can never produce ST's at-depth form. 2. **`useRegex`/`regex` omitted.** Never emitted, so a regex-key entry re-imports as `useRegex=false` and matches its pattern literally. 3. **`preventRecursion`/`excludeRecursion` omitted.** Never emitted, so a non-recursable entry re-imports as recursable, changing which lore fires. 4. **`vectorized`/`excludeFromVectorization` omitted.** Never emitted, so a vectorization opt-out is reset to default on re-import. ## How it breaks the pipeline Code trace (staging @ `b826f8f4`) — `packages/server/src/routes/lorebooks.routes.ts`, `buildCompatibleLorebookExport` (`:130-169`, per-entry object `:133-156`): - Position: `position: Number(entry.position ?? 0)` (`:144`); Marinara enum `shared/types/lorebook.ts:159-160`; importer `resolvePosition` maps `at_depth→2` (`st-lorebook.importer.ts:214-222`). - `useRegex` omitted; importer reads `Boolean(entry.useRegex ?? entry.regex ?? false)` (`st-lorebook.importer.ts:403`). - `preventRecursion` omitted; importer reads `Boolean(entry.preventRecursion ?? entry.excludeRecursion ?? false)` (`:419`). - `excludeFromVectorization` omitted; ST `vectorized` field recognized (`st-lorebook.importer.ts:49`). ## Steps to reproduce 1. Create a lorebook entry with `position=2` (at-depth), `depth=6`, `role=assistant`, `useRegex=true` (regex key), `preventRecursion=true`, `excludeFromVectorization=true`. 2. `GET /lorebooks/:id/export?format=compatible`, then re-import the file. 3. The entry returns as: at top of Author's Note (not depth 6), `useRegex=false` (literal match), `preventRecursion=false`, vectorization re-enabled. ## Suggested fix Make the compatible export the inverse of the importer: emit Marinara `position=2` as ST `position=4` with numeric `role` + `depth` (and `0→0`, `1→1`); add `useRegex` (+ `regex` alias), `excludeRecursion: entry.preventRecursion === true`, and `vectorized: entry.excludeFromVectorization !== true` to each entry object, so import/export round-trips losslessly. ## Environment - Marinara Engine version: 2.0.0 (staging @ `b826f8f4`) - Install type: source - OS + version: All (code-level defect, platform-independent) - Browser or app shell: All ## Additional context Found via a systematic multi-agent audit of import/export round-trips. Export-side companion to the import mismaps in #2690 (and the at-depth placement in #2691/#2676). Part of a set of import/export fidelity issues filed together. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
Author
Owner

@kolacheee commented on GitHub (Jun 21, 2026):

Veracity self-review — correction / clarification
Automated post-filing review of this issue against the current working tree. The reported bug remains valid; the notes below refine its scope, accuracy, or suggested fix for whoever implements it.

Two clarifications to keep this actionable:

  1. The "round-trips losslessly" goal requires importer changes too, not just the export. Marinara's own importer (packages/server/src/services/import/st-lorebook.importer.ts) cannot decode the corrected export for two of the four fields, so shipping only the export change leaves the documented "re-import the file" reproduce step still broken for at-depth and vectorization:

    • resolvePosition (st-lorebook.importer.ts:214-222) only accepts numeric 0-2; ST at-depth position=4 falls through to return 0 (before_char). So exporting at-depth as position=4 round-trips correctly into SillyTavern, but a Marinara->file->Marinara re-import still lands the entry at before_char. Fix: add if (typeof value === "number" && value === 4) return 2; (or broaden the numeric range and map 4->2) so ST at-depth decodes back to Marinara at_depth. (depth and role already survive: the importer reads depth at :405 and role at :382/:407 unconditionally, so once position decodes to 2 the original depth/role are preserved.)

    • The importer never reads vectorized: the vectorized?: boolean at :49 is declared on the STWorldInfoEntry type but never consumed, and the import input (:388-421) omits excludeFromVectorization entirely. So exporting vectorized won't restore excludeFromVectorization on Marinara re-import. Fix: in the import input add excludeFromVectorization: entry.vectorized === false ? true : Boolean(entry.excludeFromVectorization) (mind the inverted polarity — ST vectorized=true means "is vectorized" = NOT excluded).

    useRegex (:403) and preventRecursion/excludeRecursion (:419) are already read by the importer, so those two fields round-trip with the export change alone.

  2. Minor correction to the "How it breaks the pipeline" trace: the bullet "ST vectorized field recognized (st-lorebook.importer.ts:49)" should read "declared in the STWorldInfoEntry type (:49) but not consumed by the importer." The importer does not currently read entry.vectorized anywhere, which is exactly why importer change (1) above is required for the vectorization opt-out to survive a Marinara re-import.

<!-- gh-comment-id:4761102430 --> @kolacheee commented on GitHub (Jun 21, 2026): > **Veracity self-review — correction / clarification** > _Automated post-filing review of this issue against the current working tree. The reported bug remains valid; the notes below refine its scope, accuracy, or suggested fix for whoever implements it._ Two clarifications to keep this actionable: 1) The "round-trips losslessly" goal requires importer changes too, not just the export. Marinara's own importer (packages/server/src/services/import/st-lorebook.importer.ts) cannot decode the corrected export for two of the four fields, so shipping only the export change leaves the documented "re-import the file" reproduce step still broken for at-depth and vectorization: - resolvePosition (st-lorebook.importer.ts:214-222) only accepts numeric 0-2; ST at-depth position=4 falls through to `return 0` (before_char). So exporting at-depth as position=4 round-trips correctly into SillyTavern, but a Marinara->file->Marinara re-import still lands the entry at before_char. Fix: add `if (typeof value === "number" && value === 4) return 2;` (or broaden the numeric range and map 4->2) so ST at-depth decodes back to Marinara at_depth. (depth and role already survive: the importer reads `depth` at :405 and `role` at :382/:407 unconditionally, so once position decodes to 2 the original depth/role are preserved.) - The importer never reads `vectorized`: the `vectorized?: boolean` at :49 is declared on the STWorldInfoEntry type but never consumed, and the import input (:388-421) omits excludeFromVectorization entirely. So exporting `vectorized` won't restore excludeFromVectorization on Marinara re-import. Fix: in the import input add `excludeFromVectorization: entry.vectorized === false ? true : Boolean(entry.excludeFromVectorization)` (mind the inverted polarity — ST `vectorized=true` means "is vectorized" = NOT excluded). useRegex (:403) and preventRecursion/excludeRecursion (:419) are already read by the importer, so those two fields round-trip with the export change alone. 2) Minor correction to the "How it breaks the pipeline" trace: the bullet "ST `vectorized` field recognized (st-lorebook.importer.ts:49)" should read "declared in the STWorldInfoEntry type (:49) but not consumed by the importer." The importer does not currently read entry.vectorized anywhere, which is exactly why importer change (1) above is required for the vectorization opt-out to survive a Marinara re-import.
Author
Owner

@SpicyMarinara commented on GitHub (Jun 21, 2026):

Addressed the still-valid gaps on the issue sweep branch. At-depth compatible export/import and useRegex/preventRecursion handling were already present in the current branch, so I left those intact. This patch adds the ST regex alias and vectorized flag on compatible export, maps vectorized=false back to excludeFromVectorization on import, and corrects the importer so vectorized=true no longer strips keyword keys. Final pnpm validation is deferred until the full sweep is complete.

<!-- gh-comment-id:4761581159 --> @SpicyMarinara commented on GitHub (Jun 21, 2026): Addressed the still-valid gaps on the issue sweep branch. At-depth compatible export/import and useRegex/preventRecursion handling were already present in the current branch, so I left those intact. This patch adds the ST regex alias and vectorized flag on compatible export, maps vectorized=false back to excludeFromVectorization on import, and corrects the importer so vectorized=true no longer strips keyword keys. Final pnpm validation is deferred until the full sweep is complete.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#1349
No description provided.