[PR #7746] [MERGED] feat(game): save and restore game chat metadata in checkpoints #7911

Closed
opened 2026-10-24 04:08:45 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7746
Author: @ylli-selmani
Created: 10/16/2026
Status: ✅ Merged
Merged: 10/16/2026
Merged by: @ylli-selmani

Base: staging ← Head: feat/checkpoint-game-metadata


📝 Commits (5)

  • 8127494 feat(game): checkpoints save and restore the game's chat metadata
  • b708c2a fix(game): rewind the party's characterIds mirror on checkpoint load
  • 2ad47e5 fix(game): store an empty game-metadata capture as {}
  • 0673179 fix(game): checkpoints capture the chat's characterIds and restore them
  • 92e970c fix(game): keep the checkpoint metadata write readable to the key sweep

📊 Changes

4 files changed (+368 additions, -5 deletions)

View changed files

📝 packages/server/src/db/schema/checkpoints.ts (+8 -0)
📝 packages/server/src/routes/game.routes.ts (+21 -4)
📝 packages/server/src/services/game/checkpoint.service.ts (+87 -1)
➕ scripts/regressions/game-checkpoint-metadata.regression.ts (+252 -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 #7742. Prerequisite for #7743 (Game data in the State Editor).

Why this change

Before: a Game Mode checkpoint saved the turn's tracker snapshot, the spatial snapshot and the engine state. Loading one rewound the scene, but the party cards, NPCs, journal and inventory stayed as they were after the save, because those live in chat metadata.

After: a checkpoint also saves the game's own metadata keys, and loading it puts them back. An NPC met after the save is gone again, the party's HP and items are what they were, and the journal matches.

What changed

  • checkpoint.service.ts: CHECKPOINT_GAME_METADATA_KEYS, an allow-list of the keys a checkpoint saves: gameCharacterCards, gamePartyCharacterIds, gamePartySheet, gameNpcs, gameJournal, gamePlayerNotes, gameInventory, gameInventedItems, gameLootedFights, gameStartingGearTaken, gameWorldOverview, gameStoryArc, gamePlotTwists, gamePartyArcs, gamePreviousSessionSummaries, gameTime, gameWeather, gameMorale. create() copies the present ones into a new gameMetadataData column, so every caller (manual, session start/end, combat start/end) gets it. A game with none of them yet stores {}, so its load still clears keys added later.
  • create() also stores the chat's characterIds column (new chatCharacterIdsData). That column holds the party's library members, and session start trusts it over gamePartyCharacterIds.
  • buildCheckpointGameMetadataRestore: on load, a captured key is restored and an allow-listed key added after the save is cleared. Two companions follow:
    • The party sheet revision moves forward, never back, so a sheet still open from before the load gets the usual 409 instead of saving over the restored one.
    • gameInventoryTurn is dropped, because it records the tellings of stacks the load just replaced. This matches what a new session already does.
  • POST /game/checkpoint/load writes those keys, gameActiveState and the saved characterIds in one queued write (patchMetadataWithCharacterIds), so a member recruited after the save doesn't come back at the next session.
  • Deliberately not rewound: settings and prompt/media preferences (a rewind shouldn't undo a user's choices), ids, pins and lifecycle keys, live combat, caches, write ordinals, and the world, story and maps. Those three keep their own snapshots and checks (saveGameWorldSnapshot, the story checks), and leaving them out is the Game Mode maintainers' call (see the scope note on #7742).
  • Checkpoints from before this change (gameMetadataData null) load exactly as before.

How: the capture and the restore patch are pure functions, so the regression tests them directly and then end-to-end through the load route.

Commits

  • 8127494bb checkpoints save and restore the game's chat metadata
  • b708c2a34 rewind the party's characterIds on load (CodeRabbit)
  • 2ad47e509 store an empty capture as {} (CodeRabbit)
  • 067317933 capture the characterIds column itself, so saves without a party list rewind it too (CodeRabbit security review)
  • 92e970c4a keep the metadata write readable to the capability-gm-verbs key sweep (CI)

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

Ran: pnpm lint, server tsc --noEmit, prettier, and the regressions game-checkpoint-metadata (new), game-checkpoint-engine-state, checkpoint-retention, capability-gm-verbs and the other capability-* ones, open-issues, assigned-issue-sweep, multiplayer-session-flows and game-inventory-turn. All pass. Local CodeRabbit also ran.

Manual verification notes

  • There is no checkpoint screen in the client yet, so this was checked through the routes. The new regression creates a game chat, saves a checkpoint, changes cards, NPCs, inventory, journal, morale and a setting, then loads the checkpoint. The game keys are back, the later journal is cleared, and the setting keeps its new value.

  • Server-side edge cases covered by the regression:

    • a recruit added after the save leaves characterIds too, with or without a party list in the save;
    • an empty capture is stored as {} and still clears later keys;
    • a key absent both then and now is left alone;
    • an old checkpoint without the field leaves metadata untouched.

    The UI edge cases in the box above don't apply, since there's no UI.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) as needed
  • 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)

