mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #2427] [MERGED] Persist partial assistant message when generation is stopped mid-stream #5601
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#5601
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2427
Author: @Romuromylus
Created: 6/6/2026
Status: ✅ Merged
Merged: 6/6/2026
Merged by: @Romuromylus
Base:
refactor← Head:fix/persist-partial-on-stop📝 Commits (1)
163b5e9Persist partial assistant message when generation is stopped mid-stream📊 Changes
1 file changed (+169 additions, -41 deletions)
View changed files
📝
src/engine/generation/start-generation.ts(+169 -41)📄 Description
Linked issue
Closes #2320
Why this change
throwIfAbortedgate propagated beforesaveAssistantMessageon both the main/agent and direct generation paths, so streamed text was thrown away instead of persisted.What changed
src/engine/generation/start-generation.ts:streamMainGenerationLoopnow exposes its accumulated turn through aStreamPartialSinkfilled in afinally— including the in-flight turn's tokens that hadn't yet been committed tocontent(thecontent += turnContentcommit only runs once a turn's stream completes, so a mid-turn abort needs the separateinFlightTurnmirror).saveAssistantMessage(withagentResults: [], preserving regenerate/impersonate routing viaexistingExtra) and emits theassistant_messageevent for the saved row before rethrowing, so the client upserts it before clearing the streaming buffer.Refactor impact
Primary owner: engine generation
Impact areas reviewed:
src/engine/generation/start-generation.ts(streamMainGenerationLoop, both stream callsites, newpersistPartialOnAbort+StreamPartialSink)Boundary notes:
content.trim()guard prevents an empty-content save; the partial-save is wrapped in try/catch so the original AbortError still propagates even if the save fails.Pressure points touched:
Validation
pnpm checkpasses before PR push/handoffManual verification notes
pnpm vitest run src/engine/generation/start-generation.test.ts— 16 existing pass. Local-only tests confirmed: an abort mid-stream on both the main and direct paths persists exactly one assistant row carrying the partial token and emits itsassistant_messageevent; an abort before any token saves nothing; and normal completion still saves exactly once (no double-save).pnpm exec tsc -bandpnpm exec eslint …start-generation.ts— clean.Feature Discoverability
src/features/shell/discovery/Reason:
Docs and release impact
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.