[GH-ISSUE #1533] [Issue]: Long-Term Memory: extraction writes a private copy instead of updating a shared memory #1510

Closed
opened 2026-10-22 04:02:49 +07:00 by bsakaguchi · 0 comments
Owner

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

Originally assigned to: @Promansis on GitHub.

Summary

When you share a memory with a character, and the chat it came from keeps adding to it, extraction never updates the shared memory. It silently writes a private copy for that chat instead. From then on the chat recalls two versions: the shared memory, frozen at the moment you shared it, and the copy, which keeps changing. The character's other chats only ever see the frozen version, and nothing tells you this happened.

With the fix, the chat's new content is offered in Review as a change to the shared memory, with a note that accepting it also adds it where the memory is shared. Nothing reaches the shared memory without your review, and a review writes only the rows you selected. A chat that already has its own copy keeps updating that copy, so its updates don't split between two memories.

Affected package

long-term-memory 1.4.69 (upstream/staging 5984f0784).

S = packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory
C = packages/long-term-memory/src/engine/packages/client/src/features/long-term-memory

Expected behavior

  • A chat may still never write into a memory visible outside it without your review (#1028).
  • When the memory it would update has been shared beyond the chat (its scope includes the chat and more), the update is offered on that memory in Review, marked as a shared-memory change.
    • It is never auto-applied.
    • Accepting writes only the rows you selected. A row included automatically never writes to a shared memory: not a shared event's change pulled in by a link to it, and not the grounding link that goes with a change you selected.
  • The same holds for any narrower source, not only chats: for example, a character-scoped source and a memory that also names a persona.
  • A chat that already has its own copy of the memory keeps updating that copy.
  • A memory that belongs to another chat, or a global memory, is still never a target: those still get a private copy, as today.

Actual behavior

  • A chat's extraction writes with a chat-only scope (resolveChatLtmWriteScope, S/identity/chat-scope.ts:74).
  • canUpdateLtmScopedTarget (S/extraction/scoped-targets.ts:33-44, #1037) lets a source update a note only when the note's scope is inside the source's scope. A note shared with a character is broader than the chat, so the chat can't update it.
  • resolveScopedEvidenceUnitTargets (S/extraction/scoped-targets.ts:69-150) then remaps the unit to a scope-suffixed copy id (scopedVariantNoteId, :62; resolver :114) and adds a target_note_scoped_variant draft diagnostic (:133). That diagnostic only shows in the draft's extraction details, not on the Review row.
  • The copy id is deterministic per scope, so later extractions update the copy, never the shared memory.
  • This is the 1.3.14 behavior "Fork new chat-only evidence instead of adding it to a previously broader memory". The fix replaces the fork with a review suggestion and keeps the automatic write blocked.
  • Every later stage enforces the same rule, so a reviewed update can't reach the shared memory either: the draft projector (S/drafts/draft-projector.ts:249) and apply's preflight (S/drafts/reconciliation.ts:338) both reject the target with "belongs to another scope".
  • Notes kept the broad scope they had before #1037 (merged 2026-09-23, LTM 1.3.14) were never migrated, so they behave the same way: memories that automatically picked up a character or group before chat-only destinations.
  • Once a copy exists, candidate reconciliation and the model's prompt only ever see the copy. It passes canUpdate (S/extraction/candidate-reconciliation.ts:270) and is listed (S/extraction/source-extraction.ts:351); the shared memory never is. Any fix has to agree with them, or updates split between the two.
  • Apply auto-includes the pending changes of a timeline event that a selected row links to, when the event is not yet grounded in this source (S/drafts/reconciliation.ts:839-852). Once a shared event can carry this chat's changes, a fix must not let that path write it.

Evidence

Private T6 harness, reduced3 runs: about a fifth of "new" world notes per run (9–14) are such copies, 129 in all.

  • 58 target a world note from another chat. That is chat isolation and stays.
  • 71 target a note from the same chat that you later shared with a character. That is this issue.

The harness never writes, so it re-creates the copies every run. In real use it is one copy per shared memory per chat.

Private vault copy, aggregates only:

  • 182 non-source memories: 80 chat-only, 34 chat + character (created 2026-10-04, shared by the user on 2026-10-05) and 68 chat + character + group (created 2026-09-21, before #1037, so they kept the legacy broad scope).
  • 3 shared memories already have a private copy next to them.
  • 17 drafts, none pending.

Steps to reproduce

Example (anonymised):

  1. In chat A the story establishes "The harbor gate closes at dusk." Extraction saves it as a chat-only world memory, Harbor gate.
  2. You then share Harbor gate with the character Mira, so her other chats know it too.
  3. Later in chat A the story changes: "The gate now opens only for a brass token."
  • Before: extraction creates Harbor gate (chat A copy) with the brass-token fact and leaves the shared memory alone. Chat A now recalls both "closes at dusk" and "brass token". Mira's other chats still only know "closes at dusk". Review shows a new memory, not a change to the one you shared.
  • After: Review shows the brass-token change on Harbor gate itself, with the note "This memory is shared beyond this source, for example with a character or persona. Accepting adds this change everywhere it is shared; reject it to keep the change out."
    • Accept: the shared memory updates everywhere it is shared.
    • Reject: nothing changes and no copy is made. Chat A no longer keeps the brass-token fact as a memory; it stays in the chat summary.
  • If chat A already made its copy before this fix: chat A keeps updating that copy, as before. Delete the copy to get suggestions on Harbor gate instead.

Minimal fix

No new suggestion kind, no new UI surface, no schema change. Three conditions must all hold, and the privacy rule stays as it is for everything else.

  1. S/extraction/scoped-targets.ts: add isSharedLtmScopedTarget(existing, incoming). It is true when the source may not update the note but the note includes every scope link of the source: !canUpdate(existing, incoming) && canUpdate(incoming, existing). In resolveScopedEvidenceUnitTargets, such a note stays the target (no copy) when there is no identity conflict and the source has no copy of it yet. An existing copy (scopedVariantNoteId or the legacy id) stays the target, so this pass agrees with reconciliation and the prompt.
  2. S/extraction/evidence-unit-compiler.ts: changes to a note the source may not update are never low risk. They are raised to medium, so low-risk auto-apply (API applyLowRisk, S/extraction/source-processing.ts:420) skips them.
  3. S/drafts/draft-projector.ts:249: project shared targets, so Review can show the before and after.
  4. S/drafts/reconciliation.ts, three changes:
    • preflight takes the ids the caller named: mutationIds, or all ids when none are given, or null for auto-apply. It admits a shared target only when every mutation on it is named, so auto-apply and auto-included rows fail closed.
    • preflightLongTermMemoryDraft passes its selected ids, so Review shows such a row as blocked.
    • applyInner's event auto-include skips shared events: their changes wait for their own rows.
  5. S/drafts/draft-review.ts: add a shared_memory_update warning to every Review row on a shared memory. It is read at review time, so a memory shared after extraction also shows the warning. C/review/ReviewQueue.tsx:1788-1798 already shows row diagnostics.

The client already names the grounding add_link row and the event create that go with a selected row (C/review/review-state.ts:175), so normal Review accepts are not blocked.

Unchanged:

  • Creates still fork (remapDraftCreatesForProjection, S/extraction/source-extraction.ts:153).
  • The model's prompt still lists only memories the source may update (source-extraction.ts:351).
  • Global memories and other chats' memories still fork.
  • note-fork-repair never merges a copy into a memory with different availability.

CHANGELOG (user-visible), five points:

  • When a chat adds to a memory you shared with a character or persona, Review offers the change on that memory. Before, extraction silently made a private copy.
  • Only rows you select are written.
  • Rejecting means the chat no longer keeps that fact as a memory; it stays in the chat summary.
  • Memories from before 1.3.14 that picked up a character or group count as shared.
  • A chat's existing copy keeps updating until you delete it.

Regression proof

Write first; it must fail on the current code.

  1. tests/long-term-memory-delta-review.regression.ts, after the canUpdateLtmScopedTarget cases (:74): truth table for isSharedLtmScopedTarget.
    • chat + character, or a legacy chats + group scope, over its own chat: true.
    • Another chat's memory, the same chat-only scope, or a global memory: false.
  2. tests/long-term-memory-extraction-graph.regression.ts, end to end after the event-shaped review block (:1176). Setup: a chat-only source, and a world memory from that chat shared with a character. The model fixture returns new evidence for that memory, and processLongTermMemorySource runs with applyLowRisk: true.
    • No copy is created, and the memory's changes are in the draft with no low-risk mutation.
    • Nothing is auto-applied, the draft stays pending and the memory is unchanged.
    • Every Review row on it carries shared_memory_update.
    • Backstop: with the stored risks forced to low, low-risk auto-apply rejects with "belongs to another scope", and the memory stays unchanged.
    • With the memory moved to another chat's scope, a reviewed apply rejects.
    • A Review accept applies the changes, and the memory keeps its character.
    • A chat memory's static link to a shared event is accepted alone: the link applies, and the event's pending change does not. The same link as a change claim rejects, and the event stays unchanged.
    • A change on the shared memory, selected without its grounding link: preflight blocks it and apply rejects. Selecting both applies.
  3. Same file, the scoped-target cases (:1983-1996).
    • The existing case "chat-only evidence forks instead of updating a persona-visible memory" now expects the memory (a legacy broad scope) as the target.
    • New: a chat's existing copy stays the target.
    • New: a memory from another chat with the same character still forks.

Environment

  • Marinara Engine version: 2.5.1 (staging 87d1ccadc)
  • Package version: long-term-memory 1.4.69 (upstream/staging 5984f0784)
  • Install type: source (code reading; counts from private harness runs and a private vault copy)
  • OS + version: not platform-specific
  • Browser or app shell: any

Logs, screenshots, or video

None. The counts come from private harness runs and a private vault copy, so only aggregates are shared.

Additional context

Tracker item EX-I14, found in the T6 harness runs. Related: #1028 and #1037 (LTM 1.3.14).

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 21, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1533 Originally assigned to: @Promansis on GitHub. ## Summary When you share a memory with a character, and the chat it came from keeps adding to it, extraction never updates the shared memory. It silently writes a private copy for that chat instead. From then on the chat recalls two versions: the shared memory, frozen at the moment you shared it, and the copy, which keeps changing. The character's other chats only ever see the frozen version, and nothing tells you this happened. With the fix, the chat's new content is offered in Review as a change to the shared memory, with a note that accepting it also adds it where the memory is shared. Nothing reaches the shared memory without your review, and a review writes only the rows you selected. A chat that already has its own copy keeps updating that copy, so its updates don't split between two memories. ## Affected package `long-term-memory` 1.4.69 (`upstream/staging` 5984f0784). `S` = `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory` `C` = `packages/long-term-memory/src/engine/packages/client/src/features/long-term-memory` ## Expected behavior - A chat may still never write into a memory visible outside it without your review (#1028). - When the memory it would update has been shared beyond the chat (its scope includes the chat and more), the update is offered on that memory in Review, marked as a shared-memory change. - It is never auto-applied. - Accepting writes only the rows you selected. A row included automatically never writes to a shared memory: not a shared event's change pulled in by a link to it, and not the grounding link that goes with a change you selected. - The same holds for any narrower source, not only chats: for example, a character-scoped source and a memory that also names a persona. - A chat that already has its own copy of the memory keeps updating that copy. - A memory that belongs to another chat, or a global memory, is still never a target: those still get a private copy, as today. ## Actual behavior - A chat's extraction writes with a chat-only scope (`resolveChatLtmWriteScope`, `S/identity/chat-scope.ts:74`). - `canUpdateLtmScopedTarget` (`S/extraction/scoped-targets.ts:33-44`, #1037) lets a source update a note only when the note's scope is inside the source's scope. A note shared with a character is broader than the chat, so the chat can't update it. - `resolveScopedEvidenceUnitTargets` (`S/extraction/scoped-targets.ts:69-150`) then remaps the unit to a scope-suffixed copy id (`scopedVariantNoteId`, `:62`; resolver `:114`) and adds a `target_note_scoped_variant` draft diagnostic (`:133`). That diagnostic only shows in the draft's extraction details, not on the Review row. - The copy id is deterministic per scope, so later extractions update the copy, never the shared memory. - This is the 1.3.14 behavior "Fork new chat-only evidence instead of adding it to a previously broader memory". The fix replaces the fork with a review suggestion and keeps the automatic write blocked. - Every later stage enforces the same rule, so a reviewed update can't reach the shared memory either: the draft projector (`S/drafts/draft-projector.ts:249`) and apply's `preflight` (`S/drafts/reconciliation.ts:338`) both reject the target with "belongs to another scope". - Notes kept the broad scope they had before #1037 (merged 2026-09-23, LTM 1.3.14) were never migrated, so they behave the same way: memories that automatically picked up a character or group before chat-only destinations. - Once a copy exists, candidate reconciliation and the model's prompt only ever see the copy. It passes `canUpdate` (`S/extraction/candidate-reconciliation.ts:270`) and is listed (`S/extraction/source-extraction.ts:351`); the shared memory never is. Any fix has to agree with them, or updates split between the two. - Apply auto-includes the pending changes of a timeline event that a selected row links to, when the event is not yet grounded in this source (`S/drafts/reconciliation.ts:839-852`). Once a shared event can carry this chat's changes, a fix must not let that path write it. ### Evidence Private T6 harness, reduced3 runs: about a fifth of "new" world notes per run (9–14) are such copies, 129 in all. - 58 target a world note from another chat. That is chat isolation and stays. - 71 target a note from the same chat that you later shared with a character. That is this issue. The harness never writes, so it re-creates the copies every run. In real use it is one copy per shared memory per chat. Private vault copy, aggregates only: - 182 non-source memories: 80 chat-only, 34 chat + character (created 2026-10-04, shared by the user on 2026-10-05) and 68 chat + character + group (created 2026-09-21, before #1037, so they kept the legacy broad scope). - 3 shared memories already have a private copy next to them. - 17 drafts, none pending. ## Steps to reproduce Example (anonymised): 1. In chat A the story establishes "The harbor gate closes at dusk." Extraction saves it as a chat-only world memory, *Harbor gate*. 2. You then share *Harbor gate* with the character Mira, so her other chats know it too. 3. Later in chat A the story changes: "The gate now opens only for a brass token." - **Before:** extraction creates *Harbor gate* (chat A copy) with the brass-token fact and leaves the shared memory alone. Chat A now recalls both "closes at dusk" and "brass token". Mira's other chats still only know "closes at dusk". Review shows a new memory, not a change to the one you shared. - **After:** Review shows the brass-token change on *Harbor gate* itself, with the note "This memory is shared beyond this source, for example with a character or persona. Accepting adds this change everywhere it is shared; reject it to keep the change out." - Accept: the shared memory updates everywhere it is shared. - Reject: nothing changes and no copy is made. Chat A no longer keeps the brass-token fact as a memory; it stays in the chat summary. - **If chat A already made its copy before this fix:** chat A keeps updating that copy, as before. Delete the copy to get suggestions on *Harbor gate* instead. ## Minimal fix No new suggestion kind, no new UI surface, no schema change. Three conditions must all hold, and the privacy rule stays as it is for everything else. 1. `S/extraction/scoped-targets.ts`: add `isSharedLtmScopedTarget(existing, incoming)`. It is true when the source may not update the note but the note includes every scope link of the source: `!canUpdate(existing, incoming) && canUpdate(incoming, existing)`. In `resolveScopedEvidenceUnitTargets`, such a note stays the target (no copy) when there is no identity conflict and the source has no copy of it yet. An existing copy (`scopedVariantNoteId` or the legacy id) stays the target, so this pass agrees with reconciliation and the prompt. 2. `S/extraction/evidence-unit-compiler.ts`: changes to a note the source may not update are never low risk. They are raised to `medium`, so low-risk auto-apply (API `applyLowRisk`, `S/extraction/source-processing.ts:420`) skips them. 3. `S/drafts/draft-projector.ts:249`: project shared targets, so Review can show the before and after. 4. `S/drafts/reconciliation.ts`, three changes: - `preflight` takes the ids the caller named: `mutationIds`, or all ids when none are given, or `null` for auto-apply. It admits a shared target only when every mutation on it is named, so auto-apply and auto-included rows fail closed. - `preflightLongTermMemoryDraft` passes its selected ids, so Review shows such a row as blocked. - `applyInner`'s event auto-include skips shared events: their changes wait for their own rows. 5. `S/drafts/draft-review.ts`: add a `shared_memory_update` warning to every Review row on a shared memory. It is read at review time, so a memory shared after extraction also shows the warning. `C/review/ReviewQueue.tsx:1788-1798` already shows row diagnostics. The client already names the grounding `add_link` row and the event create that go with a selected row (`C/review/review-state.ts:175`), so normal Review accepts are not blocked. Unchanged: - Creates still fork (`remapDraftCreatesForProjection`, `S/extraction/source-extraction.ts:153`). - The model's prompt still lists only memories the source may update (`source-extraction.ts:351`). - Global memories and other chats' memories still fork. - `note-fork-repair` never merges a copy into a memory with different availability. **CHANGELOG** (user-visible), five points: - When a chat adds to a memory you shared with a character or persona, Review offers the change on that memory. Before, extraction silently made a private copy. - Only rows you select are written. - Rejecting means the chat no longer keeps that fact as a memory; it stays in the chat summary. - Memories from before 1.3.14 that picked up a character or group count as shared. - A chat's existing copy keeps updating until you delete it. ## Regression proof Write first; it must fail on the current code. 1. `tests/long-term-memory-delta-review.regression.ts`, after the `canUpdateLtmScopedTarget` cases (`:74`): truth table for `isSharedLtmScopedTarget`. - chat + character, or a legacy chats + group scope, over its own chat: true. - Another chat's memory, the same chat-only scope, or a global memory: false. 2. `tests/long-term-memory-extraction-graph.regression.ts`, end to end after the event-shaped review block (`:1176`). Setup: a chat-only source, and a world memory from that chat shared with a character. The model fixture returns new evidence for that memory, and `processLongTermMemorySource` runs with `applyLowRisk: true`. - No copy is created, and the memory's changes are in the draft with no low-risk mutation. - Nothing is auto-applied, the draft stays pending and the memory is unchanged. - Every Review row on it carries `shared_memory_update`. - Backstop: with the stored risks forced to low, low-risk auto-apply rejects with "belongs to another scope", and the memory stays unchanged. - With the memory moved to another chat's scope, a reviewed apply rejects. - A Review accept applies the changes, and the memory keeps its character. - A chat memory's static link to a shared event is accepted alone: the link applies, and the event's pending change does not. The same link as a change claim rejects, and the event stays unchanged. - A change on the shared memory, selected without its grounding link: preflight blocks it and apply rejects. Selecting both applies. 3. Same file, the scoped-target cases (`:1983-1996`). - The existing case "chat-only evidence forks instead of updating a persona-visible memory" now expects the memory (a legacy broad scope) as the target. - New: a chat's existing copy stays the target. - New: a memory from another chat with the same character still forks. ## Environment - Marinara Engine version: 2.5.1 (`staging` 87d1ccadc) - Package version: long-term-memory 1.4.69 (`upstream/staging` 5984f0784) - Install type: source (code reading; counts from private harness runs and a private vault copy) - OS + version: not platform-specific - Browser or app shell: any ## Logs, screenshots, or video None. The counts come from private harness runs and a private vault copy, so only aggregates are shared. ## Additional context Tracker item EX-I14, found in the T6 harness runs. Related: #1028 and #1037 (LTM 1.3.14). ## 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-22 04:02:49 +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#1510
No description provided.