mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2960] [Issue]: Switching swipes while a message is still finishing generation can attach its thinking/sprite/reactions to the wrong swipe #1536
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#1536
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?
Originally created by @kolacheee on GitHub (Jun 28, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2960
Originally assigned to: @SpicyMarinara on GitHub.
What's wrong
Structural swipe operations (switch active swipe, add swipe, edit content, delete swipe) write the message row outside the per-message lock that serializes streaming
extraupdates. So if you switch swipes in the brief window where a generation is still persisting its post-stream extra (thinking / sprite expression / CYOA / reactions), the two writes can interleave and pin that extra onto the wrong swipe (or lose it).How to reproduce (try it yourself)
You'll see (intermittently, latency-dependent): the streamed thinking/sprite/reaction ends up attached to the swipe you switched to rather than the one that produced it, or goes missing.
Expected: streaming extra always lands on the swipe that produced it.
(This is a narrow, single-threaded-Node timing window and the corrupted data is
extraJSON metadata, not the message text body — but it's a real interleave.)Where it is
packages/server/src/services/storage/chats.storage.ts—setActiveSwipe(1070-1102),addSwipe(1017-1068),updateMessageContent(843-859), andremoveSwipewritemessages.extra/content/activeSwipeIndexwith baredb.update, whileupdateMessageExtra(862-874) andappendMessageAttachmentserialize throughwithPatchQueue(messageExtraPatchQueues, id). A related un-queued spot ischats.routes.ts:1701, which callsupdateSwipeExtrausing a previously-capturedactiveSwipeIndex.What's happening
db.transaction()is intentionally avoided in this store (libSQL stateful-transaction crash, noted at ~934), so the patch queue is the only mutual-exclusion mechanism for a message's row — and the structural swipe mutators don't join it. The realistically-fireable window is the sprite/CYOA/reactions post-stream persistence block, during which the unguarded active-swipe route is freely callable.Suggested fix
Route the
messages-row writes insetActiveSwipe,addSwipe,updateMessageContent, andremoveSwipe(and thechats.routes.ts:1701updateSwipeExtra) throughwithPatchQueue(messageExtraPatchQueues, id), so all mutations of a given message's row are mutually exclusive with the streaming extra patches.AI-investigated against v2.0.6; the queued vs un-queued writers confirmed. Please verify before fixing.
@SpicyMarinara commented on GitHub (Jun 29, 2026):
Fixed in staging: structural swipe mutations and generated extras are serialized per message; generation/retry-agent extras now patch the intended swipe index and only mirror to the message row when that swipe is active. Validated with pnpm check and pnpm regression:prompt.