[PR #5419] [MERGED] fix(game): stamp the legacy checkpoint-restore fallback's createdAt #6760

Closed
opened 2026-10-23 04:13:27 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5419
Author: @kolacheee
Created: 8/22/2026
Status: ✅ Merged
Merged: 8/22/2026
Merged by: @kolacheee

Base: staging ← Head: fix/5418-legacy-restore-stamp


📝 Commits (1)

  • 4ac0575 fix(game): stamp the legacy checkpoint-restore fallback's createdAt

📊 Changes

3 files changed (+102 additions, -0 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 packages/server/src/routes/game.routes.ts (+12 -0)
📝 scripts/regressions/experience-state.regression.ts (+89 -0)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #5418

Why this change

  • The checkpoint-restore legacy fallback (used when a checkpoint has no usable engineStateData capture — pre-capture checkpoints, or a corrupt blob) was the last writer in the experience-state family that did not stamp createdAt. The #5405 stamp family runs strictly past the namespace's newest row, so a stamped burst legitimately runs ahead of the wall clock (a full 100-row import lands up to ~99 ms in the future); an unstamped now() landing inside that window sorts the freshly restored world behind rows it supersedes — flipping getLatest, the anchor-cap prune, and the next checkpoint's capture lookup back to a world the player just restored away from. Since #5406 the same row also carries a freshly allocated writeOrdinal (deliberately the chat's highest), so the row's two ordering signals disagreed. Surfaced as a CodeRabbit outside-diff finding on #5417 and dispositioned there as pre-existing #5405 behavior deserving its own PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5417#issuecomment-5383069183

What changed

  • The legacy fallback's engineStore.create now stamps createdAt through the same experienceStateStampBase(getLatest(chatId, cpEngineRow.gameType)) the captured-restore branch uses — one write site, no behavior change anywhere else.
  • Deliberate scope note: unlike the captured branch, this fallback restores whatever gameType its lookup finds, so the stamp can now apply to a restored turn-game row. That is consistent — the restore genuinely is that namespace's newest write — and in a namespace no stamped writer ever touched, the base collapses to plain now(), i.e. exactly the previous behavior.
  • Regression: new experience-state case 24 pins the inversion — an empty-capture checkpoint plus a future-stamped row; without the stamp, getLatest hands back the future-stamped row instead of the restored world. Proven fail-first (red on exactly that assertion with the stamp reverted, green with it).
  • CHANGELOG entry under Unreleased → Fixed.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

Boxes left for the human contributor per the template. What was agent-validated, exactly:

  • experience-state lanes 3/3 green (base incl. new case 24, ordinal, imported-anchors); checkpoint lanes 2/2 green; packages/server typecheck (tsc -b ../shared && tsc --noEmit) clean; prettier clean on all three touched files.
  • Fail-first proof for case 24 executed: stamp reverted → red on "the legacy-restored world is the namespace's newest"; restored → green.
  • NOT done: full pnpm check, container build/run.
  • No UI surface — a one-line server write-path fix; nothing to click through.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed — CHANGELOG entry under Unreleased; no user-facing docs affected
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

Summary by CodeRabbit

  • Bug Fixes

    • Fixed checkpoint restoration so recovered game states are timestamped after existing saves.
    • Ensured restored states remain the latest state, including when earlier saves have future timestamps.
    • Applied the fix consistently across supported game modes.
  • Tests

    • Added regression coverage for restoring checkpoints without captured world state.
  • Documentation

    • Added a changelog entry describing the checkpoint timestamping correction.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/5419 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 8/22/2026 **Status:** ✅ Merged **Merged:** 8/22/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `fix/5418-legacy-restore-stamp` --- ### 📝 Commits (1) - [`4ac0575`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4ac05751191700465c0bcf0c02141f7f0494c818) fix(game): stamp the legacy checkpoint-restore fallback's createdAt ### 📊 Changes **3 files changed** (+102 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `packages/server/src/routes/game.routes.ts` (+12 -0) 📝 `scripts/regressions/experience-state.regression.ts` (+89 -0) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. ## Linked issue Closes #5418 ## Why this change - The checkpoint-restore legacy fallback (used when a checkpoint has no usable `engineStateData` capture — pre-capture checkpoints, or a corrupt blob) was the last writer in the experience-state family that did not stamp `createdAt`. The #5405 stamp family runs strictly past the namespace's newest row, so a stamped burst legitimately runs ahead of the wall clock (a full 100-row import lands up to ~99 ms in the future); an unstamped `now()` landing inside that window sorts the freshly restored world **behind** rows it supersedes — flipping `getLatest`, the anchor-cap prune, and the next checkpoint's capture lookup back to a world the player just restored away from. Since #5406 the same row also carries a freshly allocated `writeOrdinal` (deliberately the chat's highest), so the row's two ordering signals disagreed. Surfaced as a CodeRabbit outside-diff finding on #5417 and dispositioned there as pre-existing #5405 behavior deserving its own PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5417#issuecomment-5383069183 ## What changed - The legacy fallback's `engineStore.create` now stamps `createdAt` through the same `experienceStateStampBase(getLatest(chatId, cpEngineRow.gameType))` the captured-restore branch uses — one write site, no behavior change anywhere else. - Deliberate scope note: unlike the captured branch, this fallback restores whatever `gameType` its lookup finds, so the stamp can now apply to a restored **turn-game** row. That is consistent — the restore genuinely is that namespace's newest write — and in a namespace no stamped writer ever touched, the base collapses to plain `now()`, i.e. exactly the previous behavior. - Regression: new `experience-state` case 24 pins the inversion — an empty-capture checkpoint plus a future-stamped row; without the stamp, `getLatest` hands back the future-stamped row instead of the restored world. Proven fail-first (red on exactly that assertion with the stamp reverted, green with it). - CHANGELOG entry under Unreleased → Fixed. ## Validation - [x] `pnpm check` passes locally - [x] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes Boxes left for the human contributor per the template. What was agent-validated, exactly: - `experience-state` lanes 3/3 green (base incl. new case 24, ordinal, imported-anchors); checkpoint lanes 2/2 green; `packages/server` typecheck (`tsc -b ../shared && tsc --noEmit`) clean; prettier clean on all three touched files. - Fail-first proof for case 24 executed: stamp reverted → red on "the legacy-restored world is the namespace's newest"; restored → green. - NOT done: full `pnpm check`, container build/run. - No UI surface — a one-line server write-path fix; nothing to click through. ## Docs and release impact - [ ] No docs changes needed - [x] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed — CHANGELOG entry under Unreleased; no user-facing docs affected - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Fixed checkpoint restoration so recovered game states are timestamped after existing saves. - Ensured restored states remain the latest state, including when earlier saves have future timestamps. - Applied the fix consistently across supported game modes. - **Tests** - Added regression coverage for restoring checkpoints without captured world state. - **Documentation** - Added a changelog entry describing the checkpoint timestamping correction. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:13:27 +07:00
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#6760
No description provided.