[PR #1518] [MERGED] Harden legacy profile import against silent data loss and size limits #5117

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

📋 Pull Request Information

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

Base: refactor ← Head: fix/profile-import-robustness


📝 Commits (2)

  • 5f252b7 Harden legacy profile import against silent data loss and size limits
  • a7e068c Reject malformed legacy tables and correct the import warning copy

📊 Changes

3 files changed (+328 additions, -8 deletions)

View changed files

📝 src-tauri/src/commands/storage/profile/legacy.rs (+217 -1)
📝 src-tauri/src/commands/storage/profile/zip_import.rs (+98 -7)
📝 src/features/shell/settings/components/ProfileImportSection.tsx (+13 -0)

📄 Description

Why this change

Three issues from the Heavy Data / Legacy / Import smoke test (#1484) all live in the profile import path:

  • #1513 Legacy import left several lorebook-entry fields as TEXT instead of native types. caseSensitive, constant, locked, preventRecursion, excludeFromVectorization, selective and enabled came through as "true"/"false" strings, and the filter columns (characterFilterIds, characterTagFilters, additionalMatchingSources, activationConditions) as "[]" strings. The refactor reads these directly, so the entry editor showed the wrong toggle state (a string "false" is truthy in JS) and keyword-scanner.ts raw-truthiness checks could mis-treat entries as constant or suppress recursion.
  • #1512 A legacy import rebuilt replacements for the full fixed table list, so any collection absent from the file was wiped to empty. There was also no confirmation before the destructive replace.
  • #1511 marinara-profile.json was capped at 128MB, but heavy profiles inline their chat/message tables (and large fields like chats.memories), so a real heavy dataset could never be read.

What changed

  • src-tauri/src/commands/storage/profile/legacy.rs: coerce lorebook-entry bool/array fields to native types during import (matching the field set normalize_lorebook_entry produces); only replace collections whose table key is present in the file, so a partial file no longer wipes collections it omits (a present-but-empty table is still an explicit clear).
  • src-tauri/src/commands/storage/profile/zip_import.rs: stream the parse with serde_json::from_reader off the zip entry instead of buffering the whole file into a Vec, reject early on the declared uncompressed size (with .take as the hard backstop against an understated header), and raise the sanity cap to 1 GiB.
  • src/features/shell/settings/components/ProfileImportSection.tsx: add a destructive confirmation dialog before import.

Verification

  • pnpm check (architecture, frontend, rust, docs) passes locally.
  • cargo test --lib 176 passed / 0 failed, including 3 new regression tests: lorebook-entry bool/array coercion, partial-profile no-wipe, and a streaming zip import. The Rust fixes are exercised at the command-function level against the real storage backend.
  • cargo clippy --workspace --all-targets -- -D warnings clean; tsc -b clean.

Live pnpm tauri dev note: the only live path for these fixes is the real profile import, which replace_alls the running app's actual storage, so it is not safe to drive automatically against real data. The behavior is covered by the unit tests above (real storage layer on temp dirs). The 1 GiB boundary on a genuinely >128MB profile and the confirm dialog through the native file picker remain a recommended manual pass on a backed-up profile.

Follow-ups (deferred, not blocking)

  • keyword-scanner.ts still uses raw truthiness for constant / preventRecursion / caseSensitive. Root-caused here at the import boundary (stored data is now native), but defensive coercion in the scanner could be a separate hardening.
  • The skip-absent fix covers the legacy table import path. The modern data.collections import path has the same full-replace behavior and is tracked separately in #1521.
  • #1511 notes that chats.memories is stored inline on the chat row and can reach tens of MB on its own. Moving large inline fields out of marinara-profile.json is a larger format change left for later.

Linked issues

Closes #1511
Closes #1512
Closes #1513

Summary by CodeRabbit

Release Notes

  • New Features

    • Profile imports now require user confirmation before proceeding, with a warning that imported data will replace existing collections.
  • Bug Fixes

    • Fixed profile imports to preserve existing collections when imported files omit certain data.
    • Corrected type handling for legacy profile data during import.
  • Performance Improvements

    • Increased maximum profile file size limit to 1 GiB and optimized import process to stream data instead of loading entire files into memory.

Review Change Stack


🔄 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/1518 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 5/29/2026 **Status:** ✅ Merged **Merged:** 5/29/2026 **Merged by:** [@Romuromylus](https://github.com/Romuromylus) **Base:** `refactor` ← **Head:** `fix/profile-import-robustness` --- ### 📝 Commits (2) - [`5f252b7`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5f252b7d23f1b2f5e35f6c32719b0b630c5866f7) Harden legacy profile import against silent data loss and size limits - [`a7e068c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a7e068c77e2e3ca74e460b0518b38c6251b9fb03) Reject malformed legacy tables and correct the import warning copy ### 📊 Changes **3 files changed** (+328 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `src-tauri/src/commands/storage/profile/legacy.rs` (+217 -1) 📝 `src-tauri/src/commands/storage/profile/zip_import.rs` (+98 -7) 📝 `src/features/shell/settings/components/ProfileImportSection.tsx` (+13 -0) </details> ### 📄 Description ## Why this change Three issues from the Heavy Data / Legacy / Import smoke test (#1484) all live in the profile import path: - **#1513** Legacy import left several lorebook-entry fields as TEXT instead of native types. `caseSensitive`, `constant`, `locked`, `preventRecursion`, `excludeFromVectorization`, `selective` and `enabled` came through as `"true"`/`"false"` strings, and the filter columns (`characterFilterIds`, `characterTagFilters`, `additionalMatchingSources`, `activationConditions`) as `"[]"` strings. The refactor reads these directly, so the entry editor showed the wrong toggle state (a string `"false"` is truthy in JS) and `keyword-scanner.ts` raw-truthiness checks could mis-treat entries as constant or suppress recursion. - **#1512** A legacy import rebuilt replacements for the full fixed table list, so any collection absent from the file was wiped to empty. There was also no confirmation before the destructive replace. - **#1511** `marinara-profile.json` was capped at 128MB, but heavy profiles inline their chat/message tables (and large fields like `chats.memories`), so a real heavy dataset could never be read. ## What changed - `src-tauri/src/commands/storage/profile/legacy.rs`: coerce lorebook-entry bool/array fields to native types during import (matching the field set `normalize_lorebook_entry` produces); only replace collections whose table key is present in the file, so a partial file no longer wipes collections it omits (a present-but-empty table is still an explicit clear). - `src-tauri/src/commands/storage/profile/zip_import.rs`: stream the parse with `serde_json::from_reader` off the zip entry instead of buffering the whole file into a `Vec`, reject early on the declared uncompressed size (with `.take` as the hard backstop against an understated header), and raise the sanity cap to 1 GiB. - `src/features/shell/settings/components/ProfileImportSection.tsx`: add a destructive confirmation dialog before import. ## Verification - `pnpm check` (architecture, frontend, rust, docs) passes locally. - `cargo test --lib` 176 passed / 0 failed, including 3 new regression tests: lorebook-entry bool/array coercion, partial-profile no-wipe, and a streaming zip import. The Rust fixes are exercised at the command-function level against the real storage backend. - `cargo clippy --workspace --all-targets -- -D warnings` clean; `tsc -b` clean. Live `pnpm tauri dev` note: the only live path for these fixes is the real profile import, which `replace_all`s the running app's actual storage, so it is not safe to drive automatically against real data. The behavior is covered by the unit tests above (real storage layer on temp dirs). The 1 GiB boundary on a genuinely >128MB profile and the confirm dialog through the native file picker remain a recommended manual pass on a backed-up profile. ## Follow-ups (deferred, not blocking) - `keyword-scanner.ts` still uses raw truthiness for `constant` / `preventRecursion` / `caseSensitive`. Root-caused here at the import boundary (stored data is now native), but defensive coercion in the scanner could be a separate hardening. - The skip-absent fix covers the legacy table import path. The modern `data.collections` import path has the same full-replace behavior and is tracked separately in #1521. - #1511 notes that `chats.memories` is stored inline on the chat row and can reach tens of MB on its own. Moving large inline fields out of `marinara-profile.json` is a larger format change left for later. ## Linked issues Closes #1511 Closes #1512 Closes #1513 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **New Features** * Profile imports now require user confirmation before proceeding, with a warning that imported data will replace existing collections. * **Bug Fixes** * Fixed profile imports to preserve existing collections when imported files omit certain data. * Corrected type handling for legacy profile data during import. * **Performance Improvements** * Increased maximum profile file size limit to 1 GiB and optimized import process to stream data instead of loading entire files into memory. <!-- review_stack_entry_start --> [![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/Pasta-Devs/Marinara-Engine/pull/1518?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack) <!-- review_stack_entry_end --> <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:13:28 +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#5117
No description provided.