[GH-ISSUE #3385] [Issue]: Branching a roleplay/VN chat clears all tracker state (world + character tracker) — snapshot copy is gated to Game mode only #1835

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

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

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong

When you branch a chat, the world/character tracker state is wiped in the new branch — even though the tracker agents are still on and you're continuing from the same point in the same conversation. You end up having to recreate everything by hand: the world tracker, and especially the character tracker (including the per-character variable fields, which aren't easy to re-add).

The cause: branching copies the tracker snapshots to the new branch only for Game-mode chats. Roleplay and Visual Novel chats use the exact same tracker snapshots, but the copy step skips them, so the branch starts with empty tracker state. This is a bug, not intended behavior — a branch continues the same conversation from the same point, so the tracker state should carry over just like it does in Game mode.

How to reproduce (try it yourself)

  1. In a roleplay (or visual novel) chat with the world tracker and character tracker agents on, play until the trackers hold real state (location/time/weather, present characters, character variables, etc.).
  2. Branch the chat ("fork from here").
  3. Open the new branch and look at the trackers.

You'll see: the tracker panels are empty / reset — all world and character tracker info (including custom character variables) is gone, even though the agents are still enabled and the messages carried over.
Expected: the branch keeps the tracker state up to the branch point, the same way Game-mode branches do.

Where it is

packages/server/src/routes/chats.routes.ts — the branch route copies game-state/tracker snapshots to the new branch only when the source chat is Game mode:

if (sourceToBranchedMessageId.size > 0 && sourceChat.mode === "game") {   // line 3167
  ... copy gameStateSnapshots (date/time/location/weather/presentCharacters/
      playerStats/personaStats/fieldLocks/manualOverrides) ...
}

These gameStateSnapshots are keyed by (chatId, messageId, swipeIndex) and are mode-agnostic — the same snapshots roleplay/VN trackers write and that the generation path reads back as "committed tracker context" (packages/server/src/routes/generate.routes.ts ~2519 getCommittedForMessages, ~3068 injectCommittedTrackerContext). The branch route's own comment calls them "the correct tracker state for that specific message." So the mode === "game" condition is an over-restriction that drops roleplay/VN tracker state. (Messages and their swipes ARE copied for every mode — only the tracker snapshots are gated.)

What's happening

The tracker-snapshot copy on branch was scoped to Game mode, but trackers exist in roleplay and visual-novel modes too (same snapshot table). So a roleplay/VN branch copies the messages but none of the tracker snapshots, and the new branch reads back empty tracker state. The per-character variable fields the reporter mentions are the snapshot's manualOverrides (copied at chats.routes.ts ~3180/3198 inside the same gated block), so they're lost too.

Suggested fix

Copy the gameStateSnapshots on branch regardless of mode — change the guard from sourceChat.mode === "game" to just sourceToBranchedMessageId.size > 0 (the copy is keyed per message and no-ops for a chat that has no snapshots). If desired, keep the turn-game engine-state (gameEngineState, UNO) copy inside a game check, but the tracker snapshots should be copied for roleplay and visual_novel too. This restores the world tracker, character tracker, and the per-character variables (manualOverrides) in the branch.

On the reporter's "did this work before?" — I can't speak to history without git blame, but the current v2.1.1 code definitively gates tracker-snapshot copying to Game mode, so roleplay/VN branches lose tracker state today. It's a bug, not a feature request.


AI-investigated against v2.1.1 (git describe = v2.1.1); the branch mode gate, the snapshot fields, and the roleplay generation read/commit of these snapshots were all read and confirmed. Please verify before fixing.

Originally created by @kolacheee on GitHub (Jul 8, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3385 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** When you branch a chat, the world/character tracker state is wiped in the new branch — even though the tracker agents are still on and you're continuing from the same point in the same conversation. You end up having to recreate everything by hand: the world tracker, and especially the character tracker (including the per-character variable fields, which aren't easy to re-add). The cause: branching copies the tracker snapshots to the new branch **only for Game-mode chats**. Roleplay and Visual Novel chats use the exact same tracker snapshots, but the copy step skips them, so the branch starts with empty tracker state. This is a bug, not intended behavior — a branch continues the same conversation from the same point, so the tracker state should carry over just like it does in Game mode. **How to reproduce (try it yourself)** 1. In a **roleplay** (or visual novel) chat with the world tracker and character tracker agents on, play until the trackers hold real state (location/time/weather, present characters, character variables, etc.). 2. Branch the chat ("fork from here"). 3. Open the new branch and look at the trackers. **You'll see:** the tracker panels are empty / reset — all world and character tracker info (including custom character variables) is gone, even though the agents are still enabled and the messages carried over. **Expected:** the branch keeps the tracker state up to the branch point, the same way Game-mode branches do. **Where it is** `packages/server/src/routes/chats.routes.ts` — the branch route copies game-state/tracker snapshots to the new branch only when the source chat is Game mode: ``` if (sourceToBranchedMessageId.size > 0 && sourceChat.mode === "game") { // line 3167 ... copy gameStateSnapshots (date/time/location/weather/presentCharacters/ playerStats/personaStats/fieldLocks/manualOverrides) ... } ``` These `gameStateSnapshots` are keyed by `(chatId, messageId, swipeIndex)` and are mode-agnostic — the same snapshots roleplay/VN trackers write and that the generation path reads back as "committed tracker context" (`packages/server/src/routes/generate.routes.ts` ~2519 `getCommittedForMessages`, ~3068 `injectCommittedTrackerContext`). The branch route's own comment calls them "the correct tracker state for that specific message." So the `mode === "game"` condition is an over-restriction that drops roleplay/VN tracker state. (Messages and their swipes ARE copied for every mode — only the tracker snapshots are gated.) **What's happening** The tracker-snapshot copy on branch was scoped to Game mode, but trackers exist in roleplay and visual-novel modes too (same snapshot table). So a roleplay/VN branch copies the messages but none of the tracker snapshots, and the new branch reads back empty tracker state. The per-character variable fields the reporter mentions are the snapshot's `manualOverrides` (copied at `chats.routes.ts` ~3180/3198 inside the same gated block), so they're lost too. **Suggested fix** Copy the `gameStateSnapshots` on branch regardless of mode — change the guard from `sourceChat.mode === "game"` to just `sourceToBranchedMessageId.size > 0` (the copy is keyed per message and no-ops for a chat that has no snapshots). If desired, keep the turn-game engine-state (`gameEngineState`, UNO) copy inside a game check, but the tracker snapshots should be copied for roleplay and visual_novel too. This restores the world tracker, character tracker, and the per-character variables (`manualOverrides`) in the branch. *On the reporter's "did this work before?" — I can't speak to history without git blame, but the current v2.1.1 code definitively gates tracker-snapshot copying to Game mode, so roleplay/VN branches lose tracker state today. It's a bug, not a feature request.* --- *AI-investigated against v2.1.1 (`git describe` = v2.1.1); the branch mode gate, the snapshot fields, and the roleplay generation read/commit of these snapshots were all read and confirmed. Please verify before fixing.*
bsakaguchi 2026-10-21 05:43:07 +07:00
Author
Owner

@SpicyMarinara commented on GitHub (Jul 8, 2026):

Addressed in #3388 and merged to staging.

<!-- gh-comment-id:4918159205 --> @SpicyMarinara commented on GitHub (Jul 8, 2026): Addressed in #3388 and merged to 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#1835
No description provided.