[GH-ISSUE #5418] Checkpoint-restore legacy fallback writes the only unstamped experience-state createdAt #3001

Closed
opened 2026-10-21 05:58:43 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @kolacheee on GitHub (Aug 22, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5418

Originally assigned to: @kolacheee on GitHub.

The checkpoint-restore legacy fallback in packages/server/src/routes/game.routes.ts (the branch used when a checkpoint has no usable engineStateData capture — pre-#5102 checkpoints, or a corrupt blob) is now the only game_engine_state writer in the experience-state family that does not stamp createdAt. The PUT, the bulk import, and the captured-restore branch all stamp strictly past the namespace's newest row via experienceStateStampBase (#5405); the legacy fallback still takes the store's default now().

Why this matters: experienceStateStampBase returns max(now, newest + 1), so a stamped burst can legitimately run ahead of the wall clock — a full 100-row import stamps up to ~99 ms into the future. An unstamped now() landing inside that window sorts behind rows that were written before it. createdAt is the sole recency key for getLatest, the anchor-cap prune, and the next checkpoint's capture lookup, so the freshly restored world can lose all three to rows it was meant to supersede — an ordering inversion, not just a cosmetic tie.

Once #5417 lands there is a second consequence: that same fallback row gets a freshly allocated writeOrdinal (deliberately the highest in the chat), so the row carries two ordering signals that disagree — writeOrdinal says newest, createdAt may not. Nothing breaks today because the boot comparison reads writeOrdinal while createdAt drives the prune/getLatest family, but the two should agree rather than depending on consumers never crossing.

Fix shape: stamp the legacy-fallback write through the same experienceStateStampBase(getLatest(chatId, cpEngineRow.gameType)) the captured branch uses. Note this branch restores whatever gameType the lookup finds, so the stamp would also apply to a restored turn-game row — that is consistent (the restore is genuinely the namespace's newest write, and the stamp collapses to now() in a namespace that has never been future-stamped), but it is a deliberate widening of #5405's stamp family and worth stating in the PR.

Surfaced by CodeRabbit's outside-diff-range finding on PR #5417 and dispositioned there: https://github.com/Pasta-Devs/Marinara-Engine/pull/5417#issuecomment-5383069183 (declined for that PR — the asymmetry is pre-existing #5405 behavior on staging, and #5417 was already carrying a cross-feature merge).

Originally created by @kolacheee on GitHub (Aug 22, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5418 Originally assigned to: @kolacheee on GitHub. The checkpoint-restore legacy fallback in `packages/server/src/routes/game.routes.ts` (the branch used when a checkpoint has no usable `engineStateData` capture — pre-#5102 checkpoints, or a corrupt blob) is now the only `game_engine_state` writer in the experience-state family that does not stamp `createdAt`. The PUT, the bulk import, and the captured-restore branch all stamp strictly past the namespace's newest row via `experienceStateStampBase` (#5405); the legacy fallback still takes the store's default `now()`. Why this matters: `experienceStateStampBase` returns `max(now, newest + 1)`, so a stamped burst can legitimately run ahead of the wall clock — a full 100-row import stamps up to ~99 ms into the future. An unstamped `now()` landing inside that window sorts **behind** rows that were written before it. `createdAt` is the sole recency key for `getLatest`, the anchor-cap prune, and the next checkpoint's capture lookup, so the freshly restored world can lose all three to rows it was meant to supersede — an ordering inversion, not just a cosmetic tie. Once #5417 lands there is a second consequence: that same fallback row gets a freshly allocated `writeOrdinal` (deliberately the highest in the chat), so the row carries two ordering signals that disagree — `writeOrdinal` says newest, `createdAt` may not. Nothing breaks today because the boot comparison reads `writeOrdinal` while `createdAt` drives the prune/`getLatest` family, but the two should agree rather than depending on consumers never crossing. Fix shape: stamp the legacy-fallback write through the same `experienceStateStampBase(getLatest(chatId, cpEngineRow.gameType))` the captured branch uses. Note this branch restores whatever `gameType` the lookup finds, so the stamp would also apply to a restored turn-game row — that is consistent (the restore is genuinely the namespace's newest write, and the stamp collapses to `now()` in a namespace that has never been future-stamped), but it is a deliberate widening of #5405's stamp family and worth stating in the PR. Surfaced by CodeRabbit's outside-diff-range finding on PR #5417 and dispositioned there: https://github.com/Pasta-Devs/Marinara-Engine/pull/5417#issuecomment-5383069183 (declined for that PR — the asymmetry is pre-existing #5405 behavior on staging, and #5417 was already carrying a cross-feature merge).
bsakaguchi 2026-10-21 05:58:43 +07:00
Author
Owner

@kolacheee commented on GitHub (Aug 22, 2026):

Taking this one (kolacheee, agent-assisted) — branch fix/5418-legacy-restore-stamp incoming.

<!-- gh-comment-id:5383079668 --> @kolacheee commented on GitHub (Aug 22, 2026): Taking this one (kolacheee, agent-assisted) — branch `fix/5418-legacy-restore-stamp` incoming.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#3001
No description provided.