[GH-ISSUE #1180] Pre-refactor data migration: five import gaps drop or corrupt legacy user data #583

Closed
opened 2026-10-20 17:30:27 +07:00 by bsakaguchi · 3 comments
Owner

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

Originally assigned to: @Romuromylus on GitHub.

While testing whether existing users on the pre-refactor staging branch can move their data to the Tauri refactor, I hit five separate import gaps that either drop data silently, crash the editor, or block the full-profile zip outright. They share a single theme: the refactor's importers and modals don't account for the schema and envelope shapes the production app actually ships.

Filing them as one issue since they're all the migration path and the fix in # addresses them together.

The five gaps (refactor branch HEAD 7ea792d8)

1. Profile zip import rejects every backup that contains chat images

PROFILE_ASSET_DIRS in src-tauri/src/commands/storage/profile/assets.rs lists avatars / sprites / backgrounds / game-assets / fonts / knowledge-sources / lorebooks/images. The pre-refactor BACKUP_DIRS set in packages/server/src/routes/backup.routes.ts also includes gallery (chat image attachments). When the refactor walks the zip and validates each asset entry through safe_profile_asset_path, the first gallery/ entry trips the allow-list and the whole import aborts with Invalid profile asset path. This affects every user who has attached an image to a chat, which is the common case.

2. SillyTavern chat import sets an invalid mode value

import_st_chat_text in src-tauri/src/commands/storage/imports/bulk_imports.rs defaults the new chat's mode to the literal string "chat" when the JSONL header doesn't supply one. The ChatMode enum is conversation | roleplay | visual_novel | game, and the mode sidebars filter on it; chats imported via this path get created in storage but never appear in any sidebar, only on the Recent surface.

3. Marinara lorebook envelope importer doesn't normalize legacy text-encoded array fields

import_marinara_lorebook in src-tauri/src/commands/storage/imports/marinara.rs writes the lorebook row through with_entity_defaults, which only fills missing keys. The pre-refactor schema stores tags, characterIds, and personaIds as TEXT columns containing JSON-stringified arrays (e.g. "[]" or '["foo","bar"]'). The string passes through to storage untouched, and the moment the user opens the imported lorebook the editor crashes:

LorebookEditor.tsx:1173 Uncaught TypeError: formTags.map is not a function
    at LorebookEditor (LorebookEditor.tsx:1173:31)

The same shape mismatch hits the legacy profile-zip path through add_legacy_lorebook_links in src-tauri/src/commands/storage/profile/legacy.rs whenever the source row carries those fields directly.

4. ImportPresetModal and ImportLorebookModal silently downgrade unknown marinara_* envelopes to empty SillyTavern records

Both modals detect the Marinara envelope shape with a strict-equality check (json.type === "marinara_preset" and json.type === "marinara_lorebook"). The pre-refactor app exports seven envelope types in total (marinara_character, marinara_persona, marinara_lorebook, marinara_preset, marinara_chat_preset, marinara_memory_recall, marinara_profile). When a user drops a marinara_chat_preset or marinara_memory_recall file into the preset modal, the strict check fails, the file falls through to importApi.stPreset, the permissive ST importer accepts the JSON and creates a row with zero sections / zero groups / zero choice blocks, and the modal reports "Imported preset" with full UI success. The user thinks the file imported; the data is gone.

The persona and character modals already use the broader startsWith("marinara_") check, so they correctly route unsupported envelopes to the Marinara importer where the Rust router rejects them with a real error.

5. Rust router has no handlers for marinara_chat_preset or marinara_memory_recall

import_marinara_envelope in src-tauri/src/commands/storage/imports/marinara.rs matches on the four supported envelope types and rejects everything else with Unknown Marinara import type: <type>. The two missing types are real pre-refactor export endpoints (/api/chat-presets/:id/export and /api/chats/:id/memories/export). Fixing (4) above is enough to make the user see this rejection as a clear error instead of a silent empty-record success; adding actual handlers is the longer-term path and a separate scope from this PR.

Reproduction

Fabricate the test files from a snapshot of the production data tables, then drop them through the corresponding refactor import dialogs in pnpm tauri dev. Test counts that round-trip cleanly after this fix:

  • 31 characters, 20 personas
  • 32 lorebooks / 1492 entries (tags parsed, editor opens)
  • 5 chats / 126 messages / 129 swipes / 24 memory chunks (chats now appear in the conversation sidebar)
  • 2 prompt presets, 3 chat presets (chat presets now report a clear "Unknown Marinara import type: marinara_chat_preset" error instead of creating empty rows)
  • 9 chat-image gallery attachments (profile zip succeeds)

Linked PR

I've opened a draft PR with the consolidated fix; linking back here once it has a number.

Originally created by @Romuromylus on GitHub (May 24, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1180 Originally assigned to: @Romuromylus on GitHub. While testing whether existing users on the pre-refactor `staging` branch can move their data to the Tauri refactor, I hit five separate import gaps that either drop data silently, crash the editor, or block the full-profile zip outright. They share a single theme: the refactor's importers and modals don't account for the schema and envelope shapes the production app actually ships. Filing them as one issue since they're all the migration path and the fix in #<PR-number-once-opened> addresses them together. ## The five gaps (refactor branch HEAD `7ea792d8`) ### 1. Profile zip import rejects every backup that contains chat images `PROFILE_ASSET_DIRS` in `src-tauri/src/commands/storage/profile/assets.rs` lists `avatars / sprites / backgrounds / game-assets / fonts / knowledge-sources / lorebooks/images`. The pre-refactor `BACKUP_DIRS` set in `packages/server/src/routes/backup.routes.ts` also includes `gallery` (chat image attachments). When the refactor walks the zip and validates each asset entry through `safe_profile_asset_path`, the first `gallery/` entry trips the allow-list and the whole import aborts with `Invalid profile asset path`. This affects every user who has attached an image to a chat, which is the common case. ### 2. SillyTavern chat import sets an invalid `mode` value `import_st_chat_text` in `src-tauri/src/commands/storage/imports/bulk_imports.rs` defaults the new chat's `mode` to the literal string `"chat"` when the JSONL header doesn't supply one. The `ChatMode` enum is `conversation | roleplay | visual_novel | game`, and the mode sidebars filter on it; chats imported via this path get created in storage but never appear in any sidebar, only on the Recent surface. ### 3. Marinara lorebook envelope importer doesn't normalize legacy text-encoded array fields `import_marinara_lorebook` in `src-tauri/src/commands/storage/imports/marinara.rs` writes the lorebook row through `with_entity_defaults`, which only fills missing keys. The pre-refactor schema stores `tags`, `characterIds`, and `personaIds` as TEXT columns containing JSON-stringified arrays (e.g. `"[]"` or `'["foo","bar"]'`). The string passes through to storage untouched, and the moment the user opens the imported lorebook the editor crashes: ``` LorebookEditor.tsx:1173 Uncaught TypeError: formTags.map is not a function at LorebookEditor (LorebookEditor.tsx:1173:31) ``` The same shape mismatch hits the legacy profile-zip path through `add_legacy_lorebook_links` in `src-tauri/src/commands/storage/profile/legacy.rs` whenever the source row carries those fields directly. ### 4. ImportPresetModal and ImportLorebookModal silently downgrade unknown `marinara_*` envelopes to empty SillyTavern records Both modals detect the Marinara envelope shape with a strict-equality check (`json.type === "marinara_preset"` and `json.type === "marinara_lorebook"`). The pre-refactor app exports seven envelope types in total (`marinara_character`, `marinara_persona`, `marinara_lorebook`, `marinara_preset`, `marinara_chat_preset`, `marinara_memory_recall`, `marinara_profile`). When a user drops a `marinara_chat_preset` or `marinara_memory_recall` file into the preset modal, the strict check fails, the file falls through to `importApi.stPreset`, the permissive ST importer accepts the JSON and creates a row with zero sections / zero groups / zero choice blocks, and the modal reports "Imported preset" with full UI success. The user thinks the file imported; the data is gone. The persona and character modals already use the broader `startsWith("marinara_")` check, so they correctly route unsupported envelopes to the Marinara importer where the Rust router rejects them with a real error. ### 5. Rust router has no handlers for `marinara_chat_preset` or `marinara_memory_recall` `import_marinara_envelope` in `src-tauri/src/commands/storage/imports/marinara.rs` matches on the four supported envelope types and rejects everything else with `Unknown Marinara import type: <type>`. The two missing types are real pre-refactor export endpoints (`/api/chat-presets/:id/export` and `/api/chats/:id/memories/export`). Fixing (4) above is enough to make the user see this rejection as a clear error instead of a silent empty-record success; adding actual handlers is the longer-term path and a separate scope from this PR. ## Reproduction Fabricate the test files from a snapshot of the production data tables, then drop them through the corresponding refactor import dialogs in `pnpm tauri dev`. Test counts that round-trip cleanly after this fix: - 31 characters, 20 personas - 32 lorebooks / 1492 entries (`tags` parsed, editor opens) - 5 chats / 126 messages / 129 swipes / 24 memory chunks (chats now appear in the conversation sidebar) - 2 prompt presets, 3 chat presets (chat presets now report a clear "Unknown Marinara import type: marinara_chat_preset" error instead of creating empty rows) - 9 chat-image gallery attachments (profile zip succeeds) ## Linked PR I've opened a draft PR with the consolidated fix; linking back here once it has a number.
Author
Owner

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

Linked PR: #1181 (draft). Will promote out of draft after the live drag-drop verification across all five paths in pnpm tauri dev.

<!-- gh-comment-id:4530037802 --> @Romuromylus commented on GitHub (May 24, 2026): Linked PR: #1181 (draft). Will promote out of draft after the live drag-drop verification across all five paths in `pnpm tauri dev`.
Author
Owner

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

Adding a sixth gap to the same PR after live retest exposed it:

6. All avatars render broken after a profile zip import

Pre-refactor's characters and personas tables store avatarPath as the old server route (e.g. /api/avatars/file/<uuid>.png). The refactor's legacy importer normalizes those URLs into the new relative form via normalize_legacy_profile_asset_paths, gated on the asset file existing at state.data_dir.join(relative). PR #1153 / #1179 (atomic asset transaction) staged restored assets under a temporary staging_root and only moved them into state.data_dir after the database rows had been written, so the existence check missed every just-restored avatar and the rows kept the unresolvable URLs. Symptom: profile zip imports complete successfully, but every character and persona renders with a broken avatar across the whole library.

Fix in #1181 threads an Option<&Path> staging root through the normalizer and accepts the asset as present if the file is in either the staging dir or the live data dir.

<!-- gh-comment-id:4530071235 --> @Romuromylus commented on GitHub (May 24, 2026): Adding a sixth gap to the same PR after live retest exposed it: ### 6. All avatars render broken after a profile zip import Pre-refactor's `characters` and `personas` tables store `avatarPath` as the old server route (e.g. `/api/avatars/file/<uuid>.png`). The refactor's legacy importer normalizes those URLs into the new relative form via `normalize_legacy_profile_asset_paths`, gated on the asset file existing at `state.data_dir.join(relative)`. PR #1153 / #1179 (atomic asset transaction) staged restored assets under a temporary `staging_root` and only moved them into `state.data_dir` after the database rows had been written, so the existence check missed every just-restored avatar and the rows kept the unresolvable URLs. Symptom: profile zip imports complete successfully, but every character and persona renders with a broken avatar across the whole library. Fix in #1181 threads an `Option<&Path>` staging root through the normalizer and accepts the asset as present if the file is in either the staging dir or the live data dir.
Author
Owner

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

Two more gaps surfaced during live retest and are now part of #1181:

7. Lorebook list and editor show every imported lorebook as Global

Pre-refactor stored bool columns on lorebook rows (isGlobal, enabled, recursiveScanning, excludeFromVectorization) as TEXT with literal "true" / "false" strings. The refactor's with_entity_defaults only fills the field when missing, so the strings flow into storage unchanged. JavaScript treats every non-empty string as truthy, so lorebook.isGlobal === "false" evaluates to true and the library renders every scoped lorebook as global. (Symptom: 25 of 32 lorebooks tagged Global post-import, vs the 5 that were actually global in the source.) Fixed by adding normalize_legacy_text_bool_fields to shared.rs and invoking it on the lorebook row from both the marinara-envelope path and the legacy profile-zip path.

8. Roleplay-mode chats with lorebooks error with Invalid collection name

buildActivatedEntries in src/engine/generation/prompt-assembly.ts called storage.list(lorebooks/${id}/entries). That path shape is a leftover from the pre-refactor HTTP API; the refactor storage layer rejects anything with a slash via validate_collection_name in crates/security/src/lib.rs. Any roleplay-mode chat with one or more attached lorebooks surfaced Invalid collection name: lorebooks/<id>/entries the moment the user sent a message. Fixed by switching to the existing listLorebookEntries(lorebookId) capability, matching the shape every other refactor caller uses.

<!-- gh-comment-id:4530340470 --> @Romuromylus commented on GitHub (May 24, 2026): Two more gaps surfaced during live retest and are now part of #1181: ### 7. Lorebook list and editor show every imported lorebook as `Global` Pre-refactor stored bool columns on lorebook rows (`isGlobal`, `enabled`, `recursiveScanning`, `excludeFromVectorization`) as TEXT with literal `"true"` / `"false"` strings. The refactor's `with_entity_defaults` only fills the field when missing, so the strings flow into storage unchanged. JavaScript treats every non-empty string as truthy, so `lorebook.isGlobal === "false"` evaluates to `true` and the library renders every scoped lorebook as global. (Symptom: 25 of 32 lorebooks tagged `Global` post-import, vs the 5 that were actually global in the source.) Fixed by adding `normalize_legacy_text_bool_fields` to `shared.rs` and invoking it on the lorebook row from both the marinara-envelope path and the legacy profile-zip path. ### 8. Roleplay-mode chats with lorebooks error with `Invalid collection name` `buildActivatedEntries` in `src/engine/generation/prompt-assembly.ts` called `storage.list(`lorebooks/${id}/entries`)`. That path shape is a leftover from the pre-refactor HTTP API; the refactor storage layer rejects anything with a slash via `validate_collection_name` in `crates/security/src/lib.rs`. Any roleplay-mode chat with one or more attached lorebooks surfaced `Invalid collection name: lorebooks/<id>/entries` the moment the user sent a message. Fixed by switching to the existing `listLorebookEntries(lorebookId)` capability, matching the shape every other refactor caller uses.
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#583
No description provided.