mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #3002] [Issue]: Retry illustrator attachment uses a non-atomic read-modify-write instead of the atomic append helpers #1576
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#1576
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 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3002
Originally assigned to: @SpicyMarinara on GitHub.
What's wrong
The retry illustrator handler appends a generated image to the swipe (and conditionally the message) by manually reading the swipe/message extra, pushing onto the attachments array, and writing it back. The read happens OUTSIDE the per-message/per-swipe patch queue while only the write re-enters the queue. The canonical generate route uses dedicated atomic append helpers that perform the whole read-push-write inside the queue. Because the retry path writes back a full-array overwrite captured from a stale read, any attachment appended by a concurrent writer between the read and the queued write is silently clobbered (lost update). In a strictly sequential single retry this does not trigger; impact is limited to concurrent/overlapping attachment writes on the same message.
How to reproduce (try it yourself)
Difficult to trigger deterministically: requires a second attachment write to the same retryMessageId/retrySwipeIndex to interleave between the getSwipes read and the updateSwipeExtra write. Under normal single-retry sequential flow it does not reproduce.
You'll see: under a concurrent second attachment write, one append is lost (overwritten by the stale-array write).
Expected: both appends survive, as they do on the main generate route via the atomic helpers.
Where it is
packages/server/src/routes/generate/retry-agents-route.ts:2811-2828(illustrator attachment persistence). Atomic helpers:chats.storage.ts:964-977(appendMessageAttachment) and:1205-1218(appendSwipeAttachment). Canonical usage:generate.routes.ts:9049/9055.What's happening
Hand-rolled read-modify-write of the attachments array outside the storage layer's atomic append helpers. The read is not serialized with the write under the patch queue, so concurrent appends race and the full-array overwrite clobbers the other writer's entry.
Suggested fix
Replace the manual read-push-write block (2811-2828) with the atomic helpers, mirroring generate.routes.ts:9049/9055. Always append to the swipe; append to the message only when this swipe is still active (the message helper has no internal active-swipe guard, so keep the getMessage check):
This routes both appends through the patch queue, making them atomic against concurrent extra writes while preserving the existing swipe-exists and active-swipe semantics. The active-swipe guard MUST be kept:
appendMessageAttachmentappends unconditionally, so dropping the guard would leak a non-active-swipe illustration onto the live message row.appendSwipeAttachmentinternally no-ops when the swipe index doesn't exist, equivalent to the currentif (swipeRow)guard.AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.
@SpicyMarinara commented on GitHub (Jun 29, 2026):
Fixed in merged staging PR #3004.