[PR #8565] [MERGED] fix(chats): keep branches under a deleted middle branch in the list #8676

Closed
opened 2026-11-07 17:38:51 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/8565
Author: @ylli-selmani
Created: 10/30/2026
Status: ✅ Merged
Merged: 10/30/2026
Merged by: @ylli-selmani

Base: staging ← Head: fix/branch-orphan-lineage


📝 Commits (5)

  • 607744d fix(chats): keep branches under a deleted middle branch in the list
  • e13d179 docs(chats): a deleted source branch still shows under the chat
  • 2be96db docs(chats): split the branch-list sentence and name the deleted-source case
  • c91fe8c docs(chats): say the unknown-source rule applies inside the tree
  • 42975bf test(chats): pin the all-orphan group and align the ordering comment

📊 Changes

3 files changed (+43 additions, -13 deletions)

View changed files

📝 docs/chats/branches.md (+1 -1)
📝 packages/client/src/lib/chat-branch-tree.ts (+15 -8)
📝 scripts/regressions/chat-branch-tree.regression.ts (+27 -4)

📄 Description

Linked issue

Closes #8488

Why this change

Deleting a branch that another branch hangs from takes the whole branch tree out of the chat list. The descendant chat is still there — Chat Branches lists it and the branch graph draws it — but the group's ⑂ N badge stops being a toggle: no chevron, no expand, and no way to reach the descendant from the list.

Reported on Discord and filed by @SpicyMarinara: "delete middle branch and the branch not viewable as branch." In the screenshot the badge is present but inert.

The cause is one predicate disagreeing with the data. Deleting a chat deliberately leaves its children's metadata.branchParentChatId pointing at the removed chat — lineage is history, not a foreign key. But hasChatBranchLineage only counted a parent still inside the group, so a group whose middle branch was deleted read as "no lineage at all" and fell back to the single-row list. That fallback exists for legacy branch sets and Game sessions, which record no parent at all. Importing, copying and restoring a chat all strip branchParentChatId, so a pointer with no chat behind it can only mean the source was deleted — a different thing from "lineage unknown".

What changed

  • chat-branch-tree.ts — hasChatBranchLineage counts a recorded parent pointer even when the parent chat is gone, so a group keeps its tree after a middle branch is deleted. The orphan hangs directly under the surviving top chat (the builder's existing fallback for a deleted parent), and branches below it keep their own depth.
  • chat-branch-tree.regression.ts — the old expectation ([a, b] with a deleted parent ⇒ no lineage) was this bug written down as a test, so it now asserts the opposite. Adds the issue's 3-chats-minus-the-middle repro (root:0, b1-1:1, b1-1-1:2, b2:1) and keeps the legacy-set / lone-chat / self-reference negatives.
  • docs/chats/branches.md — the branch count now opens the tree "once at least one branch in the group records which chat it was made from". Inside that tree, an unknown or deleted source sits directly under the chat.

No server change, no schema change, no migration, no new UI copy. Groups that record no lineage at all keep their single row.

Validation

Local runs on this branch, cut from origin/staging aac35cba8:

node scripts/run-regressions.mjs --filter chat-branch-tree   1/1 passed
pnpm check                                                   green (exit 0)

The regression fails on the old predicate: the deleted-source case was asserted false, and the 3→2 repro produced no tree.

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

Worktree stack on port 6980 with a seeded group: root chat → a branch of it → a branch of that branch, then the middle branch deleted with DELETE /chats/:id?force=true. The chat list then shows the root row with a clickable ⑂ 2 badge (chevron) that expands to the descendant indented under it with its guide line; collapsing hides it and expanding brings it back, with aria-expanded following. Before the fix the same data rendered the badge as a static pill with no tree.

Screenshots are kept locally in the private .tmp repo, not committed here:
.tmp/branches/branch-orphan-lineage/screenshots/2026-10-30-orphan-tree-expanded.png.

Local review (CodeRabbit, two runs)

  • Round 1 (--committed --base origin/staging): 1 minor — the branch-list paragraph was a run-on; split into short sentences, with the deleted-source case stated separately. Fixed in 2be96dbb0.
  • Round 2 (--committed --base e13d1798d): 2 minor. One asked the unknown-source rule and the "group with no known lineage" sentence to state the same rule — fixed in c91fe8c97 by scoping the first to "Inside that tree", which is the actual behavior. The other asked to rewrite the paragraph for newcomers without internal terminology; declined — that sentence is the precise rule for when the branch count becomes a button, and round 1 already reduced it to three short sentences. Rewriting it further would either drop the condition or misstate when the count is clickable.

Docs and release impact

docs/chats/branches.md changed by one sentence; the [docs-i18n] docs/chats/branches.md follow-up is #8568. No version-bearing files touched, no CHANGELOG.md entry.

UI evidence (if applicable)

The reported screenshot is the before: the ⑂ 2 pill with no chevron. After the fix the same group renders ⑂ 2 ⌃ and expands to the surviving descendant under the root.


🔄 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/8565 **Author:** [@ylli-selmani](https://github.com/ylli-selmani) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/30/2026 **Merged by:** [@ylli-selmani](https://github.com/ylli-selmani) **Base:** `staging` ← **Head:** `fix/branch-orphan-lineage` --- ### 📝 Commits (5) - [`607744d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/607744dde4683840f7f713b2edde6993f1514330) fix(chats): keep branches under a deleted middle branch in the list - [`e13d179`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e13d1798d703a6e94e50ce7f23f86d212dfd6b7f) docs(chats): a deleted source branch still shows under the chat - [`2be96db`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2be96dbb075e6a66cf132ddbbc24f99767ffc7c0) docs(chats): split the branch-list sentence and name the deleted-source case - [`c91fe8c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c91fe8c97ab5f5e9c86f5cab67ba72a863871a8b) docs(chats): say the unknown-source rule applies inside the tree - [`42975bf`](https://github.com/Pasta-Devs/Marinara-Engine/commit/42975bf87e7e48e6a86539c42434cded1d619703) test(chats): pin the all-orphan group and align the ordering comment ### 📊 Changes **3 files changed** (+43 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `docs/chats/branches.md` (+1 -1) 📝 `packages/client/src/lib/chat-branch-tree.ts` (+15 -8) 📝 `scripts/regressions/chat-branch-tree.regression.ts` (+27 -4) </details> ### 📄 Description ## Linked issue Closes #8488 ## Why this change Deleting a branch that another branch hangs from takes the whole branch tree out of the chat list. The descendant chat is still there — **Chat Branches** lists it and the branch graph draws it — but the group's `⑂ N` badge stops being a toggle: no chevron, no expand, and no way to reach the descendant from the list. Reported on Discord and filed by @SpicyMarinara: *"delete middle branch and the branch not viewable as branch."* In the screenshot the badge is present but inert. The cause is one predicate disagreeing with the data. Deleting a chat deliberately leaves its children's `metadata.branchParentChatId` pointing at the removed chat — lineage is history, not a foreign key. But `hasChatBranchLineage` only counted a parent still inside the group, so a group whose middle branch was deleted read as "no lineage at all" and fell back to the single-row list. That fallback exists for legacy branch sets and Game sessions, which record no parent at all. Importing, copying and restoring a chat all strip `branchParentChatId`, so a pointer with no chat behind it can only mean the source was deleted — a different thing from "lineage unknown". ## What changed - `chat-branch-tree.ts` — `hasChatBranchLineage` counts a recorded parent pointer even when the parent chat is gone, so a group keeps its tree after a middle branch is deleted. The orphan hangs directly under the surviving top chat (the builder's existing fallback for a deleted parent), and branches below it keep their own depth. - `chat-branch-tree.regression.ts` — the old expectation (`[a, b]` with a deleted parent ⇒ no lineage) was this bug written down as a test, so it now asserts the opposite. Adds the issue's 3-chats-minus-the-middle repro (`root:0, b1-1:1, b1-1-1:2, b2:1`) and keeps the legacy-set / lone-chat / self-reference negatives. - `docs/chats/branches.md` — the branch count now opens the tree "once at least one branch in the group records which chat it was made from". Inside that tree, an unknown **or deleted** source sits directly under the chat. No server change, no schema change, no migration, no new UI copy. Groups that record no lineage at all keep their single row. ## Validation Local runs on this branch, cut from `origin/staging` `aac35cba8`: ``` node scripts/run-regressions.mjs --filter chat-branch-tree 1/1 passed pnpm check green (exit 0) ``` The regression fails on the old predicate: the deleted-source case was asserted `false`, and the 3→2 repro produced no tree. - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes Worktree stack on port 6980 with a seeded group: root chat → a branch of it → a branch of that branch, then the middle branch deleted with `DELETE /chats/:id?force=true`. The chat list then shows the root row with a clickable `⑂ 2` badge (chevron) that expands to the descendant indented under it with its guide line; collapsing hides it and expanding brings it back, with `aria-expanded` following. Before the fix the same data rendered the badge as a static pill with no tree. Screenshots are kept locally in the private `.tmp` repo, not committed here: `.tmp/branches/branch-orphan-lineage/screenshots/2026-10-30-orphan-tree-expanded.png`. ### Local review (CodeRabbit, two runs) - Round 1 (`--committed --base origin/staging`): 1 minor — the branch-list paragraph was a run-on; split into short sentences, with the deleted-source case stated separately. Fixed in `2be96dbb0`. - Round 2 (`--committed --base e13d1798d`): 2 minor. One asked the unknown-source rule and the "group with no known lineage" sentence to state the same rule — fixed in `c91fe8c97` by scoping the first to "Inside that tree", which is the actual behavior. The other asked to rewrite the paragraph for newcomers without internal terminology; declined — that sentence is the precise rule for when the branch count becomes a button, and round 1 already reduced it to three short sentences. Rewriting it further would either drop the condition or misstate when the count is clickable. ## Docs and release impact `docs/chats/branches.md` changed by one sentence; the `[docs-i18n] docs/chats/branches.md` follow-up is **#8568**. No version-bearing files touched, no `CHANGELOG.md` entry. ## UI evidence (if applicable) The reported screenshot is the before: the `⑂ 2` pill with no chevron. After the fix the same group renders `⑂ 2 ⌃` and expands to the surviving descendant under the root. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 17:38:51 +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#8676
No description provided.