[GH-ISSUE #5102] game-surface Experiences cannot persist state in game_engine_state — swipes/branches/checkpoints diverge #2822

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

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

Originally assigned to: @kolacheee on GitHub.

The gap

game_engine_state is the engine's per-(chatId, messageId, swipeIndex) state table, and it already rides every lifecycle seam a game state needs: swipe delete and re-index, message/chat/group delete prunes, branch re-anchoring, and (since #5077/#5084) checkpoint restore via getLatestAtOrBefore. But it is only reachable through the turn-game runner — a game-surface Experience (a package that owns an entire Game mode world) cannot store its state there.

So an Experience's world state lives in chat metadata instead: a whole-blob-rewrite store that no engine seam rewinds — swipes don't rewind the world, branches copy stale state under dead message anchors, and checkpoint restores skip it entirely. The engine does all of this correctly for its own stores; a package gets none of it.

(Package-registered routes are not an alternative: the sanctioned route registrar wraps requirePrivilegedAccess, which demands the admin secret off loopback — unusable from Android over LAN, the primary mobile deployment.)

Suggested fix

Host-owned routes on the game router exposing game_engine_state to the chat's stamped Experience, reusing createGameEngineStateStorage (#5084) unchanged:

  • GET /api/game/:chatId/experience-state → the latest visible row for the chat's Experience;
  • PUT /api/game/:chatId/experience-state → create/update a row anchored to the current turn.

Scoping and safety:

  • rows use gameType: "experience:<gameExperienceId>", and the routes refuse chats without a stamped gameExperienceId — an Experience can only touch its own chat's experience rows, and turn-game rows are never reachable;
  • a bounded state blob (the table is sharded per-chat, so this avoids both the metadata whole-blob rewrite and the monolithic capabilityDocuments table);
  • per the storage module's own caveat: writes should create a fresh row per message anchor (updating in place only within the same anchor), so checkpoint-time re-lookup recovers checkpoint-time state.

With this, an Experience's world inherits swipe/branch/checkpoint correctness from the engine instead of reimplementing (or lacking) it. Driving case: the pixel-RPG Experience's saves, currently in chat metadata with documented swipe-divergence. From the Pixelforge exploration roadmap (PR-E). Verified against current staging.

Originally created by @kolacheee on GitHub (Aug 15, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5102 Originally assigned to: @kolacheee on GitHub. ### The gap `game_engine_state` is the engine's per-`(chatId, messageId, swipeIndex)` state table, and it already rides every lifecycle seam a game state needs: swipe delete and re-index, message/chat/group delete prunes, branch re-anchoring, and (since #5077/#5084) checkpoint restore via `getLatestAtOrBefore`. But it is only reachable through the turn-game runner — a `game-surface` Experience (a package that owns an entire Game mode world) cannot store its state there. So an Experience's world state lives in chat metadata instead: a whole-blob-rewrite store that no engine seam rewinds — swipes don't rewind the world, branches copy stale state under dead message anchors, and checkpoint restores skip it entirely. The engine does all of this correctly for its own stores; a package gets none of it. (Package-registered routes are not an alternative: the sanctioned route registrar wraps `requirePrivilegedAccess`, which demands the admin secret off loopback — unusable from Android over LAN, the primary mobile deployment.) ### Suggested fix Host-owned routes on the game router exposing `game_engine_state` to the chat's stamped Experience, reusing `createGameEngineStateStorage` (#5084) unchanged: - `GET /api/game/:chatId/experience-state` → the latest visible row for the chat's Experience; - `PUT /api/game/:chatId/experience-state` → create/update a row anchored to the current turn. Scoping and safety: - rows use `gameType: "experience:<gameExperienceId>"`, and the routes refuse chats without a stamped `gameExperienceId` — an Experience can only touch its own chat's experience rows, and turn-game rows are never reachable; - a bounded `state` blob (the table is sharded per-chat, so this avoids both the metadata whole-blob rewrite and the monolithic `capabilityDocuments` table); - per the storage module's own caveat: writes should create a fresh row per message anchor (updating in place only within the same anchor), so checkpoint-time re-lookup recovers checkpoint-time state. With this, an Experience's world inherits swipe/branch/checkpoint correctness from the engine instead of reimplementing (or lacking) it. Driving case: the pixel-RPG Experience's saves, currently in chat metadata with documented swipe-divergence. From the Pixelforge exploration roadmap (PR-E). Verified against current `staging`.
bsakaguchi 2026-10-21 05:56:14 +07:00
Author
Owner

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

Taking this one (agent working from kolacheee's fork) — draft PR is up. One notable find while building the regression suite: game_engine_state's create() dedupe deleted prior rows for an anchor regardless of gameType, so the first-ever second writer in a chat would have silently clobbered the other's row — the dedupe is now scoped to the writer's own type, byte-identical for every existing single-writer chat.

<!-- gh-comment-id:5304571220 --> @kolacheee commented on GitHub (Aug 15, 2026): Taking this one (agent working from kolacheee's fork) — draft PR is up. One notable find while building the regression suite: game_engine_state's create() dedupe deleted prior rows for an anchor regardless of gameType, so the first-ever second writer in a chat would have silently clobbered the other's row — the dedupe is now scoped to the writer's own type, byte-identical for every existing single-writer chat.
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#2822
No description provided.