[GH-ISSUE #2465] [Issue]: branch_chat inherits connectedChatId from the source chat, linking the branch to the partner chat #1208

Closed
opened 2026-10-21 05:29:03 +07:00 by bsakaguchi · 2 comments
Owner

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

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Severity: Medium — correctness regression. branch_chat clones the entire source chat object, so a branch created from a connected chat silently inherits the source's connectedChatId, leaking the partner chat's content into the branch's prompts and creating a one-way/phantom link.

Expected behavior

Branching should build the new chat from an explicit field allowlist (like main's /:id/branch route) and must not carry connectedChatId into the branch. A fresh branch is not linked to anything until the user links it.

Actual behavior

branch_chat loads the full source chat via get_required, mutates only id/name/groupId, scrubs summary metadata, and creates the new chat — connectedChatId is never nulled:

// src-tauri/src/commands/storage/chats.rs:2053 (fn branch_chat)
let mut chat = get_required(state, "chats", chat_id)?;   // 2054 — full source object
// ...only id/name/groupId mutated (2073-2075)
prune_branch_summary_metadata(&mut chat);   // drops summary* only (502-509)
initialize_branch_display_name(&mut chat);  // sets branchName only
let mut new_chat = state.storage.create("chats", chat)?;  // 2080 — connectedChatId carried verbatim

connectedChatId is a live, consumed field: prompt-assembly.ts loads the connected chat's last messages and injects a "linked chat" block, and connected-commands.ts redirects message routing on it. The link is also phantom/one-way — the partner chat's connectedChatId still points at the source, never the branch, so disconnect_connected_chat (which discovers partners by scanning for connectedChatId == self) can never clean the branch.

Steps to reproduce

  1. Link two chats (open the conversation↔roleplay connect flow so chat A has connectedChatId = B).
  2. Branch chat A from any message.
  3. Open the new branch and generate — chat B's content is injected into the branch's prompt, and B has no link back to the branch.

Impact area

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

Environment

  • Branch or commit: refactor @ 1fae2c42
  • Run mode: Tauri desktop
  • OS + version: found via static source audit (not runtime-reproduced)
  • Node + pnpm versions: n/a (static audit)
  • Rust version, if relevant: n/a (static audit)
  • Remote Runtime URL configured? not relevant
  • Provider, model, or integration, if relevant: n/a

Logs, screenshots, or video

Static source trace, cited to src-tauri/src/commands/storage/chats.rs:2053-2080, prune_branch_summary_metadata at :502-509, partner-discovery at disconnect_connected_chat (:1697).

Regression notes

Regression vs main — main does this correctly. packages/server/src/routes/chats.routes.ts /:id/branch builds the new chat from an explicit allowlist (name, mode, characterIds, groupId, personaId, promptPresetId, connectionId) and never copies connectedChatId. The refactor's whole-object clone reintroduced the leak.

Additional context

Fix: after cloning (or inside prune_branch_summary_metadata), object.insert("connectedChatId", Value::Null) — or rebuild the branch from an allowlist matching main. While here, consider also rejecting scene chats from branch_chat (main guards that too).

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 6, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2465 Originally assigned to: @SpicyMarinara on GitHub. ## Summary **Severity: Medium — correctness regression.** `branch_chat` clones the entire source chat object, so a branch created from a *connected* chat silently inherits the source's `connectedChatId`, leaking the partner chat's content into the branch's prompts and creating a one-way/phantom link. ## Expected behavior Branching should build the new chat from an explicit field allowlist (like main's `/:id/branch` route) and must not carry `connectedChatId` into the branch. A fresh branch is not linked to anything until the user links it. ## Actual behavior `branch_chat` loads the full source chat via `get_required`, mutates only `id`/`name`/`groupId`, scrubs summary metadata, and creates the new chat — `connectedChatId` is never nulled: ```rust // src-tauri/src/commands/storage/chats.rs:2053 (fn branch_chat) let mut chat = get_required(state, "chats", chat_id)?; // 2054 — full source object // ...only id/name/groupId mutated (2073-2075) prune_branch_summary_metadata(&mut chat); // drops summary* only (502-509) initialize_branch_display_name(&mut chat); // sets branchName only let mut new_chat = state.storage.create("chats", chat)?; // 2080 — connectedChatId carried verbatim ``` `connectedChatId` is a live, consumed field: `prompt-assembly.ts` loads the connected chat's last messages and injects a "linked chat" block, and `connected-commands.ts` redirects message routing on it. The link is also phantom/one-way — the partner chat's `connectedChatId` still points at the *source*, never the branch, so `disconnect_connected_chat` (which discovers partners by scanning for `connectedChatId == self`) can never clean the branch. ## Steps to reproduce 1. Link two chats (open the conversation↔roleplay connect flow so chat A has `connectedChatId = B`). 2. Branch chat A from any message. 3. Open the new branch and generate — chat B's content is injected into the branch's prompt, and B has no link back to the branch. ## Impact area - [x] Chat mode - [x] Roleplay mode - [x] Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime ## Environment - Branch or commit: refactor @ 1fae2c42 - Run mode: Tauri desktop - OS + version: found via static source audit (not runtime-reproduced) - Node + pnpm versions: n/a (static audit) - Rust version, if relevant: n/a (static audit) - Remote Runtime URL configured? not relevant - Provider, model, or integration, if relevant: n/a ## Logs, screenshots, or video Static source trace, cited to `src-tauri/src/commands/storage/chats.rs:2053-2080`, `prune_branch_summary_metadata` at `:502-509`, partner-discovery at `disconnect_connected_chat` (`:1697`). ## Regression notes Regression vs main — main does this correctly. `packages/server/src/routes/chats.routes.ts` `/:id/branch` builds the new chat from an explicit allowlist (name, mode, characterIds, groupId, personaId, promptPresetId, connectionId) and never copies `connectedChatId`. The refactor's whole-object clone reintroduced the leak. ## Additional context Fix: after cloning (or inside `prune_branch_summary_metadata`), `object.insert("connectedChatId", Value::Null)` — or rebuild the branch from an allowlist matching main. While here, consider also rejecting scene chats from `branch_chat` (main guards that too). ## 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:29:03 +07:00
Author
Owner

@Romuromylus commented on GitHub (Jun 6, 2026):

Sibling chat-copy guard gap: #2468 (forkRoleplayScene drops three guards main enforces). Both are chat/scene copy paths that the refactor rebuilt without main's field allowlist / validation, so they're good candidates to fix in one pass.

<!-- gh-comment-id:4638559817 --> @Romuromylus commented on GitHub (Jun 6, 2026): Sibling chat-copy guard gap: #2468 (`forkRoleplayScene` drops three guards main enforces). Both are chat/scene copy paths that the refactor rebuilt without main's field allowlist / validation, so they're good candidates to fix in one pass.
Author
Owner

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

Fixed on refactor in 038b7220.

branch_chat now clears connectedChatId on the cloned chat so branches do not inherit partner-chat links.

Verification: pnpm typecheck; pnpm build; pnpm check:architecture; cargo check --manifest-path src-tauri/Cargo.toml --workspace; focused Rust backup/profile tests; git diff --check; no .test.ts/.test.tsx files present.

<!-- gh-comment-id:4638721658 --> @SpicyMarinara commented on GitHub (Jun 6, 2026): Fixed on refactor in 038b7220. branch_chat now clears connectedChatId on the cloned chat so branches do not inherit partner-chat links. Verification: pnpm typecheck; pnpm build; pnpm check:architecture; cargo check --manifest-path src-tauri/Cargo.toml --workspace; focused Rust backup/profile tests; git diff --check; no .test.ts/.test.tsx files present.
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#1208
No description provided.