mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2981] [Issue]: Entry move transfer is non-atomic: a failure after copying duplicates entries into both lorebooks #1556
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#1556
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/2981
Originally assigned to: @SpicyMarinara on GitHub.
What's wrong
POST /api/lorebooks/:id/entries/transferwithoperation:"move"first creates copies of every source entry in the target lorebook, then in a separate loop deletes the originals from the source. There is no transaction spanning the two phases. If anyremoveEntryin the delete phase throws, or the process is interrupted between the two loops, the entries exist in both the target and the source: a "move" silently degrades into a duplicate, and the created copies are never cleaned up. (A successful move with valid inputs works correctly; this surfaces only on partial failure.)How to reproduce (try it yourself)
POST /api/lorebooks/A/entries/transfer{ "targetLorebookId": B, "entryIds":[E1,E2], "operation":"move" }.removeEntryfailure, or kill the server between the create and delete loops).You'll see: B has copies of E1+E2 and A still has the originals — duplicates across two lorebooks.
Expected: either the whole move applies or none of it does; entries end up only in B.
Where it is
packages/server/src/routes/lorebooks.routes.ts:639-656— the create-into-target loop (:641-648) then a separate delete-from-source loop (:650-653), with no transaction around them.packages/server/src/services/storage/lorebooks.storage.ts:510(createEntry, single insert) and:740-742(removeEntry, single delete).What's happening
The transfer route performs create (in target) and delete (from source) as two independent sequential loops with no transaction wrapping them, so a partial failure leaves both sides populated. Unlike
create()/update()/remove()in the storage layer, this multi-step cross-lorebook mutation is not transactional.Suggested fix
Make the move atomic at the storage layer. Add a transactional move method that threads a
txhandle through the copy-into-target and delete-from-source steps (mirroring howcreate()/update()/remove()already usedb.transactionwithtx.insert/tx.delete), so a failure in the delete phase rolls back the inserts. This is the backend-agnostic fix — note that wrapping the existing route-levelstorage.createEntry/storage.removeEntrycalls indb.transactionwould only roll back on the default file-native backend (whose rollback is async-context-based), not on the opt-inSTORAGE_BACKEND=sqlitebackend, because those storage methods use their owndbhandle rather than the transaction'stx. As a lighter alternative, perform compensating cleanup: if the delete phase throws, delete the copies just created in the target.AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.
@SpicyMarinara commented on GitHub (Jun 29, 2026):
Fixed in the v2.0.7 branch: entry transfer now cleans up target copies if any later transfer/delete step fails, preventing stranded duplicates from failed moves. Validated with pnpm check.