[GH-ISSUE #1923] [Bug]: Refactor regressed legacy message swipe sidecar storage #940

Closed
opened 2026-10-21 05:23:51 +07:00 by bsakaguchi · 2 comments
Owner

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

Originally assigned to: @SpicyMarinara on GitHub.

Regression summary

This is a bug/regression against legacy Marinara behavior, not a new storage feature request.

Legacy Marinara had message swipe sidecar storage: normal message rows and alternate swipe rows lived separately, with message_swipes storing swipe-specific content and metadata. Refactor currently does not preserve that sidecar layout; it stores alternate swipes nested inside each messages row.

That means refactor regressed the legacy storage shape that kept common message rows small and let swipe-heavy data be read only by focused swipe operations.

Expected legacy behavior

Common message list/get paths should be able to read message rows without loading full alternate swipe payloads. Swipe content and swipe-specific metadata should live in sidecar records, or an equivalent separate storage shape, and be fetched through swipe-specific operations when needed.

Legacy evidence:

  • packages/server/src/db/schema/chats.ts: messages and message_swipes were separate tables.
  • packages/server/src/services/storage/chats.storage.ts: list/paginated message paths queried message rows first and fetched only swipe counts from message_swipes; full swipe rows were fetched through focused swipe operations such as getSwipes, setActiveSwipe, and edit/remove helpers.

Actual refactor behavior

Refactor stores message swipes nested inside each messages row. Any path that needs active swipe content, active swipe extra, swipe count, or swipe previews depends on reading the row's swipes array, even when the caller only requested narrow message fields.

This came up while fixing #1919. Projected storage_get can now skip unrequested top-level row fields, but message-derived swipe fields still need swipes as an internal read field. Large swipe histories can therefore keep projected message gets/list reads heavier than the legacy sidecar shape.

Refactor evidence:

  • src-tauri/src/commands/storage/shared.rs: materialize_message_swipe_fields derives content, extra, swipeCount, and swipePreviews from nested swipes.
  • src-tauri/src/commands/storage/commands/entities.rs: projected message list/get paths need message_projection_fields_for_materialization(...), which adds swipes when caller-visible fields depend on swipe materialization.
  • src-tauri/crates/storage/src/lib.rs: nested projection currently cannot cheaply project array element subfields into the derived message shape; ProjectedNestedVisitor::visit_seq consumes arrays as ignored values when projected directly, so swipes has to be read as a full top-level field when materialization needs it.

Requested fix

Restore legacy parity by moving refactor message swipes back toward a sidecar storage shape, or an equivalent layout with the same read behavior, so message rows stay small and swipe-heavy data is read only by swipe-specific operations.

Suggested target shape:

  • Keep message-owned fields in messages: id, chatId, role, characterId, active content, activeSwipeIndex, active extra, timestamps, and other message metadata.
  • Store alternate swipe records separately with messageId, index, content, extra, timestamps, and any swipe-specific metadata.
  • Keep public storage_get/storage_list message response compatibility for current callers by materializing swipeCount, swipePreviews, active content, and active extra at the command/service boundary.
  • Provide focused storage helpers for full swipe CRUD and duplication/import/export paths.
  • Preserve embedded Tauri and remote /api/invoke behavior.

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

This is user-data and storage-layout work. It should not be folded into #1919 or another narrow projection fix.

Required proof should include:

  • migration/backfill for existing nested messages[].swipes data
  • rollback/recovery behavior for corrupt or partial storage files
  • chat import/export/profile export parity
  • chat duplication, branch/group delete, and message delete cascade behavior
  • swipe CRUD: add, set active, edit content, edit extra, remove, regenerate, and greeting swipes
  • projected message list/get performance and output compatibility
  • embedded Tauri and remote runtime parity
  • native-path proof, not just web/Vite proof

Architecture expectation: keep storage behavior in src-tauri/storage capability modules. Feature/UI callers should keep using focused shared API wrappers rather than learning the physical swipe storage layout.

Alternatives considered

Keep nested swipes and optimize array projection/materialization in-place. That would be less invasive, but it still leaves every message row carrying potentially large alternate content and metadata, and it does not restore the legacy separation that already kept common message reads small.

Treat #1919 as enough. That fixes projected gets for large character/resource rows and normal top-level projections, but it does not remove the nested-swipe read amplification for swipe-derived message fields.

Additional context

Related: #1919.

This is a legacy parity regression in refactor's storage shape, not a request to block the current projected storage_get fix. The safer sequence is to land the narrow projected-get fix first, then handle this as a dedicated storage migration branch.

Originally created by @Xelvanis on GitHub (Jun 2, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1923 Originally assigned to: @SpicyMarinara on GitHub. ## Regression summary This is a bug/regression against legacy Marinara behavior, not a new storage feature request. Legacy Marinara had message swipe sidecar storage: normal message rows and alternate swipe rows lived separately, with `message_swipes` storing swipe-specific content and metadata. Refactor currently does not preserve that sidecar layout; it stores alternate swipes nested inside each `messages` row. That means refactor regressed the legacy storage shape that kept common message rows small and let swipe-heavy data be read only by focused swipe operations. ## Expected legacy behavior Common message list/get paths should be able to read message rows without loading full alternate swipe payloads. Swipe content and swipe-specific metadata should live in sidecar records, or an equivalent separate storage shape, and be fetched through swipe-specific operations when needed. Legacy evidence: - `packages/server/src/db/schema/chats.ts`: `messages` and `message_swipes` were separate tables. - `packages/server/src/services/storage/chats.storage.ts`: list/paginated message paths queried message rows first and fetched only swipe counts from `message_swipes`; full swipe rows were fetched through focused swipe operations such as `getSwipes`, `setActiveSwipe`, and edit/remove helpers. ## Actual refactor behavior Refactor stores message swipes nested inside each `messages` row. Any path that needs active swipe content, active swipe extra, swipe count, or swipe previews depends on reading the row's `swipes` array, even when the caller only requested narrow message fields. This came up while fixing #1919. Projected `storage_get` can now skip unrequested top-level row fields, but message-derived swipe fields still need `swipes` as an internal read field. Large swipe histories can therefore keep projected message gets/list reads heavier than the legacy sidecar shape. Refactor evidence: - `src-tauri/src/commands/storage/shared.rs`: `materialize_message_swipe_fields` derives `content`, `extra`, `swipeCount`, and `swipePreviews` from nested `swipes`. - `src-tauri/src/commands/storage/commands/entities.rs`: projected message list/get paths need `message_projection_fields_for_materialization(...)`, which adds `swipes` when caller-visible fields depend on swipe materialization. - `src-tauri/crates/storage/src/lib.rs`: nested projection currently cannot cheaply project array element subfields into the derived message shape; `ProjectedNestedVisitor::visit_seq` consumes arrays as ignored values when projected directly, so `swipes` has to be read as a full top-level field when materialization needs it. ## Requested fix Restore legacy parity by moving refactor message swipes back toward a sidecar storage shape, or an equivalent layout with the same read behavior, so message rows stay small and swipe-heavy data is read only by swipe-specific operations. Suggested target shape: - Keep message-owned fields in `messages`: `id`, `chatId`, `role`, `characterId`, active `content`, `activeSwipeIndex`, active `extra`, timestamps, and other message metadata. - Store alternate swipe records separately with `messageId`, `index`, `content`, `extra`, timestamps, and any swipe-specific metadata. - Keep public `storage_get`/`storage_list` message response compatibility for current callers by materializing `swipeCount`, `swipePreviews`, active `content`, and active `extra` at the command/service boundary. - Provide focused storage helpers for full swipe CRUD and duplication/import/export paths. - Preserve embedded Tauri and remote `/api/invoke` behavior. ## 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 - [x] Shared mode UI - [x] 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 This is user-data and storage-layout work. It should not be folded into #1919 or another narrow projection fix. Required proof should include: - migration/backfill for existing nested `messages[].swipes` data - rollback/recovery behavior for corrupt or partial storage files - chat import/export/profile export parity - chat duplication, branch/group delete, and message delete cascade behavior - swipe CRUD: add, set active, edit content, edit extra, remove, regenerate, and greeting swipes - projected message list/get performance and output compatibility - embedded Tauri and remote runtime parity - native-path proof, not just web/Vite proof Architecture expectation: keep storage behavior in `src-tauri`/storage capability modules. Feature/UI callers should keep using focused shared API wrappers rather than learning the physical swipe storage layout. ## Alternatives considered Keep nested `swipes` and optimize array projection/materialization in-place. That would be less invasive, but it still leaves every message row carrying potentially large alternate content and metadata, and it does not restore the legacy separation that already kept common message reads small. Treat #1919 as enough. That fixes projected gets for large character/resource rows and normal top-level projections, but it does not remove the nested-swipe read amplification for swipe-derived message fields. ## Additional context Related: #1919. This is a legacy parity regression in refactor's storage shape, not a request to block the current projected `storage_get` fix. The safer sequence is to land the narrow projected-get fix first, then handle this as a dedicated storage migration branch.
Author
Owner

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

Closing as not planned for this issue pass. Splitting message swipes into a separate physical storage shape is a large user-data migration requiring backfill, rollback/recovery, import/export/profile parity, cascade behavior, swipe CRUD proof, and embedded/remote parity. I intentionally did not fold that migration into the current regression pass. The narrower projected storage_get work remains separate (#1924); this can be reopened or refiled when we want a dedicated storage-migration branch.

<!-- gh-comment-id:4601640941 --> @SpicyMarinara commented on GitHub (Jun 2, 2026): Closing as not planned for this issue pass. Splitting message swipes into a separate physical storage shape is a large user-data migration requiring backfill, rollback/recovery, import/export/profile parity, cascade behavior, swipe CRUD proof, and embedded/remote parity. I intentionally did not fold that migration into the current regression pass. The narrower projected storage_get work remains separate (#1924); this can be reopened or refiled when we want a dedicated storage-migration branch.
Author
Owner

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

https://github.com/Pasta-Devs/Marinara-Engine/pull/2008 Storage prep PR

<!-- gh-comment-id:4609605405 --> @Xelvanis commented on GitHub (Jun 3, 2026): https://github.com/Pasta-Devs/Marinara-Engine/pull/2008 Storage prep PR
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#940
No description provided.