[PR #1519] [MERGED] Enroll source chat into its group when creating the first branch #5116

Closed
opened 2026-10-22 04:13:28 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/1519
Author: @Romuromylus
Created: 5/29/2026
Status: ✅ Merged
Merged: 5/29/2026
Merged by: @Romuromylus

Base: refactor ← Head: fix/branch-root-chat-group


📝 Commits (2)

  • bf14ac0 Enroll source chat into its group when creating the first branch
  • e850c0b Clarify branch enroll ordering and import-path parity in comment

📊 Changes

1 file changed (+93 additions, -4 deletions)

View changed files

📝 src-tauri/src/commands/storage/chats.rs (+93 -4)

📄 Description

Why this change

After creating Roleplay branches, Manage Chat Files worked from a branch chat but the original/root chat still reported it was not part of a group and had no branches. branch_chat set the new branch's groupId to the source chat id, but left the source/root chat at groupId: null. The drawer and branch selector only fetch a group when the active chat has a groupId, so opening either from the original chat showed the no-group empty state even though branch records already pointed at that chat id.

What changed

  • src-tauri/src/commands/storage/chats.rs: when the source chat has no group, enroll it into the new group (keyed on its own id) alongside the branch, mirroring the intent of the ST-chat-into-group import path that already promotes the target chat to a group root. An empty-string groupId is now treated as ungrouped too. The branch is created first and the source enrolled after, on purpose: a failed enroll patch degrades to the pre-fix state rather than leaving a root in a branchless group.

Verification

  • pnpm check passes locally; cargo test --lib 176 passed / 0 failed, including two new regression tests: an ungrouped source chat gets enrolled and the group lists both chats, and an already-grouped source is not re-patched.
  • cargo clippy --workspace --all-targets -- -D warnings clean.
  • Verified on the real Tauri desktop shell (Playwright over WebView2 CDP, real chat_branch invoke through the real Rust runtime and real storage): branching an ungrouped roleplay chat enrolls the root, the branch joins the group, and storage_list filtered by groupId returns both the root and the branch. Seeded chats cleaned up afterward.

Known caveat

This fixes branch discovery for chats branched after the change. Chats that were already branched while the root stayed ungrouped (the existing broken state in the report) are not retroactively patched; that migration is tracked in #1522.

Follow-ups (deferred, not blocking)

  • #1522: the Manage Chat / delete dialog counts the root as a branch (pre-existing, also affected ST-imported groups), and a one-time migration to repair already-branched chats whose root stayed ungrouped.

Linked issue

Closes #1509

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Improved chat organization when branching conversations: branches now properly maintain group associations with their source chat, and ungrouped source chats are automatically enrolled in a new group with their branches.
  • Tests

    • Added comprehensive test coverage for chat branching behavior with grouped and ungrouped source chats.

Review Change Stack


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/1519 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 5/29/2026 **Status:** ✅ Merged **Merged:** 5/29/2026 **Merged by:** [@Romuromylus](https://github.com/Romuromylus) **Base:** `refactor` ← **Head:** `fix/branch-root-chat-group` --- ### 📝 Commits (2) - [`bf14ac0`](https://github.com/Pasta-Devs/Marinara-Engine/commit/bf14ac0f58b82d95f985c3803e4f70a6c1e056a1) Enroll source chat into its group when creating the first branch - [`e850c0b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e850c0b9c9ed5adf921d2880ef42fe1961af49f5) Clarify branch enroll ordering and import-path parity in comment ### 📊 Changes **1 file changed** (+93 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `src-tauri/src/commands/storage/chats.rs` (+93 -4) </details> ### 📄 Description ## Why this change After creating Roleplay branches, Manage Chat Files worked from a branch chat but the original/root chat still reported it was not part of a group and had no branches. `branch_chat` set the new branch's `groupId` to the source chat id, but left the source/root chat at `groupId: null`. The drawer and branch selector only fetch a group when the active chat has a `groupId`, so opening either from the original chat showed the no-group empty state even though branch records already pointed at that chat id. ## What changed - `src-tauri/src/commands/storage/chats.rs`: when the source chat has no group, enroll it into the new group (keyed on its own id) alongside the branch, mirroring the intent of the ST-chat-into-group import path that already promotes the target chat to a group root. An empty-string `groupId` is now treated as ungrouped too. The branch is created first and the source enrolled after, on purpose: a failed enroll patch degrades to the pre-fix state rather than leaving a root in a branchless group. ## Verification - `pnpm check` passes locally; `cargo test --lib` 176 passed / 0 failed, including two new regression tests: an ungrouped source chat gets enrolled and the group lists both chats, and an already-grouped source is not re-patched. - `cargo clippy --workspace --all-targets -- -D warnings` clean. - Verified on the real Tauri desktop shell (Playwright over WebView2 CDP, real `chat_branch` invoke through the real Rust runtime and real storage): branching an ungrouped roleplay chat enrolls the root, the branch joins the group, and `storage_list` filtered by `groupId` returns both the root and the branch. Seeded chats cleaned up afterward. ## Known caveat This fixes branch discovery for chats branched after the change. Chats that were already branched while the root stayed ungrouped (the existing broken state in the report) are not retroactively patched; that migration is tracked in #1522. ## Follow-ups (deferred, not blocking) - #1522: the Manage Chat / delete dialog counts the root as a branch (pre-existing, also affected ST-imported groups), and a one-time migration to repair already-branched chats whose root stayed ungrouped. ## Linked issue Closes #1509 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Bug Fixes** * Improved chat organization when branching conversations: branches now properly maintain group associations with their source chat, and ungrouped source chats are automatically enrolled in a new group with their branches. * **Tests** * Added comprehensive test coverage for chat branching behavior with grouped and ungrouped source chats. <!-- review_stack_entry_start --> [![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/Pasta-Devs/Marinara-Engine/pull/1519?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack) <!-- review_stack_entry_end --> <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:13:28 +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#5116
No description provided.