mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2961] [Issue]: Turn-game (UNO) engine state isn't deleted with its message/chat — it leaks and can resurface #1537
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#1537
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/2961
Originally assigned to: @SpicyMarinara on GitHub.
What's wrong
The per-turn game-engine snapshots used by turn-games (UNO) are never cleaned up when a message or a whole chat is deleted. Two consequences:
gameEngineStaterows accumulate forever. On the default "files" backend chat-deletion cleans them up, but on the opt-inSTORAGE_BACKEND=sqlite(libSQL) backend they're left behind on chat/group deletion too (no FK cascade, not in the manual cleanup list).How to reproduce (try it yourself)
Resurfacing (edge case):
gameEngineStaterows accumulate.You'll see: the engine resolver falls back to the orphaned (deleted) state instead of resetting to the opening/empty state.
Expected: deleting turn messages removes their engine state too.
(The common case — deleting only the most-recent assistant turn — does not resurface, because the surviving prior turn has its own anchored engine row that wins.)
Leaked rows: deleting a game chat (or branch group) leaves its
game_engine_staterows in the DB; onSTORAGE_BACKEND=sqlitethey're never removed.Where it is
packages/server/src/services/storage/chats.storage.ts—deleteGameStateForMessages(248-268) deletesgameStateSnapshots+gameCheckpointsbut nevergameEngineState; it's called byremoveMessage(979-986) /removeMessages(988-1011). ContrastremoveSwipe(~1160-1172), which does prunegameEngineState— so the omission is inconsistent. For whole-chat delete,remove()(585-598) andremoveGroup()(601-615) also skipgameEngineState, and the libSQL table (migrate.ts~367-377) has a barechat_idwith noREFERENCES chats(id) ON DELETE CASCADE. The resolver fallback that resurfaces orphans isgame-engine-state.storage.tsgetLatest/getLatestCommitted(~28-46), which selects bychatId + createdAtwith no message-existence check.What's happening
gameEngineStateis the one chats child table missing from both the manual per-message/per-chat cleanup lists and (on libSQL) the FK cascade set, so its rows are orphaned on delete. The turn-game runner first tries an anchored lookup by the surviving message id, so single deletes are safe; when that misses it falls through to the unanchored newest-by-createdAtrow, which can be the orphan.Suggested fix
Add
await db.delete(gameEngineState).where(inArray(gameEngineState.messageId, chunk));insidedeleteGameStateForMessages(mirroring the prune already inremoveSwipe), and addawait db.delete(gameEngineState).where(eq(gameEngineState.chatId, id));toremove()and theremoveGroup()per-chat loop (or add the FK cascade to the libSQL table). The "files" backend cascade already handles chat-level deletes.AI-investigated against v2.0.6; the cleanup helper and the removeSwipe contrast confirmed. Please verify before fixing.
@SpicyMarinara commented on GitHub (Jun 29, 2026):
Fixed in staging: turn-game engine snapshots are removed on message/chat/group deletion and pruned/shifted with swipe deletion. Validated with pnpm check and pnpm regression:prompt.