[GH-ISSUE #1344] [Issue]: Refactor chat folders need branch/folder storage parity verification #666

Closed
opened 2026-10-20 17:31:36 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @cha1latte on GitHub (May 26, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1344

Originally assigned to: @Romuromylus on GitHub.

Summary

Chat folders appear mostly present in refactor, but full backend/storage parity with v1.6.0/v1.6.1 still needs verification.

Expected behavior

Chat folders should preserve v1.6.0/v1.6.1 branch/folder inheritance, storage, profile migration, import, and export behavior.

Actual behavior

Folder UI/hooks exist, but branch/folder inheritance and profile migration parity have not been verified.

Steps to reproduce

  1. Open the refactor branch at
Originally created by @cha1latte on GitHub (May 26, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1344 Originally assigned to: @Romuromylus on GitHub. ## Summary Chat folders appear mostly present in refactor, but full backend/storage parity with v1.6.0/v1.6.1 still needs verification. ## Expected behavior Chat folders should preserve v1.6.0/v1.6.1 branch/folder inheritance, storage, profile migration, import, and export behavior. ## Actual behavior Folder UI/hooks exist, but branch/folder inheritance and profile migration parity have not been verified. ## Steps to reproduce 1. Open the refactor branch at
Author
Owner

@cha1latte commented on GitHub (May 26, 2026):

Audit follow-up: this is chat storage/migration parity. Suggested proof should cover chat folders, branch/folder inheritance, reload, profile export/import, and legacy/default paths that could drop folder assignment.

<!-- gh-comment-id:4549579206 --> @cha1latte commented on GitHub (May 26, 2026): Audit follow-up: this is chat storage/migration parity. Suggested proof should cover chat folders, branch/folder inheritance, reload, profile export/import, and legacy/default paths that could drop folder assignment.
Author
Owner

@Romuromylus commented on GitHub (May 27, 2026):

Audit results against refactor at e6c033de (current HEAD):

Verified preserved (no parity gap)

  • branch_chat (Rust) at src-tauri/src/commands/storage/chats.rs:474-498 clones the full source chat row and only mutates id, name, groupId before calling state.storage.create("chats", chat). folderId carries through. This is the equivalent of the v1.6.x fix in #363.
  • Native profile export at src-tauri/src/commands/storage/profile.rs:19-54 lists both "chats" and "chat-folders" in PROFILE_COLLECTIONS. Rows are exported verbatim with no field stripping.
  • Native profile import at src-tauri/src/commands/storage/profile.rs:167-194 reads each collection's rows as-is and calls normalize_profile_json_fields. normalize_typed_json_fields for "chats" (shared.rs:160-172) only validates the shape of characterIds, activeLorebookIds, activeAgentIds, activeToolIds, memories, metadata, gameState. folderId is not listed, so it passes through unchanged.
  • Legacy v1.6.x table import at src-tauri/src/commands/storage/profile/legacy.rs:19-53 maps ("chat_folders", "chat-folders") and ("chats", "chats"). add_legacy_chat_memories only injects a memories array; normalize_legacy_profile_json_fields reuses the same non-stripping path. folderId survives roundtrip.
  • useMoveChat, useReorderChats, useUpdateChat (use-chats / use-chat-folders hooks) all use partial storageApi.update calls, which preserve untouched fields.

Verified parity gaps

Each of these creates a new chat row with an explicit object literal that omits folderId. The source chat had a folder; the derived chat starts unfiled.

  • createRoleplayScene at src/engine/modes/roleplay/scene/scene-service.ts:145-156. Scene chat created from a roleplay chat in folder X ends up at root.
  • forkRoleplayScene at src/engine/modes/roleplay/scene/scene-service.ts:234-243. Cloning or converting a scene drops the folder from the source.
  • gameApi.createGame new-chat path at src/features/modes/game/api/game-api.ts:793-806. Only the chatId-reuse branch (line 782) preserves the folder via partial patch. The fresh-chat branch does not.
  • gameApi.startNextSession at src/features/modes/game/api/game-api.ts:950-968. Starting session N+1 in a campaign creates a new chat row and does not carry the previous session's folderId.
  • Agent create_chat command at src/engine/generation/connected-commands.ts:606-615. Lower severity: an agent creating a sibling chat plausibly has no folder context. Worth a deliberate decision either way.

Storage layer notes (not bugs, but adjacent risks)

  • There are no chat-folder-specific Rust handlers. CRUD goes through generic storage_list / create / update / delete against FileStorage. with_entity_defaults in src-tauri/src/commands/storage/shared.rs:328-501 has no "chat-folders" branch, so folder rows write whatever shape the client sends. The client's useCreateFolder (use-chat-folders.ts:22-29) only passes name, mode, color. sortOrder and collapsed end up undefined on first write.
  • Folder-delete cascade is unverified. useDeleteFolder only invalidates the chats list query; nothing nulls folderId on chats pointing at the deleted folder. After delete, those chats reference a dangling id. UI behavior depends on whether the sidebar treats missing folder lookups as "unfiled" or as "lost". Worth a runtime check.
  • useCreateChat (use-chats.ts:379-395) does not accept folderId at all. Every chat-creation entry point starts at root; folder assignment is exclusively post-creation via drag-to-folder. If the design intent is "create in current folder when one is selected", that wiring is missing on the new-chat sidebar button and the new-from-character path.

Type drift worth flagging

src/features/catalog/chats/types.ts re-declares a slimmer Chat and ChatFolder (missing personaId, promptPresetId, connectionId, connectedChatId, sortOrder, createdAt; ChatFolder misses createdAt / updatedAt). The canonical types in src/engine/contracts/types/chat.ts are richer. This local copy lets a spread or copy through these hooks silently drop fields without TypeScript flagging it. Worth collapsing onto the engine types in a follow-up.

Test coverage

No vitest or marinara_tests.rs case currently covers chat-folder roundtrip:

  • No test asserts that branch_chat preserves folderId.
  • No test asserts profile export then import preserves a folder assignment.
  • No test asserts scene creation inherits folder (because it doesn't; would need to assert the desired behavior once decided).
  • marinara_tests.rs does cover lorebook entry folder remapping (marinara_lorebook_import_remaps_nested_folders) but no chat-folder analogue.

Suggested follow-ups

If the verdict is "scene and game-new-chat should inherit folder from origin", a single small PR can wire folderId: originChat.folderId ?? null into the four explicit-create call sites listed above, plus add one roundtrip test in marinara_tests.rs and one scene-creation vitest. I can pick that up as a separate issue if you want it tracked.

The cascade-delete behavior on folder removal is the other path worth a runtime confirmation. If it is in fact dangling rather than reassigning to null, that is a bug independent of this audit. Happy to file separately.

<!-- gh-comment-id:4553198550 --> @Romuromylus commented on GitHub (May 27, 2026): Audit results against `refactor` at `e6c033de` (current HEAD): ## Verified preserved (no parity gap) - **`branch_chat` (Rust)** at `src-tauri/src/commands/storage/chats.rs:474-498` clones the full source chat row and only mutates `id`, `name`, `groupId` before calling `state.storage.create("chats", chat)`. `folderId` carries through. This is the equivalent of the v1.6.x fix in #363. - **Native profile export** at `src-tauri/src/commands/storage/profile.rs:19-54` lists both `"chats"` and `"chat-folders"` in `PROFILE_COLLECTIONS`. Rows are exported verbatim with no field stripping. - **Native profile import** at `src-tauri/src/commands/storage/profile.rs:167-194` reads each collection's rows as-is and calls `normalize_profile_json_fields`. `normalize_typed_json_fields` for `"chats"` (shared.rs:160-172) only validates the shape of `characterIds`, `activeLorebookIds`, `activeAgentIds`, `activeToolIds`, `memories`, `metadata`, `gameState`. `folderId` is not listed, so it passes through unchanged. - **Legacy v1.6.x table import** at `src-tauri/src/commands/storage/profile/legacy.rs:19-53` maps `("chat_folders", "chat-folders")` and `("chats", "chats")`. `add_legacy_chat_memories` only injects a `memories` array; `normalize_legacy_profile_json_fields` reuses the same non-stripping path. `folderId` survives roundtrip. - **`useMoveChat`, `useReorderChats`, `useUpdateChat`** (use-chats / use-chat-folders hooks) all use partial `storageApi.update` calls, which preserve untouched fields. ## Verified parity gaps Each of these creates a new chat row with an explicit object literal that omits `folderId`. The source chat had a folder; the derived chat starts unfiled. - **`createRoleplayScene`** at `src/engine/modes/roleplay/scene/scene-service.ts:145-156`. Scene chat created from a roleplay chat in folder X ends up at root. - **`forkRoleplayScene`** at `src/engine/modes/roleplay/scene/scene-service.ts:234-243`. Cloning or converting a scene drops the folder from the source. - **`gameApi.createGame` new-chat path** at `src/features/modes/game/api/game-api.ts:793-806`. Only the `chatId`-reuse branch (line 782) preserves the folder via partial patch. The fresh-chat branch does not. - **`gameApi.startNextSession`** at `src/features/modes/game/api/game-api.ts:950-968`. Starting session N+1 in a campaign creates a new chat row and does not carry the previous session's `folderId`. - **Agent `create_chat` command** at `src/engine/generation/connected-commands.ts:606-615`. Lower severity: an agent creating a sibling chat plausibly has no folder context. Worth a deliberate decision either way. ## Storage layer notes (not bugs, but adjacent risks) - There are no chat-folder-specific Rust handlers. CRUD goes through generic `storage_list / create / update / delete` against `FileStorage`. `with_entity_defaults` in `src-tauri/src/commands/storage/shared.rs:328-501` has no `"chat-folders"` branch, so folder rows write whatever shape the client sends. The client's `useCreateFolder` (use-chat-folders.ts:22-29) only passes `name`, `mode`, `color`. `sortOrder` and `collapsed` end up undefined on first write. - Folder-delete cascade is unverified. `useDeleteFolder` only invalidates the chats list query; nothing nulls `folderId` on chats pointing at the deleted folder. After delete, those chats reference a dangling id. UI behavior depends on whether the sidebar treats missing folder lookups as "unfiled" or as "lost". Worth a runtime check. - `useCreateChat` (use-chats.ts:379-395) does not accept `folderId` at all. Every chat-creation entry point starts at root; folder assignment is exclusively post-creation via drag-to-folder. If the design intent is "create in current folder when one is selected", that wiring is missing on the new-chat sidebar button and the new-from-character path. ## Type drift worth flagging `src/features/catalog/chats/types.ts` re-declares a slimmer `Chat` and `ChatFolder` (missing `personaId`, `promptPresetId`, `connectionId`, `connectedChatId`, `sortOrder`, `createdAt`; `ChatFolder` misses `createdAt` / `updatedAt`). The canonical types in `src/engine/contracts/types/chat.ts` are richer. This local copy lets a spread or copy through these hooks silently drop fields without TypeScript flagging it. Worth collapsing onto the engine types in a follow-up. ## Test coverage No vitest or marinara_tests.rs case currently covers chat-folder roundtrip: - No test asserts that `branch_chat` preserves `folderId`. - No test asserts profile export then import preserves a folder assignment. - No test asserts scene creation inherits folder (because it doesn't; would need to assert the desired behavior once decided). - `marinara_tests.rs` does cover lorebook entry folder remapping (`marinara_lorebook_import_remaps_nested_folders`) but no chat-folder analogue. ## Suggested follow-ups If the verdict is "scene and game-new-chat should inherit folder from origin", a single small PR can wire `folderId: originChat.folderId ?? null` into the four explicit-create call sites listed above, plus add one roundtrip test in `marinara_tests.rs` and one scene-creation vitest. I can pick that up as a separate issue if you want it tracked. The cascade-delete behavior on folder removal is the other path worth a runtime confirmation. If it is in fact dangling rather than reassigning to null, that is a bug independent of this audit. Happy to file separately.
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#666
No description provided.