[GH-ISSUE #8951] [Feature]: Tell Long-Term Memory when a chat is branched #8906

Closed
opened 2026-11-07 23:46:59 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @Promansis on GitHub (Nov 7, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/8951

Originally assigned to: @Promansis on GitHub.

What problem does this solve?

When a chat is branched, the Engine copies the parent's messages together with their "hidden from the AI" flags. The Long-Term Memory package hides older messages it has already turned into memories. It also keeps the last few visible, so a branch made from inside a hidden stretch starts with every copied message hidden. LTM can only show the branch's last messages again once it is asked about that chat, and the first time that happens is the branch's first recall. That recall runs after the Engine has already read the history, so:

  • the branch opens with its recent messages shown as hidden, and they only appear after the first reply;
  • the first reply in the branch is written without those recent messages.

Packages hear nothing about new chats, so LTM cannot fix this on its own.

Proposed solution

Add one optional method to the existing host-only long-term-memory:runtime service. After the branch route has finished copying (messages, metadata and snapshots), the Engine awaits it once, before it returns the new chat:

chatBranched?(input: { chatId: string; parentChatId: string }): Promise<void>;

A package without the method changes nothing. A thrown error or a slow call is logged and never fails the branch: the Engine waits at most a few seconds, then returns the branch anyway.

Minimal fix

Tip checked: upstream/staging 8ee9cc2d13 (2026-11-07); line hints may drift, re-grep.

  • packages/server/src/services/generation/long-term-memory-runtime.ts:
    • add chatBranched? to LongTermMemoryRuntimeService (:20-41), with a doc comment naming the Capability API minor;
    • add a small exported helper next to recordLongTermMemoryPromptAccepted (:162-172), e.g. notifyLongTermMemoryChatBranched(input). It reads runtimeService(), returns when the method is missing, and awaits it under a fixed cap (ponytail: comment naming the cap and the upgrade path). It logs a failure or timeout with logger.warn(err, ...) and never throws.
  • packages/server/src/routes/chats.routes.ts, POST /:id/branch (:5559): after the snapshot try/catch ends (:6048) and before storage.getById(newChat.id) (:6050), call await notifyLongTermMemoryChatBranched({ chatId: newChat.id, parentChatId: sourceChat.id }). Only this route creates branch chats (storage.create :5594, metadata :5819-5830).
  • packages/shared/src/schemas/capability-package.schema.ts:1575: bump supportedCapabilityApi to the next free minor (1.817 at this tip), with a version comment in the existing style. Use the next free number if staging moved.
  • docs/development/optional-agent-packages.md (near :1901, beside summaryMemoryInstruction): document chatBranched, when it runs, that the branch's messages and metadata already exist, and that errors and timeouts are ignored.
  • Regression: extend scripts/regressions/capability-package-lifecycle.regression.ts (it already registers long-term-memory:runtime) or the branch-route regression nearest the route. Cover three cases:
    1. branching calls chatBranched once with the new chat id and the source chat id, and inside the call the branch's copied messages and branchParentChatId metadata are readable;
    2. a service that throws, or never resolves within the cap, still returns the branch;
    3. a service without the method branches as before.

Non-goals: a general chat-event bus for every package; a manifest field or permission; client changes; changing which flags the branch copies. Do not touch CHANGELOG.md (Engine rule: release PRs only).

Alternatives considered

  • LTM checks for new branches on a timer. It lags behind the branch opening, and the first reply can still miss messages.
  • LTM runs the pass when the vault or chat drawer is opened. That doesn't fire when the branch is simply opened.
  • The Engine stops copying hidden flags. That would wrongly show messages the user hid by hand.

Additional context

The package side, which runs LTM's existing branch pass from chatBranched, lives in Pasta-Devs/Marinara-Agents. Older Engines keep the current behavior: the pass runs at the branch's first recall.

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 (Nov 7, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/8951 Originally assigned to: @Promansis on GitHub. ## What problem does this solve? When a chat is branched, the Engine copies the parent's messages together with their "hidden from the AI" flags. The Long-Term Memory package hides older messages it has already turned into memories. It also keeps the last few visible, so a branch made from inside a hidden stretch starts with every copied message hidden. LTM can only show the branch's last messages again once it is asked about that chat, and the first time that happens is the branch's first recall. That recall runs after the Engine has already read the history, so: - the branch opens with its recent messages shown as hidden, and they only appear after the first reply; - the first reply in the branch is written without those recent messages. Packages hear nothing about new chats, so LTM cannot fix this on its own. ## Proposed solution Add one optional method to the existing host-only `long-term-memory:runtime` service. After the branch route has finished copying (messages, metadata and snapshots), the Engine awaits it once, before it returns the new chat: ```ts chatBranched?(input: { chatId: string; parentChatId: string }): Promise<void>; ``` A package without the method changes nothing. A thrown error or a slow call is logged and never fails the branch: the Engine waits at most a few seconds, then returns the branch anyway. ## Minimal fix Tip checked: upstream/staging 8ee9cc2d13 (2026-11-07); line hints may drift, re-grep. - `packages/server/src/services/generation/long-term-memory-runtime.ts`: - add `chatBranched?` to `LongTermMemoryRuntimeService` (:20-41), with a doc comment naming the Capability API minor; - add a small exported helper next to `recordLongTermMemoryPromptAccepted` (:162-172), e.g. `notifyLongTermMemoryChatBranched(input)`. It reads `runtimeService()`, returns when the method is missing, and awaits it under a fixed cap (`ponytail:` comment naming the cap and the upgrade path). It logs a failure or timeout with `logger.warn(err, ...)` and never throws. - `packages/server/src/routes/chats.routes.ts`, `POST /:id/branch` (:5559): after the snapshot `try/catch` ends (:6048) and before `storage.getById(newChat.id)` (:6050), call `await notifyLongTermMemoryChatBranched({ chatId: newChat.id, parentChatId: sourceChat.id })`. Only this route creates branch chats (`storage.create` :5594, metadata :5819-5830). - `packages/shared/src/schemas/capability-package.schema.ts:1575`: bump `supportedCapabilityApi` to the next free minor (1.817 at this tip), with a version comment in the existing style. Use the next free number if staging moved. - `docs/development/optional-agent-packages.md` (near :1901, beside `summaryMemoryInstruction`): document `chatBranched`, when it runs, that the branch's messages and metadata already exist, and that errors and timeouts are ignored. - Regression: extend `scripts/regressions/capability-package-lifecycle.regression.ts` (it already registers `long-term-memory:runtime`) or the branch-route regression nearest the route. Cover three cases: 1. branching calls `chatBranched` once with the new chat id and the source chat id, and inside the call the branch's copied messages and `branchParentChatId` metadata are readable; 2. a service that throws, or never resolves within the cap, still returns the branch; 3. a service without the method branches as before. Non-goals: a general chat-event bus for every package; a manifest field or permission; client changes; changing which flags the branch copies. Do not touch `CHANGELOG.md` (Engine rule: release PRs only). ## Alternatives considered - **LTM checks for new branches on a timer.** It lags behind the branch opening, and the first reply can still miss messages. - **LTM runs the pass when the vault or chat drawer is opened.** That doesn't fire when the branch is simply opened. - **The Engine stops copying hidden flags.** That would wrongly show messages the user hid by hand. ## Additional context The package side, which runs LTM's existing branch pass from `chatBranched`, lives in Pasta-Devs/Marinara-Agents. Older Engines keep the current behavior: the pass runs at the branch's first recall. ## 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.
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#8906
No description provided.