[GH-ISSUE #3483] [Issue]: Lorebook folders: stale "flat folders" comments plus two paths that still flatten or drop nesting (same class as #3348) #1883

Closed
opened 2026-10-21 05:43:30 +07:00 by bsakaguchi · 0 comments
Owner

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

Originally assigned to: @kolacheee on GitHub.

Summary

Nested lorebook folders shipped in #2602, but the shared type contract still says folders are flat, one import path still flattens them, and the Mari CLI silently drops folder placement. This is the exact failure class behind #3348: an agent read a stale "folders are flat" comment and shipped code that flattened nested folders on import.

Why this is a problem: comments and type contracts are what agents (and new contributors) treat as ground truth. A false "flat folders" contract sitting in the shared types is a loaded gun for the next lorebook PR.
What it negatively affects: user data (folder structure is silently lost on legacy profile import and on Mari-CLI entry edits) and future agent work on the lorebook subsystem.

Expected behavior

Comments describe nesting truthfully, and every import/write path preserves parentFolderId / folderId.

Actual behavior

  • packages/shared/src/types/lorebook.ts:86 and :112 — JSDoc says "Folders are flat in v1 — parentFolderId is reserved for future nested-folder support and must currently be null" and "Always null in v1; the server rejects non-null values." Both claims are false today: lorebooks.routes.ts:752-759 accepts and validates a non-null parent on create, and :768-773 re-parents with cycle/self-parent checks via canReparentFolder. Suggested replacement: "parentFolderId nests folders; the server validates the parent exists and rejects cycles (see lorebook-folder-tree.ts)."
  • packages/server/src/routes/backup.routes.ts:2107 — the legacy (pre-snapshot) branch of POST /import-profile builds a folderIdMap but hardcodes parentFolderId: null when creating folders, so nested folders silently flatten when importing an older backup. The correct two-pass parent remap exists ~60 lines below for preset groups (2164-2192) and is never applied to lorebook folders.
  • packages/server/src/services/mari-db/mari-db.service.ts:1901 — mari lorebook add-entry / update-entry never read or assign folderId (a real nullable FK), so folder placement is silently dropped, with no warning, when entries are managed through the Mari CLI.

Steps to reproduce

  1. Create a lorebook with folders nested inside folders.
  2. Export a legacy-format profile and re-import it: the folders arrive flattened (all parents null).
  3. Compare the contract at lorebook.ts:86 with the create/patch handlers at lorebooks.routes.ts:752.

Environment

  • Marinara Engine version: 2.2.0 (staging @ 45b650de9)
  • Install type: source
  • OS + version: N/A — verified by reading the code, not runtime-specific
  • Browser or app shell: N/A

Logs, screenshots, or video

N/A — file/line references above point at the exact code.

Additional context

Related history: #2602 (nested folders), #3348 (the earlier flattening regression this class of stale comment caused). Found by a repo-wide read-only sweep for dead code and stale comments; every entry above was adversarially re-verified against the code before filing. No fix has been started — filing for triage. Part of a coordinated set of sweep catalogue 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 (Jul 11, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3483 Originally assigned to: @kolacheee on GitHub. ## Summary Nested lorebook folders shipped in #2602, but the shared type contract still says folders are flat, one import path still flattens them, and the Mari CLI silently drops folder placement. This is the exact failure class behind #3348: an agent read a stale "folders are flat" comment and shipped code that flattened nested folders on import. **Why this is a problem:** comments and type contracts are what agents (and new contributors) treat as ground truth. A false "flat folders" contract sitting in the shared types is a loaded gun for the next lorebook PR. **What it negatively affects:** user data (folder structure is silently lost on legacy profile import and on Mari-CLI entry edits) and future agent work on the lorebook subsystem. ## Expected behavior Comments describe nesting truthfully, and every import/write path preserves `parentFolderId` / `folderId`. ## Actual behavior - [ ] `packages/shared/src/types/lorebook.ts:86` and `:112` — JSDoc says "Folders are flat in v1 — `parentFolderId` is reserved for future nested-folder support and must currently be null" and "Always null in v1; the server rejects non-null values." Both claims are false today: `lorebooks.routes.ts:752-759` accepts and validates a non-null parent on create, and `:768-773` re-parents with cycle/self-parent checks via `canReparentFolder`. Suggested replacement: "`parentFolderId` nests folders; the server validates the parent exists and rejects cycles (see lorebook-folder-tree.ts)." - [ ] `packages/server/src/routes/backup.routes.ts:2107` — the legacy (pre-snapshot) branch of `POST /import-profile` builds a `folderIdMap` but hardcodes `parentFolderId: null` when creating folders, so nested folders silently flatten when importing an older backup. The correct two-pass parent remap exists ~60 lines below for preset groups (2164-2192) and is never applied to lorebook folders. - [ ] `packages/server/src/services/mari-db/mari-db.service.ts:1901` — `mari lorebook add-entry` / `update-entry` never read or assign `folderId` (a real nullable FK), so folder placement is silently dropped, with no warning, when entries are managed through the Mari CLI. ## Steps to reproduce 1. Create a lorebook with folders nested inside folders. 2. Export a legacy-format profile and re-import it: the folders arrive flattened (all parents null). 3. Compare the contract at `lorebook.ts:86` with the create/patch handlers at `lorebooks.routes.ts:752`. ## Environment - Marinara Engine version: 2.2.0 (staging @ 45b650de9) - Install type: source - OS + version: N/A — verified by reading the code, not runtime-specific - Browser or app shell: N/A ## Logs, screenshots, or video N/A — file/line references above point at the exact code. ## Additional context Related history: #2602 (nested folders), #3348 (the earlier flattening regression this class of stale comment caused). Found by a repo-wide read-only sweep for dead code and stale comments; every entry above was adversarially re-verified against the code before filing. No fix has been started — filing for triage. Part of a coordinated set of sweep catalogue 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.
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#1883
No description provided.