[GH-ISSUE #1515] [Issue]: Long-Term Memory: a relationship or character change links to an unrelated event whose id appears inside a word of its cause or text #1502

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

Originally assigned to: @Promansis on GitHub.

Summary

When a structured chat summary gives a relationship change's cause in words (caused_by: the training), extraction looks for a matching event among the events in the answer and the existing timeline notes recalled for the source. That match compares ids as plain substrings. An event whose id is a short word such as rain, ash or ball matches any cause that contains those letters ("the training", "after the crash", "the football match"), and the relationship links to the wrong event. The reverse also happens: a short cause such as rain, fire or time matches inside a longer id (training_session, fireworks_show, or the timeline_ prefix that every event id carries).

Events extracted from a chat summary are stored with a per-source hash at the end of their id (timeline_rain_8d767c3b79). Such an id never fits inside a word of the cause, so for those stored events only the reverse direction goes wrong (a short cause such as rain, fire, time or line inside the longer id). The short-id-inside-a-word case, and the tie below, hit the events in the same answer (matched before the hash is added) and stored events without the hash, such as events from a lorebook source.

A wrong match can also cost a right one. When a cause names an event in words and a shorter event id also appears inside one of the cause's words, both score as full matches, the tie rule discards both, and the relationship gets a new invented event instead of the one it named.

With the structured-summary backfill fix, character lines resolve their causes through the same matcher, so they are affected in the same way.

A second check has the same flaw. When a character line gives no cause (caused_by: none), extraction looks for one of the event ids the summary declares inside the whole line, again as a plain substring, and links the fact to it when exactly one is found. art_show is found inside "will start showing", so a change about Mara starting to show her students a script links to an art show. With the structured-summary backfill fix, the same check also runs for a change fact whose written cause matches no event.

Affected package

long-term-memory 1.4.55 (upstream/staging 8b72729f1).

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

Expected behavior

An event id matches a cause only on whole words, and the id's last word may be plural. "the training session" and "the training sessions" still link to timeline_training_session, and "the rain" still links to timeline_rain, but "the training" does not link to timeline_rain, "rain" does not link to timeline_training_session, and a bare cause time or timeline does not link to whatever event happens to be in the list. A character line names a declared event only when the event's id appears in it as whole words.

A relationship change linked to an event from another source is still dropped afterwards, because a change must link to an event from the same source. That rule is not part of this issue.

Actual behavior

  • resolveStructuredCauseTarget (S/extraction/structured-summary-normalizer.ts:881) builds the candidates from the answer's events and the existing timeline notes (timelineTargetCandidates, :930-948; the notes come from getExistingTypedNotes, S/extraction/source-extraction.ts:484). It tries an exact id (exactTargetFromCauseValue, :950), then fuzzyTimelineTargetFromCause (:961-989), and when nothing matches it creates a new event for the relationship (:913-927).
  • The exact match compares whole ids, so it is not affected.
  • fuzzyTimelineTargetFromCause scores a candidate as a full match (:968-972) when the cause's identifier is a substring of <subject id>_<target id> (for example rain_timeline_rain), or when the candidate's subject id is a substring of the cause's identifier. Neither check looks at word boundaries, and the target id adds the word timeline to every candidate.
  • Two full matches for different events are a tie, and the tie rule (:987) returns no match.
  • exactTimelineTargetFromLine (:1621-1633) is the fallback for a character line without a cause (:1295-1303). It tests each declared event id, and timeline_<id>, as a substring of the whole normalized line.

Probe on the patch base, one existing timeline note per row unless stated (relationship line and character line give the same result). The last column says whether the same wrong result happens when the stored event's id carries the per-source hash:

Cause Existing event(s) Links to today Expected With a hashed id
the training timeline_rain timeline_rain no match no
after the crash timeline_ash timeline_ash no match no
the football match timeline_ball timeline_ball no match no
rain timeline_training_session timeline_training_session no match yes
fire timeline_fireworks_show timeline_fireworks_show no match yes
time / line / timeline timeline_rain or timeline_harbor_fire that event no match yes
the training session timeline_rain and timeline_training_session none (tie); the relationship gets a new event timeline_training_session no (links today)

"No match" means the relationship gets its own new event, as it does today for a cause that matches nothing, and the character fact keeps no link.

Line fallback, with the declared events art_show ("Mara exhibited her paintings at the harbor hall.") and market_fire ("The market burned down.") both in the answer:

Character line Links to today Expected
- Mara | section: developments | text: Mara will start showing her students the old script. | caused_by: none the art show event, kept after compile no link
the same with "begin showing" no link no link

How often this happens in real vaults was not measured. It needs an answered or stored event with a short id that occurs inside a word of the cause or line, or a short cause word inside an event id.

Steps to reproduce

  1. Call normalizeStructuredSummaryEvidenceUnits in roleplay mode with this source text and an existing timeline note timeline_rain ("It rained over the harbor all night."; an id without the per-source hash, as a lorebook event has) in existingNotes:

    ## relationship_state
    - alice_rowan | text: Alice and Rowan trust each other again. | caused_by: the training
    
  2. The relationship unit's caused_by link targets timeline_rain.

  3. Add a second existing note timeline_training_session and change the cause to "the long training session at the old barracks". The relationship now links to a new event (timeline_alice_rowan_long_training_session_old_barracks_…) instead of timeline_training_session.

  4. Line fallback: call it with this source text and the two events as answered timeline_event units:

    ## timeline_event
    - art_show: Mara exhibited her paintings at the harbor hall.
    - market_fire: The market burned down.
    ## character_fact
    - Mara | section: developments | text: Mara will start showing her students the old script. | caused_by: none
    

    The character fact links caused_by to the art show event, and compileEvidenceUnitExtraction keeps that link.

Minimal fix

One PR, patch bump. Only S/extraction/structured-summary-normalizer.ts.

  • fuzzyTimelineTargetFromCause: compare the cause and the candidate's subject id as whole _-separated words (both wrapped in _…_), with the same two containment checks. The id inside the cause also matches with s or es after its last word, so a plural cause still finds its event, as the substring check allowed.
  • Compare against the candidate's subject id only, not <subject id> <target id>. The target is the subject id with timeline_ in front, so it added nothing but that prefix.
  • exactTimelineTargetFromLine: look for each declared id in the line's words the same way, through one small helper shared with the cause check. timeline_<id> needs no separate test, since it holds the id as whole words.
  • The word-overlap score below the id check is unchanged; it already works on whole words.
  • CHANGELOG under ## Unreleased: "A relationship or character change from a chat summary no longer links to the wrong event because a short event name happens to sit inside a word."

Not included

  • exactTargetFromCauseValue: it compares whole ids already.
  • Events from another source. Cause matching also offers stored events from other sources; a relationship change linked to one is then dropped by the same-source rule (closeSourceEventGraph, S/extraction/evidence-unit-extraction.ts:1742-1790). That already happens today for a correct match and needs its own issue.
  • A shorter id that is a whole word of the cause still ties with the longer one ("the wedding night attack" with wedding and wedding_night_attack), as today.

Regression proof

In tests/long-term-memory-extraction-graph.regression.ts, after the structured-summary backfill's cause cases:

  • One summary with a relationship line and a character line, both with the same caused_by, normalized with existing timeline notes.
  • Neither line links to the event for: "the training" and "timeline" with timeline_rain, "rain" with timeline_training_session, "fire" with timeline_fireworks_show. Fails today on the first cause.
  • Guard: "the long training session at the old barracks" with timeline_rain and timeline_training_session links both lines to timeline_training_session. Fails today (tie, so a new event and no link). The cause has too many other words for the word-overlap score, so only the id check can find this match; a fix that compares whole ids only fails it.
  • Guard: "the training sessions" with timeline_training_session links both lines to it. Passes today; a whole-word fix without the plural fails it.
  • A change fact "Mara will start showing her students the old script." whose cause matches no event, with art_show and market_fire declared and answered, gets no link. Fails on top of the structured-summary backfill fix (it links to the art show event).

Environment

  • Marinara Engine version: 2.5.0 line (staging 2039583ca)
  • Package version: long-term-memory 1.4.55 (upstream/staging 8b72729f1)
  • Install type: source (code reading and a local probe)
  • OS + version: not platform-specific
  • Browser or app shell: any

Logs, screenshots, or video

None. The tables above come from calling the normalizer directly with made-up notes; the line fallback case also through compileEvidenceUnitExtraction.

Additional context

Tracker item OT-5. Found while fixing the structured-summary backfill (EX-I11a), which must land first. The line fallback case was found in review of the prepared fix.

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/1515 Originally assigned to: @Promansis on GitHub. ## Summary When a structured chat summary gives a relationship change's cause in words (`caused_by: the training`), extraction looks for a matching event among the events in the answer and the existing timeline notes recalled for the source. That match compares ids as plain substrings. An event whose id is a short word such as `rain`, `ash` or `ball` matches any cause that contains those letters ("the training", "after the crash", "the football match"), and the relationship links to the wrong event. The reverse also happens: a short cause such as `rain`, `fire` or `time` matches inside a longer id (`training_session`, `fireworks_show`, or the `timeline_` prefix that every event id carries). Events extracted from a chat summary are stored with a per-source hash at the end of their id (`timeline_rain_8d767c3b79`). Such an id never fits inside a word of the cause, so for those stored events only the reverse direction goes wrong (a short cause such as `rain`, `fire`, `time` or `line` inside the longer id). The short-id-inside-a-word case, and the tie below, hit the events in the same answer (matched before the hash is added) and stored events without the hash, such as events from a lorebook source. A wrong match can also cost a right one. When a cause names an event in words and a shorter event id also appears inside one of the cause's words, both score as full matches, the tie rule discards both, and the relationship gets a new invented event instead of the one it named. With the structured-summary backfill fix, character lines resolve their causes through the same matcher, so they are affected in the same way. A second check has the same flaw. When a character line gives no cause (`caused_by: none`), extraction looks for one of the event ids the summary declares inside the whole line, again as a plain substring, and links the fact to it when exactly one is found. `art_show` is found inside "will st**art show**ing", so a change about Mara starting to show her students a script links to an art show. With the structured-summary backfill fix, the same check also runs for a change fact whose written cause matches no event. ## Affected package `long-term-memory` 1.4.55 (`upstream/staging` 8b72729f1). `S` = `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory` ## Expected behavior An event id matches a cause only on whole words, and the id's last word may be plural. "the training session" and "the training sessions" still link to `timeline_training_session`, and "the rain" still links to `timeline_rain`, but "the training" does not link to `timeline_rain`, "rain" does not link to `timeline_training_session`, and a bare cause `time` or `timeline` does not link to whatever event happens to be in the list. A character line names a declared event only when the event's id appears in it as whole words. A relationship change linked to an event from another source is still dropped afterwards, because a change must link to an event from the same source. That rule is not part of this issue. ## Actual behavior - `resolveStructuredCauseTarget` (`S/extraction/structured-summary-normalizer.ts:881`) builds the candidates from the answer's events and the existing timeline notes (`timelineTargetCandidates`, `:930-948`; the notes come from `getExistingTypedNotes`, `S/extraction/source-extraction.ts:484`). It tries an exact id (`exactTargetFromCauseValue`, `:950`), then `fuzzyTimelineTargetFromCause` (`:961-989`), and when nothing matches it creates a new event for the relationship (`:913-927`). - The exact match compares whole ids, so it is not affected. - `fuzzyTimelineTargetFromCause` scores a candidate as a full match (`:968-972`) when the cause's identifier is a substring of `<subject id>_<target id>` (for example `rain_timeline_rain`), or when the candidate's subject id is a substring of the cause's identifier. Neither check looks at word boundaries, and the target id adds the word `timeline` to every candidate. - Two full matches for different events are a tie, and the tie rule (`:987`) returns no match. - `exactTimelineTargetFromLine` (`:1621-1633`) is the fallback for a character line without a cause (`:1295-1303`). It tests each declared event id, and `timeline_<id>`, as a substring of the whole normalized line. Probe on the patch base, one existing timeline note per row unless stated (relationship line and character line give the same result). The last column says whether the same wrong result happens when the stored event's id carries the per-source hash: | Cause | Existing event(s) | Links to today | Expected | With a hashed id | |---|---|---|---|---| | the training | `timeline_rain` | `timeline_rain` | no match | no | | after the crash | `timeline_ash` | `timeline_ash` | no match | no | | the football match | `timeline_ball` | `timeline_ball` | no match | no | | rain | `timeline_training_session` | `timeline_training_session` | no match | yes | | fire | `timeline_fireworks_show` | `timeline_fireworks_show` | no match | yes | | time / line / timeline | `timeline_rain` or `timeline_harbor_fire` | that event | no match | yes | | the training session | `timeline_rain` and `timeline_training_session` | none (tie); the relationship gets a new event | `timeline_training_session` | no (links today) | "No match" means the relationship gets its own new event, as it does today for a cause that matches nothing, and the character fact keeps no link. Line fallback, with the declared events `art_show` ("Mara exhibited her paintings at the harbor hall.") and `market_fire` ("The market burned down.") both in the answer: | Character line | Links to today | Expected | |---|---|---| | `- Mara \| section: developments \| text: Mara will start showing her students the old script. \| caused_by: none` | the art show event, kept after compile | no link | | the same with "begin showing" | no link | no link | How often this happens in real vaults was not measured. It needs an answered or stored event with a short id that occurs inside a word of the cause or line, or a short cause word inside an event id. ## Steps to reproduce 1. Call `normalizeStructuredSummaryEvidenceUnits` in roleplay mode with this source text and an existing timeline note `timeline_rain` ("It rained over the harbor all night."; an id without the per-source hash, as a lorebook event has) in `existingNotes`: ``` ## relationship_state - alice_rowan | text: Alice and Rowan trust each other again. | caused_by: the training ``` 2. The relationship unit's `caused_by` link targets `timeline_rain`. 3. Add a second existing note `timeline_training_session` and change the cause to "the long training session at the old barracks". The relationship now links to a new event (`timeline_alice_rowan_long_training_session_old_barracks_…`) instead of `timeline_training_session`. 4. Line fallback: call it with this source text and the two events as answered `timeline_event` units: ``` ## timeline_event - art_show: Mara exhibited her paintings at the harbor hall. - market_fire: The market burned down. ## character_fact - Mara | section: developments | text: Mara will start showing her students the old script. | caused_by: none ``` The character fact links `caused_by` to the art show event, and `compileEvidenceUnitExtraction` keeps that link. ## Minimal fix One PR, patch bump. Only `S/extraction/structured-summary-normalizer.ts`. - `fuzzyTimelineTargetFromCause`: compare the cause and the candidate's subject id as whole `_`-separated words (both wrapped in `_…_`), with the same two containment checks. The id inside the cause also matches with `s` or `es` after its last word, so a plural cause still finds its event, as the substring check allowed. - Compare against the candidate's subject id only, not `<subject id> <target id>`. The target is the subject id with `timeline_` in front, so it added nothing but that prefix. - `exactTimelineTargetFromLine`: look for each declared id in the line's words the same way, through one small helper shared with the cause check. `timeline_<id>` needs no separate test, since it holds the id as whole words. - The word-overlap score below the id check is unchanged; it already works on whole words. - **CHANGELOG under `## Unreleased`**: "A relationship or character change from a chat summary no longer links to the wrong event because a short event name happens to sit inside a word." **Not included** - `exactTargetFromCauseValue`: it compares whole ids already. - Events from another source. Cause matching also offers stored events from other sources; a relationship change linked to one is then dropped by the same-source rule (`closeSourceEventGraph`, `S/extraction/evidence-unit-extraction.ts:1742-1790`). That already happens today for a correct match and needs its own issue. - A shorter id that is a whole word of the cause still ties with the longer one ("the wedding night attack" with `wedding` and `wedding_night_attack`), as today. ## Regression proof In `tests/long-term-memory-extraction-graph.regression.ts`, after the structured-summary backfill's cause cases: - One summary with a relationship line and a character line, both with the same `caused_by`, normalized with existing timeline notes. - Neither line links to the event for: "the training" and "timeline" with `timeline_rain`, "rain" with `timeline_training_session`, "fire" with `timeline_fireworks_show`. Fails today on the first cause. - Guard: "the long training session at the old barracks" with `timeline_rain` and `timeline_training_session` links both lines to `timeline_training_session`. Fails today (tie, so a new event and no link). The cause has too many other words for the word-overlap score, so only the id check can find this match; a fix that compares whole ids only fails it. - Guard: "the training sessions" with `timeline_training_session` links both lines to it. Passes today; a whole-word fix without the plural fails it. - A change fact "Mara will start showing her students the old script." whose cause matches no event, with `art_show` and `market_fire` declared and answered, gets no link. Fails on top of the structured-summary backfill fix (it links to the art show event). ## Environment - Marinara Engine version: 2.5.0 line (`staging` 2039583ca) - Package version: long-term-memory 1.4.55 (`upstream/staging` 8b72729f1) - Install type: source (code reading and a local probe) - OS + version: not platform-specific - Browser or app shell: any ## Logs, screenshots, or video None. The tables above come from calling the normalizer directly with made-up notes; the line fallback case also through `compileEvidenceUnitExtraction`. ## Additional context Tracker item OT-5. Found while fixing the structured-summary backfill (EX-I11a), which must land first. The line fallback case was found in review of the prepared fix. ## 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:44 +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#1502
No description provided.