mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2712] [Issue]: Game checkpoint restore uses messageId+swipe:0 instead of snapshotId — fails after a message is deleted/swiped #1356
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#1356
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 21, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2712
Originally assigned to: @SpicyMarinara on GitHub.
Summary
Loading a game checkpoint resolves the saved snapshot by
messageId+swipeIndex:0instead of the storedsnapshotId, so a checkpoint loads the wrong swipe's state — or fails permanently — once the anchored message is deleted, regenerated, or was taken on a swiped message. The checkpoint's ownsnapshotId(still valid) is never used.Expected behavior
Loading a checkpoint should restore the exact snapshot it captured (via its stored
snapshotId), regardless of later message edits/deletions/swipes.Actual behavior
checkpoint.service.tspersists bothsnapshotIdandmessageId, but/game/checkpoint/loadresolves the snapshot viastateStore.getByMessage(cp.messageId, 0)and throws "Checkpoint snapshot no longer exists" if that returns null — the storedcp.snapshotIdis never used.getByMessagefilters bymessageIdANDswipeIndex(hardcoded0). Two failure modes: (1) a checkpoint taken on a swiped assistant message (swipeIndex > 0) loads the wrong snapshot or none; (2) if the original message was later deleted/regenerated/pruned,getByMessagereturns null and restore throws permanently — even thoughcp.snapshotIdstill points at a valid, recoverable snapshot row.How it breaks the pipeline
Code trace (staging @
b826f8f4):packages/server/src/services/game/checkpoint.service.ts:52-69(persists bothsnapshotIdandmessageId).packages/server/src/routes/game.routes.ts:7824(stateStore.getByMessage(cp.messageId, 0)),:7825(throws if null) —cp.snapshotIdunused.packages/server/src/services/game/game-state.storage.ts:189(getByMessagefilters bymessageIdANDswipeIndex, here0).Steps to reproduce
POST /game/checkpoint/loadwith that checkpoint → a 500 "Checkpoint snapshot no longer exists", or restoration of the wrong swipe's state.Suggested fix
Resolve the snapshot by
cp.snapshotIdfirst (add agetByIdtogame-state.storageand use it), falling back togetByMessageonly if needed. At minimum, don't hardcodeswipeIndex 0— resolve the snapshot the checkpoint actually captured.Environment
b826f8f4)Additional context
Found via a systematic multi-agent audit of Game Mode. Presents as "load checkpoint does nothing / errors" and effectively corrupt/unloadable saves. Part of a set of game-mode issues filed together.
Template check
Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:
@kolacheee commented on GitHub (Jun 21, 2026):
Two corrections and a fix note to keep this actionable (verified against the current tree):
Strongest repro / missed instance: swipe deletion re-indexes snapshots.
removeSwipe(packages/server/src/services/storage/chats.storage.ts:902-927) deletes the removed swipe's snapshot AND decrementsswipeIndexfor every higher snapshot on that message. So after deleting an earlier swipe, the snapshot the checkpoint captured now sits at a lowerswipeIndex, andgetByMessage(cp.messageId, 0)resolves the wrong one. Note the captured snapshot's row id is unchanged (onlyswipe_indexshifts), socp.snapshotIdis still recoverable here — which is exactly why resolving bysnapshotIdfixes it. Add this as the primary reproduction.Correction to failure mode 2: a message delete/regenerate/prune does NOT remove the snapshot.
removeMessage/removeMessages(chats.storage.ts:752-782) delete only message/swipe rows; there is nomessages -> game_state_snapshotscascade (file-backed-store.ts:205-227 cascades only chats->snapshots) and no DB-level FK cascade (game-state.ts:9-10: messageId is plain notNull, "cascade handled at application level"). Regeneration reuses the same messageId viaaddSwipe(generate.routes.ts:6397), leaving swipe-0's snapshot intact. So in those casesgetByMessage(cp.messageId, 0)returns a STALE swipe-0 snapshot (wrong-state restore), not null. The only path that produces "snapshot no longer exists / permanent throw" is swipe-deleting the exact captured swipe — and therecp.snapshotId's row is deleted too, so it is NOT recoverable via snapshotId either. Reword the "throws permanently / cp.snapshotId still valid" claim: those two never co-occur. The bug primarily manifests as restoring the WRONG swipe's state (silent corruption); hard failure is the narrow swipe-delete-of-the-captured-swipe case.Fix note: when resolving by
cp.snapshotId(addgetByIdto game-state.storage — there is no snapshotgetByIdtoday; the existing checkpoint.service.ts:79 getById is for the checkpoint row), do NOT silently fall back togetByMessage(cp.messageId, 0)on null. The only timegetById(cp.snapshotId)is null is when the captured snapshot row was actually deleted, and in that casegetByMessage(..., 0)would restore a DIFFERENT, wrong snapshot. Resolve strictly bysnapshotIdand, if the row is gone, throw a clear "snapshot was deleted" error instead of falling back.(Minor file-path nits, no impact on the diagnosis: the snapshot storage is at packages/server/src/services/storage/game-state.storage.ts, not services/game/...; and the load route is game.routes.ts:7813-7825 in the current tree.)
@SpicyMarinara commented on GitHub (Jun 21, 2026):
Fixed in
aedab566. Checkpoint load now resolves the exact captured game-state snapshot by checkpoint.snapshotId, verifies it belongs to the chat, and no longer falls back to messageId + swipeIndex 0, avoiding wrong-swipe restores after swipe reindexing.