[GH-ISSUE #1893] Restore centralized storage schema/default and relation repair contracts #919

Closed
opened 2026-10-21 05:23:32 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @Xelvanis on GitHub (Jun 2, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1893

Originally assigned to: @Promansis on GitHub.

What problem does this solve?

Refactor storage is intentionally lightweight, but several storage contracts that legacy kept centralized are now scattered across command modules and startup repair code:

  • supported collection names
  • default field repair
  • typed JSON normalization
  • relationship cleanup/cascade behavior
  • profile/import/export inclusion

Legacy file-native storage kept a table registry, schema metadata, default row normalization, and a cascade map. Refactor compensates in several targeted places, but there is no single storage contract surface that proves all supported collections have defaults, cleanup behavior, and profile coverage.

Proposed behavior

Add a centralized storage contract registry for refactor collections that can answer:

  • whether a collection/entity is supported
  • which default fields should be repaired on load/create/import
  • which typed JSON fields should normalize or reject malformed values
  • which dependent collections/files need cleanup when a parent record is deleted
  • whether the collection is included in profile export/import and backup flows

This does not need to make storage heavy. It can be a focused Rust-side registry plus command-layer helpers where product behavior still belongs outside the low-level file store.

Expected owner or impact area

  • App shell, navigation, startup, or providers
  • Catalog resources: chats, characters, personas, lorebooks, presets, connections, agents, gallery, or knowledge
  • Chat mode
  • Roleplay mode
  • Game mode
  • Shared mode UI
  • Runtime systems: generation, world-state, visuals, tracker, or haptics
  • Professor Mari or shell tools
  • React-free engine behavior, contracts, agents, or capability ports
  • Shared API wrapper or remote runtime routing
  • Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime
  • Docs, contributor workflow, or templates

Refactor branch considerations

Keep product behavior in the owning feature/engine modules and keep privileged persistence in Rust. Avoid moving React/UI concepts into the storage crate. Preserve the refactor storage improvements that are better than legacy, especially streaming/projected message reads and append-oriented chat/message writes.

Alternatives considered

Leaving the current scattered repair paths avoids a new registry, but it makes future collection additions easy to miss in profile export, startup repair, delete cleanup, and remote-runtime validation.

Additional context

Static comparison points:

  • Refactor FileStorage handles generic JSON collections in src-tauri/crates/storage/src/lib.rs.
  • Refactor startup repair normalizes selected collections in src-tauri/src/state.rs.
  • Refactor create defaults and typed JSON normalization live in src-tauri/src/commands/storage/shared.rs.
  • Refactor profile export/import collection coverage lives in src-tauri/src/commands/storage/profile.rs.
  • Legacy file-native storage had FILE_BACKED_TABLES, schema metadata/default normalization, and CASCADES in packages/server/src/db/file-backed-store.ts.

Recommended first slice: create a registry for supported collections, then migrate duplicate-ID handling, profile coverage checks, and relation cleanup tests onto that registry.

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @Xelvanis on GitHub (Jun 2, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1893 Originally assigned to: @Promansis on GitHub. ## What problem does this solve? Refactor storage is intentionally lightweight, but several storage contracts that legacy kept centralized are now scattered across command modules and startup repair code: - supported collection names - default field repair - typed JSON normalization - relationship cleanup/cascade behavior - profile/import/export inclusion Legacy file-native storage kept a table registry, schema metadata, default row normalization, and a cascade map. Refactor compensates in several targeted places, but there is no single storage contract surface that proves all supported collections have defaults, cleanup behavior, and profile coverage. ## Proposed behavior Add a centralized storage contract registry for refactor collections that can answer: - whether a collection/entity is supported - which default fields should be repaired on load/create/import - which typed JSON fields should normalize or reject malformed values - which dependent collections/files need cleanup when a parent record is deleted - whether the collection is included in profile export/import and backup flows This does not need to make storage heavy. It can be a focused Rust-side registry plus command-layer helpers where product behavior still belongs outside the low-level file store. ## Expected owner or impact area - [ ] App shell, navigation, startup, or providers - [x] Catalog resources: chats, characters, personas, lorebooks, presets, connections, agents, gallery, or knowledge - [x] Chat mode - [x] Roleplay mode - [x] Game mode - [ ] Shared mode UI - [ ] Runtime systems: generation, world-state, visuals, tracker, or haptics - [ ] Professor Mari or shell tools - [ ] React-free engine behavior, contracts, agents, or capability ports - [x] Shared API wrapper or remote runtime routing - [x] Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime - [ ] Docs, contributor workflow, or templates ## Refactor branch considerations Keep product behavior in the owning feature/engine modules and keep privileged persistence in Rust. Avoid moving React/UI concepts into the storage crate. Preserve the refactor storage improvements that are better than legacy, especially streaming/projected message reads and append-oriented chat/message writes. ## Alternatives considered Leaving the current scattered repair paths avoids a new registry, but it makes future collection additions easy to miss in profile export, startup repair, delete cleanup, and remote-runtime validation. ## Additional context Static comparison points: - Refactor `FileStorage` handles generic JSON collections in `src-tauri/crates/storage/src/lib.rs`. - Refactor startup repair normalizes selected collections in `src-tauri/src/state.rs`. - Refactor create defaults and typed JSON normalization live in `src-tauri/src/commands/storage/shared.rs`. - Refactor profile export/import collection coverage lives in `src-tauri/src/commands/storage/profile.rs`. - Legacy file-native storage had `FILE_BACKED_TABLES`, schema metadata/default normalization, and `CASCADES` in `packages/server/src/db/file-backed-store.ts`. Recommended first slice: create a registry for supported collections, then migrate duplicate-ID handling, profile coverage checks, and relation cleanup tests onto that registry. ## Template check - [ ] I DID NOT read this template and provide the requested details.
Author
Owner

@Xelvanis commented on GitHub (Jun 2, 2026):

Additional concrete acceptance case for this storage-contract registry: #1895 tracks remote storage write behavior that still depends on duplicated command logic rather than one shared storage command surface.

Current code has embedded-only guards/side effects for connections and chat-presets:

  • selecting a connection as defaultForAgents clears other defaults in the same scope on the embedded path
  • default chat presets are protected from mutating default fields on the embedded path

The remote /api/invoke storage write path duplicates storage_create/storage_update and can bypass those behaviors. A future registry/shared-command cleanup should prove both embedded and remote writes use the same entity contract.

<!-- gh-comment-id:4599206118 --> @Xelvanis commented on GitHub (Jun 2, 2026): Additional concrete acceptance case for this storage-contract registry: #1895 tracks remote storage write behavior that still depends on duplicated command logic rather than one shared storage command surface. Current code has embedded-only guards/side effects for `connections` and `chat-presets`: - selecting a connection as `defaultForAgents` clears other defaults in the same scope on the embedded path - default chat presets are protected from mutating default fields on the embedded path The remote `/api/invoke` storage write path duplicates `storage_create`/`storage_update` and can bypass those behaviors. A future registry/shared-command cleanup should prove both embedded and remote writes use the same entity contract.
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#919
No description provided.