[GH-ISSUE #1759] [Feature]: Long-Term Memory: branch dropdown for the Chat Messages source #1739

Closed
opened 2026-11-07 16:36:21 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @Promansis on GitHub (Oct 27, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1759

Originally assigned to: @Promansis on GitHub.

What problem does this solve?

The Long-Term Memory "Chat Messages" source (1.5.0, #1744) lists every piece of a chat's history for import. Marinara branches are separate chats in the same group, with the same messages copied under new ids. The list covers the whole group, so with several branches the user sees pieces from all of them mixed together and cannot tell which branch a piece belongs to. Identical pieces are already merged into one row, but a piece that exists in only one branch sits beside pieces from other branches with nothing to separate them.

Example: a chat has the branches "New Branch" and "Rewrite". Both share the first 40 messages, then diverge. The list shows the shared pieces once, then the pieces from both endings interleaved. A user who only wants the "Rewrite" ending has to guess which pieces those are, and may import the abandoned ending by mistake.

Proposed package or change

Package: long-term-memory. Server preview filter and Sources screen change, no Engine change.

When the selected chat's group has more than one chat, the Chat Messages tab shows a Branch dropdown next to the Mode dropdown:

  • This branch (default): the current chat's history, which is the shared history plus its own pieces.
  • One entry per other branch in the group, labelled with the chat's display name (duplicates numbered, such as "New Branch (2)").
  • All branches: today's behaviour.

The dropdown only filters the list. Import still goes to the whole chat's memory, so a piece imported from any branch keeps counting as imported everywhere it is shared.

Version: ships as 1.5.1 (patch). Not a minor: no new setting, no stored data change.

Minimal fix

Server, packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/sources/interop.ts:

  • Add optional branchChatIds?: string[] to Candidate.
  • resolvePreviewCandidates: when it merges identical chat_transcript rows, accumulate the producing chat ids (row.provenance.sourceId) on the kept row.
  • previewPackageInterop: after resolvePreviewCandidates and before previewPage and the totals, filter rows by request.branchChatId when set and source === "messages".
  • previewPage: include branchChatId in the cursor binding hash, so a cursor from one filter is rejected under another.

Shared, packages/long-term-memory/src/engine/packages/shared/src/features/agents/long-term-memory/schema/sources.ts:

  • ltmInteropPreviewRequestSchema: add branchChatId: z.string().min(1).max(200).optional().

Client, packages/long-term-memory/src/engine/packages/client/src/features/long-term-memory/sources/SourcesWorkspace.tsx and locales/en.json:

  • branchChatId state, default the current chat, reset when the chat or source target changes.
  • Branch options from scopeTargets.data.groups / chats, shown only for source === "messages" and a group with more than one chat.
  • Add branchChatId to the preview request body and to previewQueryKey.
  • A native <select> like the Mode select (data-ltm-source-branch, aria-label), using confirmSelectionChange() and clearImportResult() on change.
  • New locale keys under ui.longTermMemory.sourcesworkspace (the existing allBranches key is reused for "All branches").

packages/long-term-memory/CHANGELOG.md: one user-facing line under ## Unreleased.

Regression: extend tests/long-term-memory-chat-transcript-import.regression.ts. Add a sibling branch whose messages diverge from branchChat, preview with branchChatId set to each branch, and expect the shared piece under both, each branch-only piece under only its own, totals consistent with the rows, and a cursor from one filter rejected under another. A branchChatId outside the group yields no rows.

Why should this be optional?

It lives in the Long-Term Memory package, which is already optional. Within the package it adds no setting: a chat without branches sees no dropdown, and "All branches" keeps today's list.

Alternatives considered

  • Detect the fork point from branch metadata (branchParentMessageId): rejected for now. Branches of branches and edited copies make it unreliable; piece text equality already drives the existing de-duplication.
  • Import into a per-branch destination: rejected. Memory belongs to the chat as a whole, and the user asked for the import to stay whole-chat.
  • Label pieces with their branch instead of filtering: more noise in a list that is already long.

Known limit: shared history is recognised by identical piece text, so a piece that spans the fork point (shared plus branch-only messages) differs per branch and shows under its own branch only.

Additional context

Follow-up to #1747 (LTM 1.5.0). Requested by the maintainer after trying the Chat Messages tab on a chat with several drafts.

Template check

Please uncheck (untick) 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 @Promansis on GitHub (Oct 27, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1759 Originally assigned to: @Promansis on GitHub. ## What problem does this solve? The Long-Term Memory "Chat Messages" source (1.5.0, #1744) lists every piece of a chat's history for import. Marinara branches are separate chats in the same group, with the same messages copied under new ids. The list covers the whole group, so with several branches the user sees pieces from all of them mixed together and cannot tell which branch a piece belongs to. Identical pieces are already merged into one row, but a piece that exists in only one branch sits beside pieces from other branches with nothing to separate them. Example: a chat has the branches "New Branch" and "Rewrite". Both share the first 40 messages, then diverge. The list shows the shared pieces once, then the pieces from both endings interleaved. A user who only wants the "Rewrite" ending has to guess which pieces those are, and may import the abandoned ending by mistake. ## Proposed package or change Package: `long-term-memory`. Server preview filter and Sources screen change, no Engine change. When the selected chat's group has more than one chat, the Chat Messages tab shows a **Branch** dropdown next to the Mode dropdown: - **This branch** (default): the current chat's history, which is the shared history plus its own pieces. - One entry per other branch in the group, labelled with the chat's display name (duplicates numbered, such as "New Branch (2)"). - **All branches**: today's behaviour. The dropdown only filters the list. Import still goes to the whole chat's memory, so a piece imported from any branch keeps counting as imported everywhere it is shared. Version: ships as 1.5.1 (patch). Not a minor: no new setting, no stored data change. ## Minimal fix Server, `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/sources/interop.ts`: - Add optional `branchChatIds?: string[]` to `Candidate`. - `resolvePreviewCandidates`: when it merges identical `chat_transcript` rows, accumulate the producing chat ids (`row.provenance.sourceId`) on the kept row. - `previewPackageInterop`: after `resolvePreviewCandidates` and before `previewPage` and the `totals`, filter `rows` by `request.branchChatId` when set and `source === "messages"`. - `previewPage`: include `branchChatId` in the cursor binding hash, so a cursor from one filter is rejected under another. Shared, `packages/long-term-memory/src/engine/packages/shared/src/features/agents/long-term-memory/schema/sources.ts`: - `ltmInteropPreviewRequestSchema`: add `branchChatId: z.string().min(1).max(200).optional()`. Client, `packages/long-term-memory/src/engine/packages/client/src/features/long-term-memory/sources/SourcesWorkspace.tsx` and `locales/en.json`: - `branchChatId` state, default the current chat, reset when the chat or source target changes. - Branch options from `scopeTargets.data.groups` / `chats`, shown only for `source === "messages"` and a group with more than one chat. - Add `branchChatId` to the preview request body and to `previewQueryKey`. - A native `<select>` like the Mode select (`data-ltm-source-branch`, aria-label), using `confirmSelectionChange()` and `clearImportResult()` on change. - New locale keys under `ui.longTermMemory.sourcesworkspace` (the existing `allBranches` key is reused for "All branches"). `packages/long-term-memory/CHANGELOG.md`: one user-facing line under `## Unreleased`. Regression: extend `tests/long-term-memory-chat-transcript-import.regression.ts`. Add a sibling branch whose messages diverge from `branchChat`, preview with `branchChatId` set to each branch, and expect the shared piece under both, each branch-only piece under only its own, `totals` consistent with the rows, and a cursor from one filter rejected under another. A `branchChatId` outside the group yields no rows. ## Why should this be optional? It lives in the Long-Term Memory package, which is already optional. Within the package it adds no setting: a chat without branches sees no dropdown, and "All branches" keeps today's list. ## Alternatives considered - **Detect the fork point from branch metadata** (`branchParentMessageId`): rejected for now. Branches of branches and edited copies make it unreliable; piece text equality already drives the existing de-duplication. - **Import into a per-branch destination:** rejected. Memory belongs to the chat as a whole, and the user asked for the import to stay whole-chat. - **Label pieces with their branch instead of filtering:** more noise in a list that is already long. Known limit: shared history is recognised by identical piece text, so a piece that spans the fork point (shared plus branch-only messages) differs per branch and shows under its own branch only. ## Additional context Follow-up to #1747 (LTM 1.5.0). Requested by the maintainer after trying the Chat Messages tab on a chat with several drafts. ## Template check Please **uncheck (untick)** 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-11-07 16:36:21 +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-Agents#1739
No description provided.