[GH-ISSUE #5131] [Issue]: Branching a Conversation chat drops its turn-game state (game_engine_state copy gated to game mode) #2836

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

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

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Branching a Conversation chat that has an active turn-game (UNO, Chess, Poker, Tic-Tac-Toe, Rock-Paper-Scissors, etc.) drops the turn-game's engine state on the new branch. The branch route only creates the game_engine_state copy store when sourceChat.mode === "game", but turn-games run in Conversation mode, so their engine rows are never copied to the branch.

Expected behavior

Branching a Conversation chat should carry the turn-game's game_engine_state rows to the new branch (the same way the route already copies game-mode tracker/spatial snapshots), so the branch continues the game from the branch point.

Actual behavior

The turn-game state is lost on the branch. The new branch has no game_engine_state rows, so the turn-game resets/disappears in the branch, while the source chat is unaffected.

Steps to reproduce

  1. In a Conversation chat, start a turn-game via its slash command (e.g. Chess/UNO/Poker) and make a few moves so game_engine_state rows exist for the chat.
  2. Branch the chat (fork at a message).
  3. Open the new branch: the turn-game state is gone — it was not copied — even though the source chat still has it.

Environment

  • Marinara Engine version: staging (2.4.3); present in every release since the engine-state branch-copy was added
  • Install type: source (server-side logic, environment-independent)
  • OS + version: n/a
  • Browser or app shell: n/a

Root cause

packages/server/src/routes/chats.routes.ts, the chat-branch route (~L3899):

const gameEngineStore =
  sourceChat.mode === "game"
    ? createGameEngineStateStorage(app.db)
    : null;

game_engine_state holds both game-surface Experience state (Game mode) and turn-game state (Conversation mode). The mode === "game" gate excludes Conversation, so the downstream engine-state copy loop (each site guarded by if (gameEngineStore)) is skipped entirely for Conversation branches.

This is pre-existing: the gate was introduced when the engine-state branch-copy was first added (commit e1e378b7e), and it is unchanged on staging. It is independent of the experience-state work in #5106 — that PR reworked the per-anchor copy loop (limit(1) → all rows) but not this mode gate. CodeRabbit surfaced it while reviewing #5106's nearby change, which is why it is filed here separately.

Suggested fix

Create gameEngineStore for Conversation as well as Game mode (null for other modes), so the existing copy loop runs for Conversation turn-games:

const gameEngineStore =
  sourceChat.mode === "game" || sourceChat.mode === "conversation"
    ? createGameEngineStateStorage(app.db)
    : null;

(Creating it unconditionally would also work — the copy loop is a no-op when a chat has no engine rows.) A regression should branch a Conversation chat that has turn-game engine rows and assert the branch retains them at the re-keyed anchors.

Additional context

Found during CodeRabbit's review of #5106 (host-owned experience-state routes). Related engine-state-on-branch handling lives in the same route; this specific gap concerns Conversation-mode turn-games, not the game-surface Experiences that PR targets.

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @kolacheee on GitHub (Aug 16, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5131 Originally assigned to: @SpicyMarinara on GitHub. ## Summary Branching a **Conversation** chat that has an active turn-game (UNO, Chess, Poker, Tic-Tac-Toe, Rock-Paper-Scissors, etc.) drops the turn-game's engine state on the new branch. The branch route only creates the `game_engine_state` copy store when `sourceChat.mode === "game"`, but turn-games run in Conversation mode, so their engine rows are never copied to the branch. ## Expected behavior Branching a Conversation chat should carry the turn-game's `game_engine_state` rows to the new branch (the same way the route already copies game-mode tracker/spatial snapshots), so the branch continues the game from the branch point. ## Actual behavior The turn-game state is lost on the branch. The new branch has no `game_engine_state` rows, so the turn-game resets/disappears in the branch, while the source chat is unaffected. ## Steps to reproduce 1. In a Conversation chat, start a turn-game via its slash command (e.g. Chess/UNO/Poker) and make a few moves so `game_engine_state` rows exist for the chat. 2. Branch the chat (fork at a message). 3. Open the new branch: the turn-game state is gone — it was not copied — even though the source chat still has it. ## Environment - Marinara Engine version: `staging` (2.4.3); present in every release since the engine-state branch-copy was added - Install type: source (server-side logic, environment-independent) - OS + version: n/a - Browser or app shell: n/a ## Root cause `packages/server/src/routes/chats.routes.ts`, the chat-branch route (~L3899): ```ts const gameEngineStore = sourceChat.mode === "game" ? createGameEngineStateStorage(app.db) : null; ``` `game_engine_state` holds **both** game-surface Experience state (Game mode) **and** turn-game state (Conversation mode). The `mode === "game"` gate excludes Conversation, so the downstream engine-state copy loop (each site guarded by `if (gameEngineStore)`) is skipped entirely for Conversation branches. This is **pre-existing**: the gate was introduced when the engine-state branch-copy was first added (commit `e1e378b7e`), and it is unchanged on `staging`. It is independent of the experience-state work in #5106 — that PR reworked the per-anchor copy loop (`limit(1)` → all rows) but not this mode gate. CodeRabbit surfaced it while reviewing #5106's nearby change, which is why it is filed here separately. ## Suggested fix Create `gameEngineStore` for Conversation as well as Game mode (null for other modes), so the existing copy loop runs for Conversation turn-games: ```ts const gameEngineStore = sourceChat.mode === "game" || sourceChat.mode === "conversation" ? createGameEngineStateStorage(app.db) : null; ``` (Creating it unconditionally would also work — the copy loop is a no-op when a chat has no engine rows.) A regression should branch a Conversation chat that has turn-game engine rows and assert the branch retains them at the re-keyed anchors. ## Additional context Found during CodeRabbit's review of #5106 (host-owned experience-state routes). Related engine-state-on-branch handling lives in the same route; this specific gap concerns Conversation-mode turn-games, not the game-surface Experiences that PR targets. ## Template check - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:56:34 +07:00
Author
Owner

@SpicyMarinara commented on GitHub (Aug 16, 2026):

Taking this now as SpicyMarinara. I’ll keep the fix scoped to Conversation/Game engine-state branch copying, add an end-to-end Conversation branch regression, and track the work in a draft PR against staging.

<!-- gh-comment-id:5307343821 --> @SpicyMarinara commented on GitHub (Aug 16, 2026): Taking this now as SpicyMarinara. I’ll keep the fix scoped to Conversation/Game engine-state branch copying, add an end-to-end Conversation branch regression, and track the work in a draft PR against staging.
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#2836
No description provided.