[GH-ISSUE #1932] [Issue]: paged chat message reads parse full rows before projection #949

Closed
opened 2026-10-21 05:23:59 +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/1932

Originally assigned to: @cha1latte on GitHub.

Summary

Paged chat message reads can still parse full stored message rows before projection. storage_list calls for messages with filters.chatId, fields/fieldSelections, and limit/before route to the paged reader first, then project afterward. That means large extra, swipes, attachments, generation replay, and prompt snapshot payloads can still be parsed on active chat open, infinite scroll, tracker/world-state context reads, and post-generation refresh.

This is distinct from the closed projected read fixes. #1888 covered projected message reads without the paged path, and #1919 covered projected storage_get.

Expected behavior

Projected paged message reads should keep the storage-read shape narrow before parsing large row payloads. The hot timeline path should either:

  • use a projected page reader, or
  • use a focused compact timeline page helper that reads only fields needed for visible timeline rows, swipe counts/previews, and requested extra subfields.

Embedded Tauri and remote /api/invoke behavior should stay identical.

Actual behavior

Static trace on refactor at 8c36be60 shows:

  • src/features/catalog/chats/hooks/use-chats.ts:243 calls storageApi.listChatMessages with timelineMessageProjection(...) and limit.
  • src-tauri/src/commands/storage/commands/entities.rs:56 routes any message list with limit/before to list_messages_for_chat_page(...) before the projected message reader branch at :66.
  • src-tauri/crates/storage/src/lib.rs:2191 implements the reverse page scanner, and :2248 parses each matched message record as a full serde_json::Value.
  • src-tauri/src/commands/storage/commands/entities.rs:142-:151 materializes message swipe fields and projects only after rows have been read.
  • src/features/catalog/chats/lib/timeline-message.ts:15 requests swipePreviews, and :33-:36 request heavy extra subfields such as generation replay, prompt snapshot, attachments, and persona snapshot.
  • src/features/runtime/generation/hooks/use-generate.ts:339-:348 invalidates messages, message count, chat detail, and chat list after generation events, which can trigger the expensive path right when the user expects the UI to settle.
  • src/features/runtime/world-state/api/world-state-api.ts:179-:181 reads up to 200 recent messages for visible target context through the same paged list path.

Steps to reproduce

  1. Use a chat with a large message history and messages containing heavy extra, alternate swipes, attachments, or prompt snapshots.
  2. Open the chat, scroll history, open tracker/world-state surfaces, or complete a generation.
  3. Inspect storage_list calls for messages with filters.chatId, fields, fieldSelections, and limit.
  4. Observe that the code path uses the paged full-row reader before applying the requested projection.

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

Suggested proof:

  • Add focused cold/warm timing around paged storage_list(messages) with large extra, swipes, and attachments.
  • Prove a paged projected reader does not parse unrequested top-level fields.
  • Preserve swipeCount, swipePreviews, active swipe materialization, legacy prompt snapshot synthesis, and message cursor behavior.
  • Prove embedded Tauri and remote /api/invoke dispatch use the same path.

Additional context

Related but not duplicate:

  • #1888 fixed projected chat message reads that bypassed projection, but the current issue is the limit/before page path.
  • #1919 fixed projected storage_get, not paged storage_list.
  • #1923 discusses a larger physical swipe-storage split. This issue can be fixed first as a narrower read-path optimization.

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/1932 Originally assigned to: @cha1latte on GitHub. ## Summary Paged chat message reads can still parse full stored message rows before projection. `storage_list` calls for `messages` with `filters.chatId`, `fields`/`fieldSelections`, and `limit`/`before` route to the paged reader first, then project afterward. That means large `extra`, `swipes`, attachments, generation replay, and prompt snapshot payloads can still be parsed on active chat open, infinite scroll, tracker/world-state context reads, and post-generation refresh. This is distinct from the closed projected read fixes. #1888 covered projected message reads without the paged path, and #1919 covered projected `storage_get`. ## Expected behavior Projected paged message reads should keep the storage-read shape narrow before parsing large row payloads. The hot timeline path should either: - use a projected page reader, or - use a focused compact timeline page helper that reads only fields needed for visible timeline rows, swipe counts/previews, and requested `extra` subfields. Embedded Tauri and remote `/api/invoke` behavior should stay identical. ## Actual behavior Static trace on `refactor` at `8c36be60` shows: - `src/features/catalog/chats/hooks/use-chats.ts:243` calls `storageApi.listChatMessages` with `timelineMessageProjection(...)` and `limit`. - `src-tauri/src/commands/storage/commands/entities.rs:56` routes any message list with `limit`/`before` to `list_messages_for_chat_page(...)` before the projected message reader branch at `:66`. - `src-tauri/crates/storage/src/lib.rs:2191` implements the reverse page scanner, and `:2248` parses each matched message record as a full `serde_json::Value`. - `src-tauri/src/commands/storage/commands/entities.rs:142`-`:151` materializes message swipe fields and projects only after rows have been read. - `src/features/catalog/chats/lib/timeline-message.ts:15` requests `swipePreviews`, and `:33`-`:36` request heavy `extra` subfields such as generation replay, prompt snapshot, attachments, and persona snapshot. - `src/features/runtime/generation/hooks/use-generate.ts:339`-`:348` invalidates messages, message count, chat detail, and chat list after generation events, which can trigger the expensive path right when the user expects the UI to settle. - `src/features/runtime/world-state/api/world-state-api.ts:179`-`:181` reads up to 200 recent messages for visible target context through the same paged list path. ## Steps to reproduce 1. Use a chat with a large message history and messages containing heavy `extra`, alternate swipes, attachments, or prompt snapshots. 2. Open the chat, scroll history, open tracker/world-state surfaces, or complete a generation. 3. Inspect `storage_list` calls for `messages` with `filters.chatId`, `fields`, `fieldSelections`, and `limit`. 4. Observe that the code path uses the paged full-row reader before applying the requested projection. ## 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 Suggested proof: - Add focused cold/warm timing around paged `storage_list(messages)` with large `extra`, `swipes`, and attachments. - Prove a paged projected reader does not parse unrequested top-level fields. - Preserve `swipeCount`, `swipePreviews`, active swipe materialization, legacy prompt snapshot synthesis, and message cursor behavior. - Prove embedded Tauri and remote `/api/invoke` dispatch use the same path. ## Additional context Related but not duplicate: - #1888 fixed projected chat message reads that bypassed projection, but the current issue is the `limit`/`before` page path. - #1919 fixed projected `storage_get`, not paged `storage_list`. - #1923 discusses a larger physical swipe-storage split. This issue can be fixed first as a narrower read-path optimization. ## Template check - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:23:59 +07:00
Author
Owner

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

fixed in #1955

<!-- gh-comment-id:4604379832 --> @cha1latte commented on GitHub (Jun 2, 2026): fixed in #1955
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#949
No description provided.