[GH-ISSUE #1914] [Feature]: Long-Term Memory: optionally hide imported chat messages from the AI #1819

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

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

Originally assigned to: @Promansis on GitHub.

What problem does this solve?

The Engine's chat summary has "Hide summarised messages": once messages are summarised, they stop being sent to the AI, and the summary stands in for them. Long-Term Memory's Chat messages import has no equivalent. After a long chat is imported into memory, every imported message is still sent with each reply, alongside the memories recalled from it. The prompt carries the same history twice, and long chats keep paying for it.

Proposed package or change

An opt-in setting, off by default: Hide imported messages from the AI. When it is on, LTM hides the messages of each Chat messages piece it has imported, except the most recent ones. Turning it off shows them again.

Depends on Pasta-Devs/Marinara-Engine#8491 (persistence.setMessagesHiddenFromAI). LTM feature-detects that method: on an Engine without it, the setting is disabled with a short note, and nothing else changes. So no engine.min bump is needed, and the manifest keeps capabilityApi 1.387: declaring 1.388 would make every Engine at 1.387 refuse the package.

Behaviour:

  • After a piece's source note commits, LTM hides that piece's messages. A piece that failed or was cancelled hides nothing.
  • Recent messages stay visible. The last N messages of the chat are never hidden. N is the chat's own summary tail (summaryTailMessages in the chat's metadata, the Engine's "keep last N messages"; default 10 when unset, 0 hides everything: SUMMARY_TAIL_MESSAGES, Engine shared/src/types/chat.ts ~305), so one setting governs both features. Like the Engine's computeSummaryHideIds, it counts the last N visible messages. As the chat grows, messages of imported pieces leave the tail; each later import (and turning the setting on) also hides those, as the summary re-hides a drifted tail.
  • A user's choice wins. If the user shows or hides an LTM-hidden message by hand (the Engine marks it visibilityManual), LTM drops it from its ownership record and never changes it again. From then on LTM reads it like any other message: shown by hand, it stays in its piece; hidden by hand, it leaves the piece as today, and the piece's source note shows as updated.
  • LTM owns only what it hid. It records the ids the Engine reports as changed, per source note. A message that was already hidden (by the summary, or by hand) is not LTM's, and LTM never shows it again. A message whose visibility the user set by hand is never touched; the Engine call enforces that.
  • Shown again when its memory goes away: when the setting is turned off, or when the piece's source note is permanently deleted, LTM shows exactly the messages it owns for that note.
  • Turning the setting on hides the messages of pieces already imported, as the summary does when its setting is turned on.

Minimal fix

Server, under packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/:

  • package-runtime.ts (~75): add the optional setMessagesHiddenFromAI to the persistence host type.
  • sources/interop.ts
    • transcriptPieces (~174; TranscriptPiece ~167)
      • Each TranscriptPiece also lists its messageIds.
      • It takes the set of ids LTM owns and treats those messages as visible, unless the message has visibilityManual. Today it skips every hiddenFromAI message (~188), so without this the next preview would lose every hidden piece and outdatedSourceNotes (~801) would offer to remove its source note.
      • Messages hidden by anyone else are still skipped, as today.
    • The chat-messages builder (~695) passes the owned ids, read once per chat. The tail comes from the chat already read there (chat.metadata, ~619).
    • After the import batch commits (the processLongTermMemorySourceBatch call, ~1283), hide the committed chat_transcript pieces' messages, minus the tail, and record what was flipped. No Engine chat lock: LTM never calls withChatLock today, and none is needed, because ownership is only what the Engine reports flipped. A message the summary or the user hid first is never claimed, and a deleted id is simply not returned.
  • persistence/storage.ts
    • A small ownership record in the vault: source note id → hidden message ids, per chat. The note's evidence caps at 100 entries, which a 24k-character piece can exceed, so the record lives beside the notes.
    • deleteNotesPermanently (~1095) shows the deleted source notes' owned messages again and drops their records. Moving a note to trash does not show them; restoring it keeps them hidden. It is also reached from scope pruning (~1363) and trash purge, so the show pass tolerates a chat that no longer exists (the host rejects with "was not found") and still drops the record.
  • Settings: shared/src/features/agents/long-term-memory/schema/settings.ts gets the boolean on ltmGlobalSettingsSchema (~43). Turning it on or off runs the hide or show pass described above.
  • Manifest: add chat-write to permissions. This is a permission change and needs explicit validation notes; existing installs see the new permission on update. LTM calls only the new method; it gains but does not use appendMessages, patchChatMetadata, createChatNote, createChatInfluence and updateCharacterStatus, and the PR's validation notes say so. capabilityApi stays 1.387 and engine.min stays 2.5.1.
  • Client:
    • the setting with its description, disabled with a note when the Engine lacks the method;
    • en and ko strings; node scripts/validate-package-locales.mjs must pass.

Regression: a deterministic test with a fake host and fake language model, next to tests/long-term-memory-chat-transcript-import.regression.ts:

  1. Setting off: an import calls nothing new.
  2. Setting on:
    • an import hides the committed pieces' messages except the tail;
    • the ownership record holds exactly the ids the host returned;
    • a message that was already hidden is not recorded.
  3. Re-preview after hiding:
    • the same pieces come back, with the same ids and text;
    • nothing is reported as outdated;
    • a message hidden by someone else is still skipped.
  4. Turning the setting off shows exactly the owned messages, and leaves an already-hidden message hidden.
  5. Tail drift: after new messages arrive, the next import hides the imported pieces' messages that left the tail.
  6. A user's choice:
    • after the user shows an owned message by hand, a later import doesn't hide it again and the record no longer lists it;
    • after the user hides an owned message by hand, the next preview leaves it out of its piece.
  7. Permanently deleting a piece's source note shows its messages again. Trashing it does not.
  8. With no host method:
    • the setting reports unavailable;
    • an import behaves exactly as today.

Non-goals

  • A per-chat override of the setting. It could come later, like the summary's per-chat switch.
  • Hiding chat summary sources, or any non-chat source.
  • Changing recall to make up for hidden messages.

Why should this be optional?

Hidden messages reach the AI only when recall brings them back as memories. A summary is always in the prompt, but LTM recall is selective, so continuity in a chat with this setting on depends on recall quality. That is a trade-off each user should choose, which is why it is off by default and keeps a recent tail.

Alternatives considered

  • Write an Engine summary entry for each imported piece, so the summary's hiding runs. It puts LTM's text into the chat's summary prompt and summary list. Rejected.
  • Hide without recording ownership. Turning the setting off would then show messages the summary or the user had hidden. Rejected.
  • Keep hidden messages out of LTM's own reading too. Every hidden piece would then look deleted on the next preview. Rejected.

Additional context

  • The Engine's summary does the same with hiddenMessageIds on each summary entry (summaryHidingPatch, generate-route-utils.ts ~867); this follows that model.
  • To check during implementation: whether branching a chat copies hiddenFromAI onto the copied messages. If it does, a branch's copies of hidden messages are not owned by LTM, and its Chat messages import would skip them like any other hidden message.

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @Promansis on GitHub (Oct 30, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1914 Originally assigned to: @Promansis on GitHub. ## What problem does this solve? The Engine's chat summary has "Hide summarised messages": once messages are summarised, they stop being sent to the AI, and the summary stands in for them. Long-Term Memory's Chat messages import has no equivalent. After a long chat is imported into memory, every imported message is still sent with each reply, alongside the memories recalled from it. The prompt carries the same history twice, and long chats keep paying for it. ## Proposed package or change An opt-in setting, off by default: **Hide imported messages from the AI**. When it is on, LTM hides the messages of each Chat messages piece it has imported, except the most recent ones. Turning it off shows them again. Depends on Pasta-Devs/Marinara-Engine#8491 (`persistence.setMessagesHiddenFromAI`). LTM feature-detects that method: on an Engine without it, the setting is disabled with a short note, and nothing else changes. So no `engine.min` bump is needed, and the manifest keeps `capabilityApi` 1.387: declaring 1.388 would make every Engine at 1.387 refuse the package. Behaviour: - After a piece's source note commits, LTM hides that piece's messages. A piece that failed or was cancelled hides nothing. - **Recent messages stay visible.** The last N messages of the chat are never hidden. N is the chat's own summary tail (`summaryTailMessages` in the chat's metadata, the Engine's "keep last N messages"; default 10 when unset, 0 hides everything: `SUMMARY_TAIL_MESSAGES`, Engine `shared/src/types/chat.ts` ~305), so one setting governs both features. Like the Engine's `computeSummaryHideIds`, it counts the last N *visible* messages. As the chat grows, messages of imported pieces leave the tail; each later import (and turning the setting on) also hides those, as the summary re-hides a drifted tail. - **A user's choice wins.** If the user shows or hides an LTM-hidden message by hand (the Engine marks it `visibilityManual`), LTM drops it from its ownership record and never changes it again. From then on LTM reads it like any other message: shown by hand, it stays in its piece; hidden by hand, it leaves the piece as today, and the piece's source note shows as updated. - **LTM owns only what it hid.** It records the ids the Engine reports as changed, per source note. A message that was already hidden (by the summary, or by hand) is not LTM's, and LTM never shows it again. A message whose visibility the user set by hand is never touched; the Engine call enforces that. - **Shown again when its memory goes away:** when the setting is turned off, or when the piece's source note is permanently deleted, LTM shows exactly the messages it owns for that note. - **Turning the setting on** hides the messages of pieces already imported, as the summary does when its setting is turned on. ### Minimal fix Server, under `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/`: - `package-runtime.ts` (~75): add the optional `setMessagesHiddenFromAI` to the `persistence` host type. - `sources/interop.ts` - `transcriptPieces` (~174; `TranscriptPiece` ~167) - Each `TranscriptPiece` also lists its `messageIds`. - It takes the set of ids LTM owns and treats those messages as visible, unless the message has `visibilityManual`. Today it skips every `hiddenFromAI` message (~188), so without this the next preview would lose every hidden piece and `outdatedSourceNotes` (~801) would offer to remove its source note. - Messages hidden by anyone else are still skipped, as today. - The chat-messages builder (~695) passes the owned ids, read once per chat. The tail comes from the chat already read there (`chat.metadata`, ~619). - After the import batch commits (the `processLongTermMemorySourceBatch` call, ~1283), hide the committed `chat_transcript` pieces' messages, minus the tail, and record what was flipped. No Engine chat lock: LTM never calls `withChatLock` today, and none is needed, because ownership is only what the Engine reports flipped. A message the summary or the user hid first is never claimed, and a deleted id is simply not returned. - `persistence/storage.ts` - A small ownership record in the vault: source note id → hidden message ids, per chat. The note's `evidence` caps at 100 entries, which a 24k-character piece can exceed, so the record lives beside the notes. - `deleteNotesPermanently` (~1095) shows the deleted source notes' owned messages again and drops their records. Moving a note to trash does not show them; restoring it keeps them hidden. It is also reached from scope pruning (~1363) and trash purge, so the show pass tolerates a chat that no longer exists (the host rejects with "was not found") and still drops the record. - Settings: `shared/src/features/agents/long-term-memory/schema/settings.ts` gets the boolean on `ltmGlobalSettingsSchema` (~43). Turning it on or off runs the hide or show pass described above. - Manifest: add `chat-write` to `permissions`. This is a permission change and needs explicit validation notes; existing installs see the new permission on update. LTM calls only the new method; it gains but does not use `appendMessages`, `patchChatMetadata`, `createChatNote`, `createChatInfluence` and `updateCharacterStatus`, and the PR's validation notes say so. `capabilityApi` stays 1.387 and `engine.min` stays 2.5.1. - Client: - the setting with its description, disabled with a note when the Engine lacks the method; - `en` and `ko` strings; `node scripts/validate-package-locales.mjs` must pass. Regression: a deterministic test with a fake host and fake language model, next to `tests/long-term-memory-chat-transcript-import.regression.ts`: 1. Setting off: an import calls nothing new. 2. Setting on: - an import hides the committed pieces' messages except the tail; - the ownership record holds exactly the ids the host returned; - a message that was already hidden is not recorded. 3. Re-preview after hiding: - the same pieces come back, with the same ids and text; - nothing is reported as outdated; - a message hidden by someone else is still skipped. 4. Turning the setting off shows exactly the owned messages, and leaves an already-hidden message hidden. 5. Tail drift: after new messages arrive, the next import hides the imported pieces' messages that left the tail. 6. A user's choice: - after the user shows an owned message by hand, a later import doesn't hide it again and the record no longer lists it; - after the user hides an owned message by hand, the next preview leaves it out of its piece. 7. Permanently deleting a piece's source note shows its messages again. Trashing it does not. 8. With no host method: - the setting reports unavailable; - an import behaves exactly as today. ### Non-goals - A per-chat override of the setting. It could come later, like the summary's per-chat switch. - Hiding chat summary sources, or any non-chat source. - Changing recall to make up for hidden messages. ## Why should this be optional? Hidden messages reach the AI only when recall brings them back as memories. A summary is always in the prompt, but LTM recall is selective, so continuity in a chat with this setting on depends on recall quality. That is a trade-off each user should choose, which is why it is off by default and keeps a recent tail. ## Alternatives considered - **Write an Engine summary entry for each imported piece, so the summary's hiding runs.** It puts LTM's text into the chat's summary prompt and summary list. Rejected. - **Hide without recording ownership.** Turning the setting off would then show messages the summary or the user had hidden. Rejected. - **Keep hidden messages out of LTM's own reading too.** Every hidden piece would then look deleted on the next preview. Rejected. ## Additional context - The Engine's summary does the same with `hiddenMessageIds` on each summary entry (`summaryHidingPatch`, `generate-route-utils.ts` ~867); this follows that model. - To check during implementation: whether branching a chat copies `hiddenFromAI` onto the copied messages. If it does, a branch's copies of hidden messages are not owned by LTM, and its Chat messages import would skip them like any other hidden message. ## Template check - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-11-07 16:36:53 +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#1819
No description provided.