mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #3347] [Issue]: Native lorebook import flattens nested folders (parentFolderId dropped) #1815
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#1815
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 (Jul 7, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3347
Originally assigned to: @kolacheee on GitHub.
Summary
Nested lorebook folders (a shipped feature — you can drag a folder into another folder in the editor to nest it) are flattened to the root level when a lorebook is imported from a native (
.marinara.json) export. The export correctly records each folder'sparentFolderId, but the importer hardcodesparentFolderId: null, so the entire folder hierarchy collapses to a single flat level on import.Expected behavior
Importing a natively-exported lorebook reproduces the exact folder tree, including sub-folders nested under their parents. A native export is Marinara's own round-trip format, so it should preserve everything Marinara supports — and folders can nest.
Actual behavior
Every imported folder lands at the top level; all nesting is lost. Entries still land inside the correct folder (folder IDs are remapped), but the parent/child relationship between folders is gone — a sub-folder that was inside "Locations" is now a sibling of it at the root.
Steps to reproduce
.marinara.json) format.data.folders[]contains "Cities" withparentFolderIdset to "Locations"' id — the nesting is in the export.Environment
Logs, screenshots, or video
N/A (data-shape issue). Code references:
parentFolderId. Native lorebook export emitsdata: { lorebook, entries, folders }(packages/server/src/routes/lorebooks.routes.ts:521and:556), wherefolders=storage.listFolders(id)→parseFolderRowincludesparentFolderId(packages/server/src/services/storage/lorebooks.storage.ts:216,:664).importLorebookPayload's folder-restore loop hardcodesparentFolderId: null(packages/server/src/services/import/marinara.importer.ts:508, comment// v1 ignores nesting on import).Nesting is fully implemented end-to-end, so the "v1 is flat" assumption behind that line no longer holds:
lorebooks.routes.ts:752-759); PATCH reparent runs a full descendant-cycle check (canReparentFolder,lorebooks.routes.ts:770).createFolder/updateFolderboth honorparentFolderId(lorebooks.storage.ts:967,:984);cloneFolderdeep-clones subtrees; delete supports?cascadesubtree deletion.packages/client/src/components/lorebooks/LorebookEditor.tsx:1081,:1232,:1255).The "flat in v1 / reserved / always null" comments in
db/schema/lorebooks.ts:68-69&:82,lorebooks.storage.ts:966, andmarinara.importer.ts:508are all stale — nested folders shipped after those comments were written.Additional context
Two import paths hit the same flattening (both funnel through
importLorebookPayload):lorebooks.routes.tsexport →marinara.importer.tsimport).importBundledLorebooks→ sameimportLorebookPayload).This is independent of the linked-lorebook export bug (#3345, "revert #3342's attached-lorebook bundling"): even if that bundling is reverted, the standalone native round-trip still flattens nesting. It is also distinct from the embed feature (#3341 / #3343), where folders are dropped entirely because the V2
character_bookshape has no folder concept — a separate limitation, not this flattening.Suggested fix — make the importer's folder restore a two-pass operation:
folderIdRemap(old id → new id).d.foldersagain and, for each folder whose exportedparentFolderIdis non-null, callupdateFolder(newId, { parentFolderId: folderIdRemap.get(oldParentId) }).Two passes make it order-independent (every new id exists before any reparent), and reusing the existing
canReparentFoldervalidation keeps it safe against malformed exports. While there, refresh the stale "v1 / flat / reserved / always null" comments inmarinara.importer.ts:508,lorebooks.storage.ts:966, anddb/schema/lorebooks.ts:68-69&:82.Template check
Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked: