[GH-ISSUE #2956] [Issue]: Branching a chat throws away every alternate swipe — only the one you're viewing survives #1530

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

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

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong

When you branch a chat ("fork from here"), each copied message keeps only its currently-active swipe. Every alternate generation (the other swipes you generated) is silently dropped and is gone for good in the new branch. So branching — which users expect to be a faithful copy — quietly loses data.

How to reproduce (try it yourself)

  1. Open a roleplay or conversation chat.
  2. On an assistant message, regenerate a couple of times so it has 2–3 swipes (the counter shows e.g. 1/3); optionally swipe to swipe 2 so it's the active one.
  3. Use the branch / "fork from here" action on that chat.
  4. Open the new branch and look at that message's swipe control.

You'll see: the counter shows 1/1 — only the swipe that was active at branch time exists; the other alternates are gone.
Expected: the branched message keeps all 3 swipes (with the same one active), so you can still swipe between the alternates.

(The active swipe's text is copied correctly — it's only the alternates that are lost. Note the JSONL export path already emits all swipes, so the branch path is the inconsistent one.)

Where it is

packages/server/src/routes/chats.routes.ts — the branch copy loop at lines 3024-3064 resolves only the active swipe's content (3027-3032) and calls storage.createMessage with a single content (3034). storage.createMessage (packages/server/src/services/storage/chats.storage.ts:710-740) is a single-swipe constructor: it always inserts the message with activeSwipeIndex: 0 and exactly one messageSwipes row. The loop never calls storage.getSwipes(msg.id). (Relatedly, the game-state snapshot copy at ~3120-3122 hardcodes the target swipeIndex to 0.)

What's happening

Because the branch loop only ever passes the single active-swipe content into the single-swipe createMessage, the new message is born with one swipe. The storage layer already has a multi-swipe path (createMessagesBatch accepts a swipes array, used elsewhere for full-swipe cloning) — the branch path just doesn't use it.

Suggested fix

In the branch loop, fetch const swipes = await storage.getSwipes(msg.id) and recreate all of them, preserving each swipe's content, sanitized extra, createdAt, and the original msg.activeSwipeIndex — easiest via storage.createMessagesBatch with a per-message { activeSwipeIndex, swipes } payload (or createMessage then addSwipe the rest in index order, then setActiveSwipe). Also re-key the game-state snapshot copy to each swipe's real index instead of hardcoding 0.


AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.

Originally created by @kolacheee on GitHub (Jun 28, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2956 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** When you branch a chat ("fork from here"), each copied message keeps only its **currently-active** swipe. Every alternate generation (the other swipes you generated) is silently dropped and is gone for good in the new branch. So branching — which users expect to be a faithful copy — quietly loses data. **How to reproduce (try it yourself)** 1. Open a roleplay or conversation chat. 2. On an assistant message, regenerate a couple of times so it has 2–3 swipes (the counter shows e.g. `1/3`); optionally swipe to swipe 2 so it's the active one. 3. Use the branch / "fork from here" action on that chat. 4. Open the new branch and look at that message's swipe control. **You'll see:** the counter shows `1/1` — only the swipe that was active at branch time exists; the other alternates are gone. **Expected:** the branched message keeps all 3 swipes (with the same one active), so you can still swipe between the alternates. (The active swipe's text *is* copied correctly — it's only the alternates that are lost. Note the JSONL **export** path already emits all swipes, so the branch path is the inconsistent one.) **Where it is** `packages/server/src/routes/chats.routes.ts` — the branch copy loop at lines 3024-3064 resolves only the active swipe's content (3027-3032) and calls `storage.createMessage` with a single `content` (3034). `storage.createMessage` (`packages/server/src/services/storage/chats.storage.ts:710-740`) is a single-swipe constructor: it always inserts the message with `activeSwipeIndex: 0` and exactly one `messageSwipes` row. The loop never calls `storage.getSwipes(msg.id)`. (Relatedly, the game-state snapshot copy at ~3120-3122 hardcodes the target `swipeIndex` to 0.) **What's happening** Because the branch loop only ever passes the single active-swipe content into the single-swipe `createMessage`, the new message is born with one swipe. The storage layer already has a multi-swipe path (`createMessagesBatch` accepts a `swipes` array, used elsewhere for full-swipe cloning) — the branch path just doesn't use it. **Suggested fix** In the branch loop, fetch `const swipes = await storage.getSwipes(msg.id)` and recreate all of them, preserving each swipe's content, sanitized `extra`, `createdAt`, and the original `msg.activeSwipeIndex` — easiest via `storage.createMessagesBatch` with a per-message `{ activeSwipeIndex, swipes }` payload (or `createMessage` then `addSwipe` the rest in index order, then `setActiveSwipe`). Also re-key the game-state snapshot copy to each swipe's real index instead of hardcoding 0. --- *AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.*
Author
Owner

@SpicyMarinara commented on GitHub (Jun 29, 2026):

Fixed in staging: branching now copies every swipe, preserves the active swipe index, and rekeys Game/turn-game snapshots to matching branched swipe indexes. Validated with pnpm check and pnpm regression:prompt.

<!-- gh-comment-id:4830955072 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Fixed in staging: branching now copies every swipe, preserves the active swipe index, and rekeys Game/turn-game snapshots to matching branched swipe indexes. Validated with pnpm check and pnpm regression:prompt.
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#1530
No description provided.