[PR #1181] [MERGED] Fix pre-refactor data migration import gaps #4963

Closed
opened 2026-10-22 04:12:04 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/1181
Author: @Romuromylus
Created: 5/24/2026
Status: ✅ Merged
Merged: 5/24/2026
Merged by: @Romuromylus

Base: refactor ← Head: fix/pre-refactor-data-migration


📝 Commits (7)

  • 2239fc3 Fix pre-refactor data migration import gaps
  • 68bb338 Restore legacy avatar paths when assets are still staged
  • 48791f8 Update legacy import tests for staging_root parameter
  • bf92d15 Read staged avatar bytes from staging dir, not data dir
  • d181d42 Address CodeRabbit findings on legacy import normalization
  • def54cd Coerce legacy text-encoded bool fields on imported lorebooks
  • bc0a949 Use listLorebookEntries capability for lorebook prompt assembly

📊 Changes

9 files changed (+217 additions, -35 deletions)

View changed files

📝 src-tauri/src/commands/storage/imports/bulk_imports.rs (+1 -1)
📝 src-tauri/src/commands/storage/imports/marinara.rs (+19 -0)
📝 src-tauri/src/commands/storage/profile/assets.rs (+53 -10)
📝 src-tauri/src/commands/storage/profile/legacy.rs (+59 -18)
📝 src-tauri/src/commands/storage/profile/zip_import.rs (+2 -0)
📝 src-tauri/src/commands/storage/shared.rs (+64 -0)
📝 src/engine/generation/prompt-assembly.ts (+3 -1)
📝 src/features/catalog/lorebooks/components/ImportLorebookModal.tsx (+8 -3)
📝 src/features/catalog/presets/components/ImportPresetModal.tsx (+8 -2)

📄 Description

Why this change

Existing users on the pre-refactor staging branch cannot move their data into the Tauri refactor without hitting one of eight import or post-import gaps. The full-profile zip is rejected outright if the user has any chat images, every imported avatar lands as a broken URL, individual lorebook imports crash the editor on open, individual chat imports become unreachable, two of the seven pre-refactor envelope types silently create empty rows instead of erroring, every imported lorebook renders as Global even when it was scoped, and any roleplay-mode chat with an attached lorebook fails to assemble a prompt at all. This PR fixes all eight gaps as one coherent change because they share a single theme - the refactor's importers, modals, and runtime don't yet account for the schema and envelope shapes the production app actually ships.

Filed together at #1180.

What changed

  • src-tauri/src/commands/storage/profile/assets.rs: add "gallery" to PROFILE_ASSET_DIRS. The pre-refactor backup set includes a gallery/ directory for chat-image attachments; without this the safe_profile_asset_path allow-list rejected the entire profile zip with Invalid profile asset path for any user with chat images. Also thread an optional staging_root through normalize_legacy_profile_asset_paths and legacy_profile_asset_for_path, and resolve the read path off the staging dir when the install transaction hasn't committed yet. PR #1153 / #1179's atomic asset transaction moves restored files into state.data_dir only at install time, so the previous existence check missed every just-restored avatar and the rows kept the unresolvable /api/avatars/file/<hash>.png URLs. Expose RestoredProfileAssets::staging_root() to support the same.
  • src-tauri/src/commands/storage/profile/legacy.rs: read the staging root from RestoredProfileAssets and pass it through import_legacy_profile_tables / import_legacy_profile_tables_with_restored_assets into the per-row normalizer. Normalize legacy text-encoded array fields (tags, characterIds, personaIds) on lorebook rows then union them with the junction-table-derived link IDs, so neither source is dropped and the lorebook editor doesn't crash on formTags.map is not a function. Also normalize legacy text-encoded bool fields (isGlobal, enabled, recursiveScanning, excludeFromVectorization) on lorebook rows; pre-refactor stored these as "true" / "false" strings, which the frontend reads as truthy and renders every scoped lorebook as Global.
  • src-tauri/src/commands/storage/profile/zip_import.rs: pass the staging root into the legacy branch alongside the restored_assets count.
  • src-tauri/src/commands/storage/imports/bulk_imports.rs: default import_st_chat_text to mode = "conversation" instead of the bogus "chat". The ChatMode enum is conversation | roleplay | visual_novel | game; the old default sat outside the enum, so imported chats never showed up in any mode sidebar.
  • src-tauri/src/commands/storage/imports/marinara.rs: in import_marinara_lorebook, normalize legacy text-encoded array fields (tags, characterIds, personaIds) and bool fields (isGlobal, enabled, recursiveScanning, excludeFromVectorization) before writing the lorebook row, matching the legacy profile-zip path.
  • src-tauri/src/commands/storage/shared.rs: add normalize_legacy_text_array_fields and normalize_legacy_text_bool_fields as the shared helpers both the marinara envelope path and the legacy profile-zip path use. The bool helper accepts true|1|yes|on and false|0|no|off as the truthy / falsy sets and coerces everything else (including malformed legacy values) to false.
  • src/features/catalog/presets/components/ImportPresetModal.tsx + src/features/catalog/lorebooks/components/ImportLorebookModal.tsx: relax the strict-equality detection so any marinara_* envelope (not only the exactly-matched type) routes to the Marinara importer instead of the permissive SillyTavern fallback. Matches the pattern the persona and character modals already use. The Rust router then rejects unsupported envelope types (marinara_chat_preset, marinara_memory_recall) with the existing "Unknown Marinara import type" error - clear failure instead of silent empty-record success.
  • src/engine/generation/prompt-assembly.ts: in buildActivatedEntries, use the listLorebookEntries(lorebookId) capability instead of calling storage.list("lorebooks/<id>/entries"). The path-style argument is a leftover from the pre-refactor HTTP API; the refactor storage layer rejects anything with a slash via validate_collection_name, so roleplay-mode chats with any attached lorebook surfaced Invalid collection name: lorebooks/<id>/entries the moment the user sent a message.

Verification

  • pnpm check and cargo clippy --all-targets -- -D warnings pass locally.
  • Reproduced and verified every path in pnpm tauri dev against a snapshot of the current production tables (31 characters, 20 personas, 32 lorebooks / 1492 entries, 5 chats with 126 messages and 24 memories, 3 chat presets, 18 connections, 9 chat-image gallery attachments):
    • chat-preset.marinara.json and memory-recall.marinara.json now produce a clear "Unknown Marinara import type: " error instead of creating empty preset / lorebook rows.
    • Individual character / persona / lorebook / preset .marinara.json files import cleanly; lorebooks open in the editor without the formTags.map crash.
    • SillyTavern .jsonl chat imports now appear under the conversation sidebar.
    • Full profile zip (49 MB, with the 9 chat-image attachments and all 51 character + persona avatars) imports end-to-end and every avatar resolves correctly post-install.
    • The lorebook list shows the correct Global count (5 of 32, matching the source) instead of marking every imported lorebook as global.
    • Roleplay-mode chats with one or more attached lorebooks send and receive without the Invalid collection name error; the prompt assembly fetches entries through the proper storage capability.
  • Not yet exercised on macOS or Linux. The Rust changes are platform-agnostic but Tauri behavior should still be confirmed cross-platform before release.

Linked issue

Closes #1180


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/1181 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 5/24/2026 **Status:** ✅ Merged **Merged:** 5/24/2026 **Merged by:** [@Romuromylus](https://github.com/Romuromylus) **Base:** `refactor` ← **Head:** `fix/pre-refactor-data-migration` --- ### 📝 Commits (7) - [`2239fc3`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2239fc3c3c30aeb4dd0c0f202e2c523fa1e33298) Fix pre-refactor data migration import gaps - [`68bb338`](https://github.com/Pasta-Devs/Marinara-Engine/commit/68bb33854cbf0fa4a49e0bcdbe7df9cd4101417c) Restore legacy avatar paths when assets are still staged - [`48791f8`](https://github.com/Pasta-Devs/Marinara-Engine/commit/48791f8d0b17bf37a91ed26578263909ecc25809) Update legacy import tests for staging_root parameter - [`bf92d15`](https://github.com/Pasta-Devs/Marinara-Engine/commit/bf92d15a48859726f0c11a05d04622f92abb406d) Read staged avatar bytes from staging dir, not data dir - [`d181d42`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d181d42de7fa4d669188202d2105ddc1bd397af5) Address CodeRabbit findings on legacy import normalization - [`def54cd`](https://github.com/Pasta-Devs/Marinara-Engine/commit/def54cda7db1d6865ac98b37a5891f85179215bb) Coerce legacy text-encoded bool fields on imported lorebooks - [`bc0a949`](https://github.com/Pasta-Devs/Marinara-Engine/commit/bc0a949c95fc6ef043af4f3c1e27286f8d06398e) Use listLorebookEntries capability for lorebook prompt assembly ### 📊 Changes **9 files changed** (+217 additions, -35 deletions) <details> <summary>View changed files</summary> 📝 `src-tauri/src/commands/storage/imports/bulk_imports.rs` (+1 -1) 📝 `src-tauri/src/commands/storage/imports/marinara.rs` (+19 -0) 📝 `src-tauri/src/commands/storage/profile/assets.rs` (+53 -10) 📝 `src-tauri/src/commands/storage/profile/legacy.rs` (+59 -18) 📝 `src-tauri/src/commands/storage/profile/zip_import.rs` (+2 -0) 📝 `src-tauri/src/commands/storage/shared.rs` (+64 -0) 📝 `src/engine/generation/prompt-assembly.ts` (+3 -1) 📝 `src/features/catalog/lorebooks/components/ImportLorebookModal.tsx` (+8 -3) 📝 `src/features/catalog/presets/components/ImportPresetModal.tsx` (+8 -2) </details> ### 📄 Description ## Why this change Existing users on the pre-refactor `staging` branch cannot move their data into the Tauri refactor without hitting one of eight import or post-import gaps. The full-profile zip is rejected outright if the user has any chat images, every imported avatar lands as a broken URL, individual lorebook imports crash the editor on open, individual chat imports become unreachable, two of the seven pre-refactor envelope types silently create empty rows instead of erroring, every imported lorebook renders as `Global` even when it was scoped, and any roleplay-mode chat with an attached lorebook fails to assemble a prompt at all. This PR fixes all eight gaps as one coherent change because they share a single theme - the refactor's importers, modals, and runtime don't yet account for the schema and envelope shapes the production app actually ships. Filed together at #1180. ## What changed - **`src-tauri/src/commands/storage/profile/assets.rs`**: add `"gallery"` to `PROFILE_ASSET_DIRS`. The pre-refactor backup set includes a `gallery/` directory for chat-image attachments; without this the `safe_profile_asset_path` allow-list rejected the entire profile zip with `Invalid profile asset path` for any user with chat images. Also thread an optional `staging_root` through `normalize_legacy_profile_asset_paths` and `legacy_profile_asset_for_path`, and resolve the read path off the staging dir when the install transaction hasn't committed yet. PR #1153 / #1179's atomic asset transaction moves restored files into `state.data_dir` only at install time, so the previous existence check missed every just-restored avatar and the rows kept the unresolvable `/api/avatars/file/<hash>.png` URLs. Expose `RestoredProfileAssets::staging_root()` to support the same. - **`src-tauri/src/commands/storage/profile/legacy.rs`**: read the staging root from `RestoredProfileAssets` and pass it through `import_legacy_profile_tables` / `import_legacy_profile_tables_with_restored_assets` into the per-row normalizer. Normalize legacy text-encoded array fields (`tags`, `characterIds`, `personaIds`) on lorebook rows then union them with the junction-table-derived link IDs, so neither source is dropped and the lorebook editor doesn't crash on `formTags.map is not a function`. Also normalize legacy text-encoded bool fields (`isGlobal`, `enabled`, `recursiveScanning`, `excludeFromVectorization`) on lorebook rows; pre-refactor stored these as `"true"` / `"false"` strings, which the frontend reads as truthy and renders every scoped lorebook as `Global`. - **`src-tauri/src/commands/storage/profile/zip_import.rs`**: pass the staging root into the legacy branch alongside the `restored_assets` count. - **`src-tauri/src/commands/storage/imports/bulk_imports.rs`**: default `import_st_chat_text` to `mode = "conversation"` instead of the bogus `"chat"`. The `ChatMode` enum is `conversation | roleplay | visual_novel | game`; the old default sat outside the enum, so imported chats never showed up in any mode sidebar. - **`src-tauri/src/commands/storage/imports/marinara.rs`**: in `import_marinara_lorebook`, normalize legacy text-encoded array fields (`tags`, `characterIds`, `personaIds`) and bool fields (`isGlobal`, `enabled`, `recursiveScanning`, `excludeFromVectorization`) before writing the lorebook row, matching the legacy profile-zip path. - **`src-tauri/src/commands/storage/shared.rs`**: add `normalize_legacy_text_array_fields` and `normalize_legacy_text_bool_fields` as the shared helpers both the marinara envelope path and the legacy profile-zip path use. The bool helper accepts `true|1|yes|on` and `false|0|no|off` as the truthy / falsy sets and coerces everything else (including malformed legacy values) to `false`. - **`src/features/catalog/presets/components/ImportPresetModal.tsx`** + **`src/features/catalog/lorebooks/components/ImportLorebookModal.tsx`**: relax the strict-equality detection so any `marinara_*` envelope (not only the exactly-matched type) routes to the Marinara importer instead of the permissive SillyTavern fallback. Matches the pattern the persona and character modals already use. The Rust router then rejects unsupported envelope types (`marinara_chat_preset`, `marinara_memory_recall`) with the existing "Unknown Marinara import type" error - clear failure instead of silent empty-record success. - **`src/engine/generation/prompt-assembly.ts`**: in `buildActivatedEntries`, use the `listLorebookEntries(lorebookId)` capability instead of calling `storage.list("lorebooks/<id>/entries")`. The path-style argument is a leftover from the pre-refactor HTTP API; the refactor storage layer rejects anything with a slash via `validate_collection_name`, so roleplay-mode chats with any attached lorebook surfaced `Invalid collection name: lorebooks/<id>/entries` the moment the user sent a message. ## Verification - `pnpm check` and `cargo clippy --all-targets -- -D warnings` pass locally. - Reproduced and verified every path in `pnpm tauri dev` against a snapshot of the current production tables (31 characters, 20 personas, 32 lorebooks / 1492 entries, 5 chats with 126 messages and 24 memories, 3 chat presets, 18 connections, 9 chat-image gallery attachments): - `chat-preset.marinara.json` and `memory-recall.marinara.json` now produce a clear "Unknown Marinara import type: <type>" error instead of creating empty preset / lorebook rows. - Individual character / persona / lorebook / preset `.marinara.json` files import cleanly; lorebooks open in the editor without the `formTags.map` crash. - SillyTavern `.jsonl` chat imports now appear under the conversation sidebar. - Full profile zip (49 MB, with the 9 chat-image attachments and all 51 character + persona avatars) imports end-to-end and every avatar resolves correctly post-install. - The lorebook list shows the correct `Global` count (5 of 32, matching the source) instead of marking every imported lorebook as global. - Roleplay-mode chats with one or more attached lorebooks send and receive without the `Invalid collection name` error; the prompt assembly fetches entries through the proper storage capability. - Not yet exercised on macOS or Linux. The Rust changes are platform-agnostic but Tauri behavior should still be confirmed cross-platform before release. ## Linked issue Closes #1180 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:12:04 +07:00
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#4963
No description provided.