[GH-ISSUE #2500] [Feature]: Add batch message and swipe creation for transcript imports #1241

Closed
opened 2026-10-21 05:29:45 +07:00 by bsakaguchi · 0 comments
Owner

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

What problem does this solve?

Refactor still creates imported/copied transcript messages one message at a time through message_swipes::create_message. The new uncached append helper improves the single-message path, but imports and transcript-copy workflows still repeat message+sidecar preparation, temp-file staging, locking, backup work, and parent chat timestamp decisions for every row.

Legacy had a dedicated createMessagesBatch storage path for this class of work. Its comments explicitly call out Windows/NTFS transaction/fsync cost and the need to preserve message timestamps, message extras, active swipe index, and full swipe lists during clone/import workflows.

Proposed behavior

Add a refactor batch message+swipe creation API owned by the storage/message-swipe layer. It should accept a target chat and prepared message inputs, produce both messages and message-swipes rows, and write the affected collections in one coherent operation.

Expected behavior for the batch path:

  • Preserve imported/copied createdAt, message extra, activeSwipeIndex, per-swipe content, per-swipe extra, per-swipe createdAt, and character IDs where provided.
  • Update the parent chat updatedAt once using an explicit caller policy, such as latest trusted imported timestamp or fresh branch timestamp.
  • Keep rollback/import cleanup behavior intact if any message or sidecar write fails.
  • Route bulk import, Marinara chat bulk import, and transcript copy/branch/scene flows through the batch path where that does not change product semantics.

Expected owner or impact area

  • 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 the owner in src-tauri storage/message-swipe commands. Feature/UI callers should continue using shared command/API surfaces rather than mutating message-swipes directly.

The storage operation should respect the current refactor sidecar design: message output can be materialized for compatibility, but durable storage should keep swipes in the sidecar collection. The batch write should also avoid fake success or partial import success when rollback/cleanup fails.

Alternatives considered

Keep using repeated create_message calls plus the new append_many_uncached shortcut. That is a useful single-message optimization, but it does not fully match legacy's batch-import surface and still spreads batch timestamp/rollback/performance concerns across import and copy callers.

Additional context

Static parity evidence:

  • Legacy packages/server/src/services/storage/chats.storage.ts has createMessagesBatch, including comments about Windows/NTFS cost and preserving copied/imported message+swipe metadata.
  • Legacy packages/server/src/services/import/st-chat.importer.ts uses createMessagesBatch for SillyTavern chat import.
  • Legacy packages/server/src/routes/scene.routes.ts uses createMessagesBatch for scene copy/export-to-standalone style workflows.
  • Refactor src-tauri/src/commands/storage/imports/bulk_imports.rs loops over parsed rows and calls message_swipes::create_message per message.
  • Refactor src-tauri/src/commands/storage/imports/marinara_chat_bulk.rs also loops through imported messages and calls message_swipes::create_message per message.
  • Refactor src-tauri/src/commands/storage/message_swipes.rs currently uses the new append_many_uncached only for one created message plus its swipes at a time.

Related but distinct from #2301: this asks for a durable batch transcript creation surface, not only removal of full-collection deep clone/rewrite work in individual message operations.

Template check

Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @Xelvanis on GitHub (Jun 6, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2500 ## What problem does this solve? Refactor still creates imported/copied transcript messages one message at a time through `message_swipes::create_message`. The new uncached append helper improves the single-message path, but imports and transcript-copy workflows still repeat message+sidecar preparation, temp-file staging, locking, backup work, and parent chat timestamp decisions for every row. Legacy had a dedicated `createMessagesBatch` storage path for this class of work. Its comments explicitly call out Windows/NTFS transaction/fsync cost and the need to preserve message timestamps, message extras, active swipe index, and full swipe lists during clone/import workflows. ## Proposed behavior Add a refactor batch message+swipe creation API owned by the storage/message-swipe layer. It should accept a target chat and prepared message inputs, produce both `messages` and `message-swipes` rows, and write the affected collections in one coherent operation. Expected behavior for the batch path: - Preserve imported/copied `createdAt`, message `extra`, `activeSwipeIndex`, per-swipe `content`, per-swipe `extra`, per-swipe `createdAt`, and character IDs where provided. - Update the parent chat `updatedAt` once using an explicit caller policy, such as latest trusted imported timestamp or fresh branch timestamp. - Keep rollback/import cleanup behavior intact if any message or sidecar write fails. - Route bulk import, Marinara chat bulk import, and transcript copy/branch/scene flows through the batch path where that does not change product semantics. ## Expected owner or impact area - [x] Catalog resources: chats, characters, personas, lorebooks, presets, connections, agents, gallery, or knowledge - [x] 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 - [x] Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime - [ ] Docs, contributor workflow, or templates ## Refactor branch considerations Keep the owner in `src-tauri` storage/message-swipe commands. Feature/UI callers should continue using shared command/API surfaces rather than mutating `message-swipes` directly. The storage operation should respect the current refactor sidecar design: message output can be materialized for compatibility, but durable storage should keep swipes in the sidecar collection. The batch write should also avoid fake success or partial import success when rollback/cleanup fails. ## Alternatives considered Keep using repeated `create_message` calls plus the new `append_many_uncached` shortcut. That is a useful single-message optimization, but it does not fully match legacy's batch-import surface and still spreads batch timestamp/rollback/performance concerns across import and copy callers. ## Additional context Static parity evidence: - Legacy `packages/server/src/services/storage/chats.storage.ts` has `createMessagesBatch`, including comments about Windows/NTFS cost and preserving copied/imported message+swipe metadata. - Legacy `packages/server/src/services/import/st-chat.importer.ts` uses `createMessagesBatch` for SillyTavern chat import. - Legacy `packages/server/src/routes/scene.routes.ts` uses `createMessagesBatch` for scene copy/export-to-standalone style workflows. - Refactor `src-tauri/src/commands/storage/imports/bulk_imports.rs` loops over parsed rows and calls `message_swipes::create_message` per message. - Refactor `src-tauri/src/commands/storage/imports/marinara_chat_bulk.rs` also loops through imported messages and calls `message_swipes::create_message` per message. - Refactor `src-tauri/src/commands/storage/message_swipes.rs` currently uses the new `append_many_uncached` only for one created message plus its swipes at a time. Related but distinct from #2301: this asks for a durable batch transcript creation surface, not only removal of full-collection deep clone/rewrite work in individual message operations. ## Template check Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:29:45 +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#1241
No description provided.