[GH-ISSUE #1189] Avoid duplicate chat message loads in startGeneration #587

Closed
opened 2026-10-20 17:30:30 +07:00 by bsakaguchi · 1 comment
Owner

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

Originally assigned to: @cha1latte on GitHub.

Summary

startGeneration currently loads chat messages once before committing the visible tracker snapshot, then loads chat messages again immediately afterward for prompt assembly and tracker baseline selection.

This works, but it does extra storage work on the generation path. In long chats, that can make generation startup do more message-listing than necessary.

Current behavior

In src/engine/generation/start-generation.ts, the generation flow:

  1. Prepares the user input.
  2. If a user message will be saved, loads chat messages for commitVisibleTrackerSnapshotSafely.
  3. Saves the user message.
  4. Loads chat messages again into storedMessages.

The second load is still needed when saving the user message changes the timeline, but some paths should be able to reuse already-loaded messages.

Expected behavior

Reuse loaded chat messages when the timeline has not changed, and reload only when saving a user message actually changes the message list.

Suggested implementation

Keep the change scoped to startGeneration:

  • Load existing chat messages once before tracker snapshot commit when needed.
  • Reuse that list for generation paths where no new user message was saved.
  • Reload after saveUserMessage only when a saved user message changes the timeline.
  • Preserve existing tracker snapshot, regeneration, impersonation, and prompt assembly behavior.

Why this matters

This is a cleanup/performance chore, not a known correctness bug. It reduces repeated storage reads in the generation startup path and makes the tracker snapshot flow easier to reason about.

Verification

Suggested checks for the eventual PR:

  • pnpm typecheck
  • Existing focused generation tests, plus a test or assertion covering whether message loads are reused/reloaded in the right cases
Originally created by @Xelvanis on GitHub (May 25, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1189 Originally assigned to: @cha1latte on GitHub. ## Summary `startGeneration` currently loads chat messages once before committing the visible tracker snapshot, then loads chat messages again immediately afterward for prompt assembly and tracker baseline selection. This works, but it does extra storage work on the generation path. In long chats, that can make generation startup do more message-listing than necessary. ## Current behavior In `src/engine/generation/start-generation.ts`, the generation flow: 1. Prepares the user input. 2. If a user message will be saved, loads chat messages for `commitVisibleTrackerSnapshotSafely`. 3. Saves the user message. 4. Loads chat messages again into `storedMessages`. The second load is still needed when saving the user message changes the timeline, but some paths should be able to reuse already-loaded messages. ## Expected behavior Reuse loaded chat messages when the timeline has not changed, and reload only when saving a user message actually changes the message list. ## Suggested implementation Keep the change scoped to `startGeneration`: - Load existing chat messages once before tracker snapshot commit when needed. - Reuse that list for generation paths where no new user message was saved. - Reload after `saveUserMessage` only when a saved user message changes the timeline. - Preserve existing tracker snapshot, regeneration, impersonation, and prompt assembly behavior. ## Why this matters This is a cleanup/performance chore, not a known correctness bug. It reduces repeated storage reads in the generation startup path and makes the tracker snapshot flow easier to reason about. ## Verification Suggested checks for the eventual PR: - `pnpm typecheck` - Existing focused generation tests, plus a test or assertion covering whether message loads are reused/reloaded in the right cases
Author
Owner

@cha1latte commented on GitHub (May 25, 2026):

Closed in #1197

<!-- gh-comment-id:4537143606 --> @cha1latte commented on GitHub (May 25, 2026): Closed in #1197
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#587
No description provided.