[GH-ISSUE #2320] [Issue]: Pressing Stop mid-stream discards the entire partial assistant message (never persisted) #1147

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

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

Originally assigned to: @Romuromylus on GitHub.

Summary

Severity: Medium — Data-loss (work-in-progress). When the user presses Stop during streaming, the abort throws out of the stream loop before saveAssistantMessage runs, so the assistant text the user already watched stream in is discarded — it is never persisted, and the UI buffer is cleared. There is no way to keep, swipe, or continue from the partial. This differs from SillyTavern-style keep-on-stop behavior.

Expected behavior

A user-initiated Stop should "finish early with what we have": persist the partial assistant message generated so far, then cancel the remaining post-processing (agents/illustrations/tracker). The streamed text should remain in the chat.

Actual behavior

In src/engine/generation/start-generation.ts, streamMainGenerationLoop (3287-3453) accumulates the text in a local content returned only on normal completion (3452). throwIfAborted(signal) gates inside the loop throw abortGenerationError() the moment Stop fires, dropping the accumulated content. Both paths place throwIfAborted immediately before the only save:

} = yield* streamMainGenerationLoop({ ... signal });
throwIfAborted(signal);            // aborts here, before save
let content = streamedContent;
...
const saved = connected.suppressAssistantMessage ? null : await saveAssistantMessage({ ... content: displayContent, ... });

No partial-save path exists. The UI (use-generate.ts) persists the assistant message only via the message/assistant_message events, which the engine emits after saveAssistantMessage succeeds; on abort it throws first. The catch (1681-1687) rethrows AbortError and stopGenerationUi() clears the stream buffer, wiping the on-screen partial too.

Steps to reproduce

  1. Start a normal generation and let the model stream several tokens.
  2. Click Stop (ChatInput.tsx → chat.store.stopGeneration → controller.abort()).
  3. The streamed text vanishes and no assistant message is created.

Impact area

  • Chat mode
  • Roleplay mode
  • Game mode
  • Runtime systems: generation, world-state, visuals, tracker, or haptics

Environment

  • Branch or commit: refactor @ b0e5561d
  • Run mode: Tauri desktop (shared engine; also server mode)
  • OS + version: not relevant (static source audit)
  • Node + pnpm versions: not relevant
  • Rust version, if relevant: not relevant
  • Remote Runtime URL configured? not relevant (applies to both)
  • Provider, model, or integration, if relevant: any streaming generation

Logs, screenshots, or video

Static source audit; cited to file:line above.

Regression notes

Found via static audit of the refactor branch; not verified against main. Lost content is freshly generated and never-committed (no corruption of saved data) and Stop is explicit and regenerable, hence medium.

Additional context

Suggested fix: on AbortError, if the accumulated content/UI received buffer is non-empty, run saveAssistantMessage with the partial before propagating, then keep the heavier post-save throwIfAborted gates so agent/illustration/tracker work is still cancelled. Capture content via try/finally out of streamMainGenerationLoop so the caller can persist it when signal.aborted && content.trim().

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 @Romuromylus on GitHub (Jun 5, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2320 Originally assigned to: @Romuromylus on GitHub. ## Summary **Severity: Medium — Data-loss (work-in-progress).** When the user presses Stop during streaming, the abort throws out of the stream loop before `saveAssistantMessage` runs, so the assistant text the user already watched stream in is discarded — it is never persisted, and the UI buffer is cleared. There is no way to keep, swipe, or continue from the partial. This differs from SillyTavern-style keep-on-stop behavior. ## Expected behavior A user-initiated Stop should "finish early with what we have": persist the partial assistant message generated so far, then cancel the remaining post-processing (agents/illustrations/tracker). The streamed text should remain in the chat. ## Actual behavior In `src/engine/generation/start-generation.ts`, `streamMainGenerationLoop` (3287-3453) accumulates the text in a local `content` returned only on normal completion (3452). `throwIfAborted(signal)` gates inside the loop throw `abortGenerationError()` the moment Stop fires, dropping the accumulated content. Both paths place `throwIfAborted` immediately before the only save: ```ts } = yield* streamMainGenerationLoop({ ... signal }); throwIfAborted(signal); // aborts here, before save let content = streamedContent; ... const saved = connected.suppressAssistantMessage ? null : await saveAssistantMessage({ ... content: displayContent, ... }); ``` No partial-save path exists. The UI (`use-generate.ts`) persists the assistant message only via the `message`/`assistant_message` events, which the engine emits after `saveAssistantMessage` succeeds; on abort it throws first. The catch (1681-1687) rethrows AbortError and `stopGenerationUi()` clears the stream buffer, wiping the on-screen partial too. ## Steps to reproduce 1. Start a normal generation and let the model stream several tokens. 2. Click Stop (`ChatInput.tsx` → `chat.store.stopGeneration` → `controller.abort()`). 3. The streamed text vanishes and no assistant message is created. ## Impact area - [x] Chat mode - [x] Roleplay mode - [x] Game mode - [x] Runtime systems: generation, world-state, visuals, tracker, or haptics ## Environment - Branch or commit: refactor @ b0e5561d - Run mode: Tauri desktop (shared engine; also server mode) - OS + version: not relevant (static source audit) - Node + pnpm versions: not relevant - Rust version, if relevant: not relevant - Remote Runtime URL configured? not relevant (applies to both) - Provider, model, or integration, if relevant: any streaming generation ## Logs, screenshots, or video Static source audit; cited to file:line above. ## Regression notes Found via static audit of the refactor branch; not verified against main. Lost content is freshly generated and never-committed (no corruption of saved data) and Stop is explicit and regenerable, hence medium. ## Additional context Suggested fix: on `AbortError`, if the accumulated `content`/UI `received` buffer is non-empty, run `saveAssistantMessage` with the partial before propagating, then keep the heavier post-save `throwIfAborted` gates so agent/illustration/tracker work is still cancelled. Capture `content` via try/finally out of `streamMainGenerationLoop` so the caller can persist it when `signal.aborted && content.trim()`. ## 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:27:51 +07:00
Author
Owner

@Romuromylus commented on GitHub (Jun 6, 2026):

Fixed by #2427, merged into refactor.

<!-- gh-comment-id:4637904830 --> @Romuromylus commented on GitHub (Jun 6, 2026): Fixed by #2427, merged into `refactor`.
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#1147
No description provided.