[GH-ISSUE #1194] [Issue]: Long-Term Memory: targeted group recall must return only the responder's memories #612

Closed
opened 2026-10-20 17:29:01 +07:00 by bsakaguchi · 0 comments
Owner

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

Originally assigned to: @Promansis on GitHub.

Summary

In a multi-character group chat, the Engine targets one responder and passes that responder's id in promptCharacterIds, but the package ignores it: generation recall uses the chat's full characterIds and includes global notes unconditionally. A targeted responder can therefore receive every other character's memories.

Affected package

long-term-memory (Long-Term Memory), generation recall scope. Finding A2. This is a package-only change; the Engine already supplies the target ids.

Expected behavior

When the Engine targets a single responder in a multi-character chat, generation recall must return only that character's memories:

  • Eligible: notes explicitly scoped to the target character (the target is in scope.characterIds and no other character is).
  • Excluded: global/unscoped notes; chat-only, group-only, or persona-only notes with no target character; notes scoped to a different character; and notes that mix the target with any other character.
  • Keep the restriction on generation recall only. Do not change matchesLtmScope/ltmScopesOverlap defaults used by vault listing (GET /notes), note transfer, extraction, reconciliation, subject-identity, or the public /search route.
  • When the Engine supplies the chat's full character set (non-targeted/mixed generation) or the chat has a single character, preserve today's chat-wide behavior, including shared/global notes.

The Engine's current handoff makes the target detectable: resolvePromptCharacterIdsForTarget returns a one-element list when forCharacterId matches, otherwise the full set. The package should treat a supplied character set that is a strict, non-empty subset of a multi-character chat's characters as the target scope, and pass an explicit "exclude global/foreign" signal into retrieval rather than relying on the current unconditional includeGlobal: true. If the implementer finds this heuristic ambiguous, prefer an explicit Engine target flag before widening the package contract.

Actual behavior

  • prepareGenerationLongTermMemory ignores its input.characterIds and calls retrieveLongTermMemory with characterIds: chat.characterIds and scope = resolveChatLtmScope(chat), which already carries every chat character.
  • retrieveLongTermMemory unions scope.characterIds with input.characterIds and passes includeGlobal: true, so global, chat-only, mixed-character, and foreign-character/shared-chat notes all match.
  • A disposable package-runtime fixture recalled both world_a (target A) and world_b (target B) for each target direction. Scope-helper controls accepted global, chat-only, mixed-character, and foreign-character/shared-chat notes.

Steps to reproduce

  1. Activate the package runtime against a disposable vault. Create world_a scoped to character A and world_b scoped to character B in a chat with characterIds: ["A", "B"]; build the index.
  2. Call runtime.recall({ chatId, chatMode, characterIds: ["A"], ... }) and inspect receipt.artifact.chunks. It returns both world_a and world_b.
  3. Repeat with characterIds: ["B"]; it again returns both.
  4. Add global, chat-only, mixed (["A","B"]), and foreign/shared-chat notes and confirm each currently matches, then confirm the strict contract excludes them.

Environment

  • Marinara Engine version: 2.4.6 (227e3e12c87a55c40074413f1f32e57d732217da); its resolvePromptCharacterIdsForTarget handoff was read directly.
  • Package version: 1.3.34 at the time of the fixture; package 1.3.36 is current upstream and does not change this behavior.
  • Install type: source-module/runtime fixture; not an installed ZIP-package test or live group-chat/browser test.
  • OS + version: Linux; exact distribution/version not captured.
  • Browser or app shell: not applicable; Node v24.15.0, installed tsx 4.23.13.

Logs, screenshots, or video

Relevant output from the disposable readiness fixture (/tmp/opencode/ltm-readiness-proof.mts):

{"case":"group-target","target":"A","recalledNotes":["world_a","world_b"]}
{"case":"group-target","target":"B","recalledNotes":["world_a","world_b"]}
{"case":"scope-overlap","accepted":{"global":true,"chatWide":true,"mixedCharacters":true,"otherCharacterSharedChat":true}}

The desired-invariant run exited 1 with:

Targeted recall must exclude every other character's memories
actual: [ 'world_a', 'world_b' ]
expected: [ 'world_a' ]

No private chat data or real provider/model calls were used.

Additional context

Scope and ownership

  • Implement against Agents staging. No Engine source change is strictly required because the Engine already passes promptCharacterIds; if the subset heuristic is rejected, coordinate an explicit target flag as a separate Engine issue rather than shipping an ambiguous contract.
  • Primary owners: packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/{generation-injection,retrieval,chat-scope}.ts and the shared scope.ts matcher, with the strict behavior passed as an explicit option.
  • Keep the strict path opt-in from generation; do not change default matchesLtmScope/ltmScopesOverlap semantics for other callers.
  • Keep this separate from the A3 history-only query change (Engine issue 10). Do not combine scope narrowing with query-source filtering.
  • Preserve mode filtering, status/archived filtering, exact-text dedup, and lexical/semantic/graph/keyword ranking for eligible notes. Do not change scoring or tier policy.

Open product detail to confirm in review

Excluding chat-only and global notes from a targeted group responder is the maintainer's stated strict contract. If shared context for a chat is wanted instead, that is a different decision and must be stated explicitly before implementation.

Validation plan

  • Add the smallest regression proving target A returns only world_a and target B returns only world_b, then reverse the target.
  • Prove global, chat-only, mixed-character, and foreign-character/shared-chat notes are excluded in targeted mode while remaining eligible in non-targeted/single-character generation.
  • Prove non-generation matchesLtmScope consumers (vault listing, transfer, extraction, reconciliation, subject-identity, /search) are unchanged.
  • Cover a target that is not in the chat, an empty target set, and a chat whose character list changes between index build and recall.
  • Run affected runtime, scope-targets, storage, routes, and local-characters regressions; run repository-required validation and rebuild/validate generated outputs before publication.

Proof above is characterization and a red baseline, not repaired behavior or release validation. Installed dependencies differ from the repository's pins; install locked dependencies in the implementation workspace before claiming repository gates. Live group-chat/browser validation remains a manual PR item.

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 2, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1194 Originally assigned to: @Promansis on GitHub. ## Summary In a multi-character group chat, the Engine targets one responder and passes that responder's id in `promptCharacterIds`, but the package ignores it: generation recall uses the chat's full `characterIds` and includes global notes unconditionally. A targeted responder can therefore receive every other character's memories. ## Affected package `long-term-memory` (Long-Term Memory), generation recall scope. Finding A2. This is a package-only change; the Engine already supplies the target ids. ## Expected behavior When the Engine targets a single responder in a multi-character chat, generation recall must return only that character's memories: - Eligible: notes explicitly scoped to the target character (the target is in `scope.characterIds` and no other character is). - Excluded: global/unscoped notes; chat-only, group-only, or persona-only notes with no target character; notes scoped to a different character; and notes that mix the target with any other character. - Keep the restriction on generation recall only. Do not change `matchesLtmScope`/`ltmScopesOverlap` defaults used by vault listing (`GET /notes`), note transfer, extraction, reconciliation, `subject-identity`, or the public `/search` route. - When the Engine supplies the chat's full character set (non-targeted/mixed generation) or the chat has a single character, preserve today's chat-wide behavior, including shared/global notes. The Engine's current handoff makes the target detectable: `resolvePromptCharacterIdsForTarget` returns a one-element list when `forCharacterId` matches, otherwise the full set. The package should treat a supplied character set that is a strict, non-empty subset of a multi-character chat's characters as the target scope, and pass an explicit "exclude global/foreign" signal into retrieval rather than relying on the current unconditional `includeGlobal: true`. If the implementer finds this heuristic ambiguous, prefer an explicit Engine target flag before widening the package contract. ## Actual behavior - `prepareGenerationLongTermMemory` ignores its `input.characterIds` and calls `retrieveLongTermMemory` with `characterIds: chat.characterIds` and `scope = resolveChatLtmScope(chat)`, which already carries every chat character. - `retrieveLongTermMemory` unions `scope.characterIds` with `input.characterIds` and passes `includeGlobal: true`, so global, chat-only, mixed-character, and foreign-character/shared-chat notes all match. - A disposable package-runtime fixture recalled both `world_a` (target A) and `world_b` (target B) for each target direction. Scope-helper controls accepted global, chat-only, mixed-character, and foreign-character/shared-chat notes. ## Steps to reproduce 1. Activate the package runtime against a disposable vault. Create `world_a` scoped to character A and `world_b` scoped to character B in a chat with `characterIds: ["A", "B"]`; build the index. 2. Call `runtime.recall({ chatId, chatMode, characterIds: ["A"], ... })` and inspect `receipt.artifact.chunks`. It returns both `world_a` and `world_b`. 3. Repeat with `characterIds: ["B"]`; it again returns both. 4. Add global, chat-only, mixed (`["A","B"]`), and foreign/shared-chat notes and confirm each currently matches, then confirm the strict contract excludes them. ## Environment - Marinara Engine version: `2.4.6` (`227e3e12c87a55c40074413f1f32e57d732217da`); its `resolvePromptCharacterIdsForTarget` handoff was read directly. - Package version: `1.3.34` at the time of the fixture; package `1.3.36` is current upstream and does not change this behavior. - Install type: source-module/runtime fixture; not an installed ZIP-package test or live group-chat/browser test. - OS + version: Linux; exact distribution/version not captured. - Browser or app shell: not applicable; Node `v24.15.0`, installed `tsx` `4.23.13`. ## Logs, screenshots, or video Relevant output from the disposable readiness fixture (`/tmp/opencode/ltm-readiness-proof.mts`): ```json {"case":"group-target","target":"A","recalledNotes":["world_a","world_b"]} {"case":"group-target","target":"B","recalledNotes":["world_a","world_b"]} {"case":"scope-overlap","accepted":{"global":true,"chatWide":true,"mixedCharacters":true,"otherCharacterSharedChat":true}} ``` The desired-invariant run exited 1 with: ```text Targeted recall must exclude every other character's memories actual: [ 'world_a', 'world_b' ] expected: [ 'world_a' ] ``` No private chat data or real provider/model calls were used. ## Additional context ### Scope and ownership - Implement against Agents `staging`. No Engine source change is strictly required because the Engine already passes `promptCharacterIds`; if the subset heuristic is rejected, coordinate an explicit target flag as a separate Engine issue rather than shipping an ambiguous contract. - Primary owners: `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/{generation-injection,retrieval,chat-scope}.ts` and the shared `scope.ts` matcher, with the strict behavior passed as an explicit option. - Keep the strict path opt-in from generation; do not change default `matchesLtmScope`/`ltmScopesOverlap` semantics for other callers. - Keep this separate from the A3 history-only query change (Engine issue 10). Do not combine scope narrowing with query-source filtering. - Preserve mode filtering, status/archived filtering, exact-text dedup, and lexical/semantic/graph/keyword ranking for eligible notes. Do not change scoring or tier policy. ### Open product detail to confirm in review Excluding chat-only and global notes from a targeted group responder is the maintainer's stated strict contract. If shared context for a chat is wanted instead, that is a different decision and must be stated explicitly before implementation. ### Validation plan - [ ] Add the smallest regression proving target A returns only `world_a` and target B returns only `world_b`, then reverse the target. - [ ] Prove global, chat-only, mixed-character, and foreign-character/shared-chat notes are excluded in targeted mode while remaining eligible in non-targeted/single-character generation. - [ ] Prove non-generation `matchesLtmScope` consumers (vault listing, transfer, extraction, reconciliation, `subject-identity`, `/search`) are unchanged. - [ ] Cover a target that is not in the chat, an empty target set, and a chat whose character list changes between index build and recall. - [ ] Run affected runtime, scope-targets, storage, routes, and local-characters regressions; run repository-required validation and rebuild/validate generated outputs before publication. Proof above is characterization and a red baseline, not repaired behavior or release validation. Installed dependencies differ from the repository's pins; install locked dependencies in the implementation workspace before claiming repository gates. Live group-chat/browser validation remains a manual PR item. ## 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-10-20 17:29:01 +07:00
  • closed this issue
  • added the
    bug
    label
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#612
No description provided.