[GH-ISSUE #2323] [Issue]: branch_chat nulls the new branch's gameState on a partial branch, losing bootstrap world-state #1150

Closed
opened 2026-10-21 05:27:58 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @Romuromylus on GitHub (Jun 5, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2323

Originally assigned to: @Xelvanis on GitHub.

Summary

Severity: Medium — Data-loss. branch_chat can null the new branch's gameState when no copied assistant message has a tracker snapshot at its active swipe, dropping the branch's initial/bootstrap world-state. The branch then opens with no visible world-state until a later turn regenerates it.

Expected behavior

Branching should preserve the branch's visible world-state. When no per-message snapshot is copied, it should fall back to the bootstrap tracker snapshot rather than nulling gameState.

Actual behavior

src-tauri/src/commands/storage/chats.rs:1102-1106:

} else if !chat_game_state_is_bootstrap(&new_chat) {
    new_chat =
        state
            .storage
            .patch("chats", &new_chat_id, json!({ "gameState": Value::Null }))?;
}

The if/else-if chain is: (1) visible_tracker_target.is_some() → patch gameState to that snapshot; (2) else if !chat_game_state_is_bootstrap → set gameState = Null (1102-1106); (3) else if copy_bootstrap_tracker_snapshot(...) → patch to bootstrap (1107-1115).

When visible_tracker_target == None (no copied assistant message has an active-swipe snapshot) AND the cloned source gameState is message-bound (so chat_game_state_is_bootstrap returns false), branch (2) fires and nulls gameState — making branch (3) unreachable, so the bootstrap snapshot is never copied. copy_tracker_snapshots_for_message only copies per-message snapshots, never the bootstrap (messageId ""); the bootstrap is copied solely by copy_bootstrap_tracker_snapshot, the shadowed branch. sync_chat_game_state_to_visible_tracker only runs on message/swipe delete (not on branch/open), so it is not self-healed until the next turn.

Steps to reproduce

  1. A tracker/game-mode chat that established initial world-state via the bootstrap snapshot, then progressed several turns (visible gameState bound to a later message).
  2. Branch the chat up-to an early message (e.g. the greeting) that predates any per-message snapshot.
  3. The new branch opens with gameState wiped to null.

Impact area

  • Game mode
  • Roleplay mode
  • Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime

Environment

  • Branch or commit: refactor @ b0e5561d
  • Run mode: Tauri desktop (shared backend; also server mode)
  • OS + version: not relevant (static source audit)
  • Node + pnpm versions: not relevant
  • Rust version, if relevant: not relevant
  • Remote Runtime URL configured? not relevant (applies to both)
  • Provider, model, or integration, if relevant: world-state tracker / game mode

Logs, screenshots, or video

Static source audit; cited to file:line above.

Regression notes

Found via static audit of the refactor branch; not verified against main. The copied per-message snapshots are not lost (only the bootstrap fallback + the convenience gameState field), and the next turn regenerates state, hence medium.

Additional context

Suggested fix: when visible_tracker_target is None but tracker snapshots were copied (or a bootstrap snapshot exists), fall back to the latest copied snapshot or copy_bootstrap_tracker_snapshot before zeroing gameState; only null gameState when no copied/bootstrap snapshot exists at all. Reorder so the bootstrap-copy branch can still run when the cloned gameState is message-bound.

Template check

Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @Romuromylus on GitHub (Jun 5, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2323 Originally assigned to: @Xelvanis on GitHub. ## Summary **Severity: Medium — Data-loss.** `branch_chat` can null the new branch's `gameState` when no copied assistant message has a tracker snapshot at its active swipe, dropping the branch's initial/bootstrap world-state. The branch then opens with no visible world-state until a later turn regenerates it. ## Expected behavior Branching should preserve the branch's visible world-state. When no per-message snapshot is copied, it should fall back to the bootstrap tracker snapshot rather than nulling `gameState`. ## Actual behavior `src-tauri/src/commands/storage/chats.rs:1102-1106`: ```rust } else if !chat_game_state_is_bootstrap(&new_chat) { new_chat = state .storage .patch("chats", &new_chat_id, json!({ "gameState": Value::Null }))?; } ``` The if/else-if chain is: (1) `visible_tracker_target.is_some()` → patch gameState to that snapshot; (2) `else if !chat_game_state_is_bootstrap` → set gameState = Null (1102-1106); (3) `else if copy_bootstrap_tracker_snapshot(...)` → patch to bootstrap (1107-1115). When `visible_tracker_target == None` (no copied assistant message has an active-swipe snapshot) AND the cloned source `gameState` is message-bound (so `chat_game_state_is_bootstrap` returns false), branch (2) fires and nulls gameState — making branch (3) unreachable, so the bootstrap snapshot is never copied. `copy_tracker_snapshots_for_message` only copies per-message snapshots, never the bootstrap (messageId `""`); the bootstrap is copied solely by `copy_bootstrap_tracker_snapshot`, the shadowed branch. `sync_chat_game_state_to_visible_tracker` only runs on message/swipe delete (not on branch/open), so it is not self-healed until the next turn. ## Steps to reproduce 1. A tracker/game-mode chat that established initial world-state via the bootstrap snapshot, then progressed several turns (visible `gameState` bound to a later message). 2. Branch the chat up-to an early message (e.g. the greeting) that predates any per-message snapshot. 3. The new branch opens with `gameState` wiped to null. ## Impact area - [x] Game mode - [x] Roleplay mode - [x] Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime ## Environment - Branch or commit: refactor @ b0e5561d - Run mode: Tauri desktop (shared backend; also server mode) - OS + version: not relevant (static source audit) - Node + pnpm versions: not relevant - Rust version, if relevant: not relevant - Remote Runtime URL configured? not relevant (applies to both) - Provider, model, or integration, if relevant: world-state tracker / game mode ## Logs, screenshots, or video Static source audit; cited to file:line above. ## Regression notes Found via static audit of the refactor branch; not verified against main. The copied per-message snapshots are not lost (only the bootstrap fallback + the convenience `gameState` field), and the next turn regenerates state, hence medium. ## Additional context Suggested fix: when `visible_tracker_target` is None but tracker snapshots were copied (or a bootstrap snapshot exists), fall back to the latest copied snapshot or `copy_bootstrap_tracker_snapshot` before zeroing `gameState`; only null `gameState` when no copied/bootstrap snapshot exists at all. Reorder so the bootstrap-copy branch can still run when the cloned gameState is message-bound. ## Template check Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:27:58 +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#1150
No description provided.