docs/game/sessions-and-saves.md still says there's no screen to restore checkpoints, which stays true. It gets updated with the Load checkpoint button in #7743.

UI evidence (if applicable)

None, server only.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Checkpoints now save selected game metadata and the party’s character list, then restore them when loaded.
    • Loading a checkpoint clears selected metadata values added after it was captured while preserving unrelated metadata.
    • Restoring a checkpoint updates the party-sheet revision and clears the inventory’s current-turn marker when applicable.
    • Checkpoints created before this update continue to load without changing current metadata.

🔄 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/7746 **Author:** [@ylli-selmani](https://github.com/ylli-selmani) **Created:** 10/16/2026 **Status:** ✅ Merged **Merged:** 10/16/2026 **Merged by:** [@ylli-selmani](https://github.com/ylli-selmani) **Base:** `staging` ← **Head:** `feat/checkpoint-game-metadata` --- ### 📝 Commits (5) - [`8127494`](https://github.com/Pasta-Devs/Marinara-Engine/commit/8127494bb557c2cb2dc0befd6d208491c6f9ab0d) feat(game): checkpoints save and restore the game's chat metadata - [`b708c2a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b708c2a3406b3bac50a878299a7b55df5daf97e6) fix(game): rewind the party's characterIds mirror on checkpoint load - [`2ad47e5`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2ad47e509832418bf81d21fcdd19e14d23d322c6) fix(game): store an empty game-metadata capture as {} - [`0673179`](https://github.com/Pasta-Devs/Marinara-Engine/commit/06731793396ea9702bef2ca6ad9d6d290151aa16) fix(game): checkpoints capture the chat's characterIds and restore them - [`92e970c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/92e970c4a062af96f66ed07e530aebf2650379e4) fix(game): keep the checkpoint metadata write readable to the key sweep ### 📊 Changes **4 files changed** (+368 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/db/schema/checkpoints.ts` (+8 -0) 📝 `packages/server/src/routes/game.routes.ts` (+21 -4) 📝 `packages/server/src/services/game/checkpoint.service.ts` (+87 -1) ➕ `scripts/regressions/game-checkpoint-metadata.regression.ts` (+252 -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 #7742. Prerequisite for #7743 (Game data in the State Editor). ## Why this change Before: a Game Mode checkpoint saved the turn's tracker snapshot, the spatial snapshot and the engine state. Loading one rewound the scene, but the party cards, NPCs, journal and inventory stayed as they were after the save, because those live in chat metadata. After: a checkpoint also saves the game's own metadata keys, and loading it puts them back. An NPC met after the save is gone again, the party's HP and items are what they were, and the journal matches. ## What changed - `checkpoint.service.ts`: `CHECKPOINT_GAME_METADATA_KEYS`, an **allow-list** of the keys a checkpoint saves: `gameCharacterCards`, `gamePartyCharacterIds`, `gamePartySheet`, `gameNpcs`, `gameJournal`, `gamePlayerNotes`, `gameInventory`, `gameInventedItems`, `gameLootedFights`, `gameStartingGearTaken`, `gameWorldOverview`, `gameStoryArc`, `gamePlotTwists`, `gamePartyArcs`, `gamePreviousSessionSummaries`, `gameTime`, `gameWeather`, `gameMorale`. `create()` copies the present ones into a new `gameMetadataData` column, so every caller (manual, session start/end, combat start/end) gets it. A game with none of them yet stores `{}`, so its load still clears keys added later. - `create()` also stores the chat's `characterIds` column (new `chatCharacterIdsData`). That column holds the party's library members, and session start trusts it over `gamePartyCharacterIds`. - `buildCheckpointGameMetadataRestore`: on load, a captured key is restored and an allow-listed key added after the save is cleared. Two companions follow: - The **party sheet revision moves forward**, never back, so a sheet still open from before the load gets the usual 409 instead of saving over the restored one. - `gameInventoryTurn` is dropped, because it records the tellings of stacks the load just replaced. This matches what a new session already does. - `POST /game/checkpoint/load` writes those keys, `gameActiveState` and the saved `characterIds` in one queued write (`patchMetadataWithCharacterIds`), so a member recruited after the save doesn't come back at the next session. - **Deliberately not rewound:** settings and prompt/media preferences (a rewind shouldn't undo a user's choices), ids, pins and lifecycle keys, live combat, caches, write ordinals, and the world, story and maps. Those three keep their own snapshots and checks (`saveGameWorldSnapshot`, the story checks), and leaving them out is the Game Mode maintainers' call (see the scope note on #7742). - Checkpoints from before this change (`gameMetadataData` null) load exactly as before. How: the capture and the restore patch are pure functions, so the regression tests them directly and then end-to-end through the load route. ### Commits - [x] `8127494bb` checkpoints save and restore the game's chat metadata - [x] `b708c2a34` rewind the party's `characterIds` on load (CodeRabbit) - [x] `2ad47e509` store an empty capture as `{}` (CodeRabbit) - [x] `067317933` capture the `characterIds` column itself, so saves without a party list rewind it too (CodeRabbit security review) - [x] `92e970c4a` keep the metadata write readable to the `capability-gm-verbs` key sweep (CI) ## 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) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` Ran: `pnpm lint`, server `tsc --noEmit`, prettier, and the regressions `game-checkpoint-metadata` (new), `game-checkpoint-engine-state`, `checkpoint-retention`, `capability-gm-verbs` and the other `capability-*` ones, `open-issues`, `assigned-issue-sweep`, `multiplayer-session-flows` and `game-inventory-turn`. All pass. Local CodeRabbit also ran. ### Manual verification notes - There is no checkpoint screen in the client yet, so this was checked through the routes. The new regression creates a game chat, saves a checkpoint, changes cards, NPCs, inventory, journal, morale and a setting, then loads the checkpoint. The game keys are back, the later journal is cleared, and the setting keeps its new value. - Server-side edge cases covered by the regression: - a recruit added after the save leaves `characterIds` too, with or without a party list in the save; - an empty capture is stored as `{}` and still clears later keys; - a key absent both then and now is left alone; - an old checkpoint without the field leaves metadata untouched. The UI edge cases in the box above don't apply, since there's no UI. ## Docs and release impact - [x] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) as needed - [ ] 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) `docs/game/sessions-and-saves.md` still says there's no screen to restore checkpoints, which stays true. It gets updated with the Load checkpoint button in #7743. ## UI evidence (if applicable) None, server only. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Checkpoints now save selected game metadata and the party’s character list, then restore them when loaded. * Loading a checkpoint clears selected metadata values added after it was captured while preserving unrelated metadata. * Restoring a checkpoint updates the party-sheet revision and clears the inventory’s current-turn marker when applicable. * Checkpoints created before this update continue to load without changing current metadata. <!-- 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-24 04:08:45 +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#7911
No description provided.