[GH-ISSUE #1543] [Issue]: Long-Term Memory: a name starting with Char, or a relationship slug starting with rel_, gets a second memory #1515

Closed
opened 2026-10-22 04:02:52 +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/1543

Originally assigned to: @Promansis on GitHub.

Summary

A character whose name starts with "Char", such as "Char Aznable", gets the memory id char_char_aznable from identity, because the id is always char_ plus the name. Identity then hands the extracted fact a subject id with the prefix removed once, char_aznable, and turning that back into a note id keeps it as char_aznable, because it already starts with char_. So the fact is saved to char_aznable, a different memory from the one identity chose. Relationships whose first name starts with "Rel" go the same way (rel_rel_varga_sayla_mass becomes rel_varga_sayla_mass).

What users see:

  • Events about the character are dropped as "linked to a memory this extraction could not find", because identity points event links at char_char_aznable, which the draft never creates.
  • When a memory with the full id already exists, extraction proposes a second memory for the same character instead of updating it. Once both are kept and bound to the character, later extractions stop as ambiguous identity in Review.

Affected package

long-term-memory 1.4.72 (upstream/staging bcaebd07d) with the #1534 fix (PR #1540, 1.4.73). Line numbers below are on that tree (refreshed 2026-10-21; first checked on 8b72729f1).

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

Expected behavior

Facts about a character or relationship are saved to the memory identity chose for it, whatever the name's first word. Events about it keep their link.

Actual behavior

  • canonicalNoteIdForEntries (S/identity/subject-identity.ts:2542-2553) builds ${prefix}_${slugs}, so "Char Aznable" is char_char_aznable.
  • subjectIdForTarget (:2555-2558) removes char_ or rel_ once: char_aznable. It is called for every resolved unit (:1433) and for source-backed characters (:1356).
  • noteIdForEvidenceUnit → prefixed() (S/extraction/evidence-unit-validation.ts:748-756, :767-769) keeps a subject id that already starts with the prefix, so the unit's note is char_aznable.
  • The structured-summary normalizer removes the prefix once more on the compile pass (stripUnitSubjectPrefix, S/extraction/structured-summary-normalizer.ts:1774-1777, called at :328, :541, :566), so a value that survived identity still loses the word there.
  • resolveIdentityLinkTarget (S/identity/subject-identity.ts:2496-2515) resolves an affects_character link to the chosen memory, or to canonicalNoteIdForEntries when there is none yet (:2514): char_char_aznable. linkTargetDiagnostics (S/extraction/evidence-unit-validation.ts:676-697) then drops the event with unknown_link_target and details.linkTarget: "char_char_aznable".
  • Identity's own diagnostic says what it meant to do: subject_identity_normalized with originalNoteId: "char_aznable" and targetNoteId: "char_char_aznable", while the draft creates char_aznable.
  • The same happens to any memory identity chooses whose id already repeats its prefix, whatever the name. A memory char_char_mara bound to Mara (for example from an import) gets its facts split into a new char_mara; a bound rel_rel_ana_bo gets a new rel_ana_bo.
  • Ordinary names with ordinary ids are not affected: "Mara" with no memory yet is char_mara either way.

Steps to reproduce

  1. Put a character named "Char Aznable" in the chat.
  2. Extract from a source such as "Char Aznable pilots a red mobile suit. Char Aznable defected from the fleet." The model returns a character fact with subject id char_aznable and an event linked to it with affects_character.
  3. The draft creates char_aznable, not char_char_aznable, and the event is dropped as unknown_link_target with linkTarget: "char_char_aznable".
  4. With a memory char_char_aznable already in the vault and bound to Char Aznable, the same extraction proposes a new memory char_aznable instead of appending to it.

Minimal fix

One PR, patch bump. Three source files, no new file.

  • Add unprefixedSubjectId(prefix, id) beside prefixed() in S/extraction/evidence-unit-validation.ts: remove the prefix, unless what is left starts with the prefix again, so prefixed() maps the result back to the same note.
  • Use it in subjectIdForTarget, and in the normalizer's branches that handle identity's output, for units with subjects: the character branch (:328, :566) and the relationship branch (:541). The relationship branch keeps looking summary hints up with the id stripped once, so a summary's relationship dimensions still apply.
  • The fix covers any chosen memory whose id repeats its prefix, not only names that start with "Char" or "Rel": a bound char_char_mara now receives Mara's facts instead of a new char_mara. That is an improvement, but it changes identity behaviour on existing vaults. For every other chosen id the helper returns what the one-time strip returned, so those ids do not change.
  • CHANGELOG under ## Unreleased: "Extraction now saves facts about a character whose name starts with "Char", such as "Char Aznable", or a relationship whose first name starts with "Rel", to the memory chosen for them."

Not included

  • Identity's matching keys (stripNotePrefix, subjectSlugFromNote): they pair with canonicalNoteIdForEntries and choose the same memory today; ids are never written from them.
  • Ids the model chooses (world, thread, tone, timeline, anchor, and character and relationship units before identity). Changing how those fold would split one subject across runs.
  • A migration. A memory already saved under the shortened id keeps receiving facts while it is bound to the character. A vault holding both memories needs a merge in the app.
  • A structured summary line for "Char Aznable" is read like an id by the summary backfill (aznable), so it adds a copy of the fact that identity drops as untrusted. That is the same before and after; separate issue if wanted.
  • The same misreading keys a structured character: Char Aznable / section: profile hint as aznable. Today it only matches because the fact goes to the wrong memory char_aznable; with the fix the fact goes to char_char_aznable and takes its section from the text instead. Same follow-up as the line above.

Regression proof

In tests/long-term-memory-extraction-graph.regression.ts, before the event-shaped review case: run processLongTermMemorySource with a roster of Char Aznable, Rel Varga, Sayla Mass and Mara and fixture model units (char_aznable, rel_varga_sayla_mass, mara, and an event linked to char_aznable with affects_character).

  • Empty vault, plain source: the created memories are char_char_aznable, char_mara and rel_rel_varga_sayla_mass, nothing is dropped, and the event links to char_char_aznable. It fails today: char_aznable and rel_varga_sayla_mass.
  • Vault already holding bound char_char_aznable and rel_rel_varga_sayla_mass, structured summary whose relationship section carries relationship_id: rel_varga_sayla_mass and dimensions: trust 80, and no relationship unit from the model (the summary line supplies it): only char_mara is created, the two existing memories are updated, and the relationship update carries trust: 80.

Environment

  • Marinara Engine version: 2.5.1 (staging 87d1ccadc)
  • Package version: long-term-memory 1.4.73 (upstream/staging bcaebd07d with the #1534 fix, PR #1540)
  • Install type: source (code reading and a fixture-model run through processLongTermMemorySource)
  • OS + version: not platform-specific
  • Browser or app shell: any

Logs, screenshots, or video

None. The reproduction uses fixture names, not user data.

Additional context

Tracker item OT-4. Found while fixing the recovery subjectId issue (#1534), which has landed.

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/1543 Originally assigned to: @Promansis on GitHub. ## Summary A character whose name starts with "Char", such as "Char Aznable", gets the memory id `char_char_aznable` from identity, because the id is always `char_` plus the name. Identity then hands the extracted fact a subject id with the prefix removed once, `char_aznable`, and turning that back into a note id keeps it as `char_aznable`, because it already starts with `char_`. So the fact is saved to `char_aznable`, a different memory from the one identity chose. Relationships whose first name starts with "Rel" go the same way (`rel_rel_varga_sayla_mass` becomes `rel_varga_sayla_mass`). What users see: - Events about the character are dropped as "linked to a memory this extraction could not find", because identity points event links at `char_char_aznable`, which the draft never creates. - When a memory with the full id already exists, extraction proposes a second memory for the same character instead of updating it. Once both are kept and bound to the character, later extractions stop as ambiguous identity in Review. ## Affected package `long-term-memory` 1.4.72 (`upstream/staging` bcaebd07d) with the #1534 fix (PR #1540, 1.4.73). Line numbers below are on that tree (refreshed 2026-10-21; first checked on 8b72729f1). `S` = `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory` ## Expected behavior Facts about a character or relationship are saved to the memory identity chose for it, whatever the name's first word. Events about it keep their link. ## Actual behavior - `canonicalNoteIdForEntries` (`S/identity/subject-identity.ts:2542-2553`) builds `${prefix}_${slugs}`, so "Char Aznable" is `char_char_aznable`. - `subjectIdForTarget` (`:2555-2558`) removes `char_` or `rel_` once: `char_aznable`. It is called for every resolved unit (`:1433`) and for source-backed characters (`:1356`). - `noteIdForEvidenceUnit` → `prefixed()` (`S/extraction/evidence-unit-validation.ts:748-756`, `:767-769`) keeps a subject id that already starts with the prefix, so the unit's note is `char_aznable`. - The structured-summary normalizer removes the prefix once more on the compile pass (`stripUnitSubjectPrefix`, `S/extraction/structured-summary-normalizer.ts:1774-1777`, called at `:328`, `:541`, `:566`), so a value that survived identity still loses the word there. - `resolveIdentityLinkTarget` (`S/identity/subject-identity.ts:2496-2515`) resolves an `affects_character` link to the chosen memory, or to `canonicalNoteIdForEntries` when there is none yet (`:2514`): `char_char_aznable`. `linkTargetDiagnostics` (`S/extraction/evidence-unit-validation.ts:676-697`) then drops the event with `unknown_link_target` and `details.linkTarget: "char_char_aznable"`. - Identity's own diagnostic says what it meant to do: `subject_identity_normalized` with `originalNoteId: "char_aznable"` and `targetNoteId: "char_char_aznable"`, while the draft creates `char_aznable`. - The same happens to any memory identity chooses whose id already repeats its prefix, whatever the name. A memory `char_char_mara` bound to Mara (for example from an import) gets its facts split into a new `char_mara`; a bound `rel_rel_ana_bo` gets a new `rel_ana_bo`. - Ordinary names with ordinary ids are not affected: "Mara" with no memory yet is `char_mara` either way. ## Steps to reproduce 1. Put a character named "Char Aznable" in the chat. 2. Extract from a source such as "Char Aznable pilots a red mobile suit. Char Aznable defected from the fleet." The model returns a character fact with subject id `char_aznable` and an event linked to it with `affects_character`. 3. The draft creates `char_aznable`, not `char_char_aznable`, and the event is dropped as `unknown_link_target` with `linkTarget: "char_char_aznable"`. 4. With a memory `char_char_aznable` already in the vault and bound to Char Aznable, the same extraction proposes a new memory `char_aznable` instead of appending to it. ## Minimal fix One PR, patch bump. Three source files, no new file. - Add `unprefixedSubjectId(prefix, id)` beside `prefixed()` in `S/extraction/evidence-unit-validation.ts`: remove the prefix, unless what is left starts with the prefix again, so `prefixed()` maps the result back to the same note. - Use it in `subjectIdForTarget`, and in the normalizer's branches that handle identity's output, for units with `subjects`: the character branch (`:328`, `:566`) and the relationship branch (`:541`). The relationship branch keeps looking summary hints up with the id stripped once, so a summary's relationship dimensions still apply. - The fix covers any chosen memory whose id repeats its prefix, not only names that start with "Char" or "Rel": a bound `char_char_mara` now receives Mara's facts instead of a new `char_mara`. That is an improvement, but it changes identity behaviour on existing vaults. For every other chosen id the helper returns what the one-time strip returned, so those ids do not change. - **CHANGELOG under `## Unreleased`**: "Extraction now saves facts about a character whose name starts with "Char", such as "Char Aznable", or a relationship whose first name starts with "Rel", to the memory chosen for them." **Not included** - Identity's matching keys (`stripNotePrefix`, `subjectSlugFromNote`): they pair with `canonicalNoteIdForEntries` and choose the same memory today; ids are never written from them. - Ids the model chooses (world, thread, tone, timeline, anchor, and character and relationship units before identity). Changing how those fold would split one subject across runs. - A migration. A memory already saved under the shortened id keeps receiving facts while it is bound to the character. A vault holding both memories needs a merge in the app. - A structured summary line for "Char Aznable" is read like an id by the summary backfill (`aznable`), so it adds a copy of the fact that identity drops as untrusted. That is the same before and after; separate issue if wanted. - The same misreading keys a structured `character: Char Aznable` / `section: profile` hint as `aznable`. Today it only matches because the fact goes to the wrong memory `char_aznable`; with the fix the fact goes to `char_char_aznable` and takes its section from the text instead. Same follow-up as the line above. ## Regression proof In `tests/long-term-memory-extraction-graph.regression.ts`, before the event-shaped review case: run `processLongTermMemorySource` with a roster of Char Aznable, Rel Varga, Sayla Mass and Mara and fixture model units (`char_aznable`, `rel_varga_sayla_mass`, `mara`, and an event linked to `char_aznable` with `affects_character`). - Empty vault, plain source: the created memories are `char_char_aznable`, `char_mara` and `rel_rel_varga_sayla_mass`, nothing is dropped, and the event links to `char_char_aznable`. It fails today: `char_aznable` and `rel_varga_sayla_mass`. - Vault already holding bound `char_char_aznable` and `rel_rel_varga_sayla_mass`, structured summary whose relationship section carries `relationship_id: rel_varga_sayla_mass` and `dimensions: trust 80`, and no relationship unit from the model (the summary line supplies it): only `char_mara` is created, the two existing memories are updated, and the relationship update carries `trust: 80`. ## Environment - Marinara Engine version: 2.5.1 (`staging` 87d1ccadc) - Package version: long-term-memory 1.4.73 (`upstream/staging` bcaebd07d with the #1534 fix, PR #1540) - Install type: source (code reading and a fixture-model run through `processLongTermMemorySource`) - OS + version: not platform-specific - Browser or app shell: any ## Logs, screenshots, or video None. The reproduction uses fixture names, not user data. ## Additional context Tracker item OT-4. Found while fixing the recovery subjectId issue (#1534), which has landed. ## 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:52 +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#1515
No description provided.