[GH-ISSUE #1505] [Issue]: Long-Term Memory: the structured-summary backfill drops character facts whose cause is written in words #1496

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

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

Originally assigned to: @Promansis on GitHub.

Summary

When a chat summary uses the structured format, the server adds the character facts the model missed from the summary's character_fact section (the backfill). If one of those lines has a cause or evidence field written in words, for example caused_by: the night lesson, the server turns the words into an event id (timeline_the_night_lesson) without checking that any event has that id. None does, so validation drops the fact the server has just added. The extraction then reports a partial success with "Dropped a candidate that linked to a memory this extraction could not find or did not keep", although the model never wrote that link.

Relationship lines with the same field already go through a resolver. It matches the words to an event in the answer or the vault, and adds an event if none matches. Character lines skip that resolver.

In the live runs these are most of the "could not find" drops: up to 3 lost facts per run with today's code, on both models and in every prompt variant.

Affected package

Re-checked 2026-10-21 at upstream/staging edb9c4928 (long-term-memory 1.4.57, built on the Engine's host, capability API 1.341): the fix applies unchanged there; line numbers are at the commit named below.

long-term-memory 1.4.54 (upstream/staging b1873710f). The same at #1473 head c4b1c0192, which doesn't change structured-summary-normalizer.ts or evidence-unit-validation.ts.

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

Expected behavior

  • A fact the server adds from the summary follows the server's own link rule (S/extraction/evidence-unit-extraction.ts:87): it links only to an event in the same answer or a note the extraction already holds.
  • A static fact whose cause can't be matched is kept without that link. Static units need no event link (:88).
  • A cause or evidence value given as the id of a note the extraction holds (the source note included) links to that note.

Actual behavior

  • parseStructuredCharacterLine (S/extraction/structured-summary-normalizer.ts:1183) reads a cause or evidence field at :1256-1264. timelineLinkFromValue (:1588) calls timelineTargetFromValue (:1593-1600), which turns any non-empty value into timeline_<words>. Nothing checks that id against the answer's events, the summary's own event ids (hints.eventIds) or the existing notes.
  • characterTimelineRelation (:1639-1645) keeps caused_by for developments and progression and turns it into evidenced_by for every other section.
  • maybeAddStructuredCharacterUnits (:1132) appends the unit when the model's answer doesn't already cover the fact. normalizeStructuredSummaryEvidenceUnits doesn't give it existingNotes (:262-271).
  • The relationship path handles the same field properly. maybeAddStructuredRelationshipUnits (:642) calls resolveStructuredCauseTarget (:881-928). That tries an exact id (exactTargetFromCauseValue, :950), then a word match (fuzzyTimelineTargetFromCause, :961) over the answer's events and the existing notes (timelineTargetCandidates, :930), then adds an event (structuredCauseTimelineUnit, :991).
  • linkTargetDiagnostics (S/extraction/evidence-unit-validation.ts:676-697) drops the added fact as unknown_link_target at validationStage: "initial".
  • The backfill runs on every extraction of a structured summary. The first-pass call (S/extraction/source-extraction.ts:554-565) uses the default addStructuredUnits = true (:210). See the PL-3 correction in the hygiene issue (RT-4, RT-8, RS-4, PL-3).

Measurement

T6 harness on a private 15-source vault copy (private harness, real prepareLongTermMemorySource, responses cached). Models claude-haiku-5-5 and claude-sonnet-5-5 through claude -p. These are Claude models only, not every provider people use. Only aggregate counts are shared.

Drops for a link target the extraction "could not find", per run, split by where the link came from:

Runs All such drops Added from the summary Source note link Other
today, Haiku (5 runs) 2 / 4 / 3 / 3 / 0 2 / 2 / 3 / 3 / 0 0 / 0 / 0 / 0 / 0 0 / 2 / 0 / 0 / 0
today, Sonnet (2 runs) 3 / 3 3 / 3 0 / 0 0 / 0
pre-#1417, Haiku / Sonnet 2 / 2 2 / 2 0 / 0 0 / 0
EX-I5 reduced, Haiku / Sonnet 0 / 4 0 / 4 0 / 0 0 / 0
EX-I5 reduced2, Haiku a / b, Sonnet 2 / 11 / 2 2 / 0 / 2 0 / 2 / 0 0 / 9 / 0
EX-I5 reduced3, Haiku (6 runs) 4 / 3 / 3 / 2 / 1 / 2 1 / 3 / 2 / 2 / 0 / 1 0 / 0 / 1 / 0 / 1 / 1 3 / 0 / 0 / 0 / 0 / 0
EX-I5 reduced3, Sonnet 3 2 1 0
  • With today's code, 16 of the 18 such drops in seven runs are facts the server added from the summary. The other two are anchors that link to a summary event the answer left out, the model miss that EX-I11's decision D covers.
  • Every drop in the "summary" column is a fact the model did not return, because the backfill skips facts the answer already covers. Each one is lost.
  • They come from four summary lines in two sources. In one source, three character_fact lines give their cause in words. In the other, one line names an event id that no source in the vault has.
  • Source note links are 0 with today's prompt and 6 across the ten reduced2/reduced3 runs. The EX-I5 wording drops the long link descriptions, and models then sometimes cite the source note with evidenced_by instead of extracted_from.
  • "Other" in the EX-I5 rows: 9 in reduced2 Haiku b come from events rejected for a missing sectionKey, and 3 in reduced3 Haiku a are anchors like the two above.

Steps to reproduce

  1. Use a roleplay chat summary in the structured format. Give it a ## timeline_event section and a ## character_fact line such as - Mara | sectionKey: facts | Learned the observatory script. | caused_by: the night lesson.
  2. Extract it with a model whose answer leaves that fact out.
  3. The draft's diagnostics show unknown_link_target with details.linkTarget: "timeline_the_night_lesson" on a unit the server added.

Minimal fix

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

  • maybeAddStructuredCharacterUnits (:1132): pass in existingNotes from :262. For each cause or evidence value on a character line, resolve it the way relationships do: exactTargetFromCauseValue, then fuzzyTimelineTargetFromCause, over timelineTargetCandidates(next, existingNotes). Hand that resolver to parseStructuredCharacterLine in options and call it in place of timelineLinkFromValue at :1258.
  • When nothing matches on a developments or progression line, use the existing fallback (deriveTimelineLinkForStructuredCharacter, :1602: an event id named in the line, or the only event), but keep its link only when the extraction holds that event. On any other line leave the link out. (The fallback can pick an event the summary declares in ## timeline_event even when the model left that event out, which would drop the fact again as unknown_link_target. Values that are empty, such as caused_by: none, keep today's fallback.)
  • An exact id the extraction holds (the source note, an existing note, or a note from the same answer) keeps its link, the same target set validation uses.
    • A static fact without a link is valid and is kept.
    • A change fact still without an event is dropped by closeSourceEventGraph (S/extraction/evidence-unit-extraction.ts:1742) as source_event_graph_open, which names the real problem.
    • Don't add an event the way the relationship path does. Most of these lines are static facts. A character's "because of" field is supporting detail, not a story beat of its own.
  • Each unit the backfill adds joins the set of held targets, so a later line can name it, as it can a unit from the answer.
  • CHANGELOG under ## Unreleased: "Memories added from a structured chat summary are no longer dropped when their 'because of' note doesn't match an event."

Not included

  • Model links to the source note by its bare id (the "Source note link" column above: none today, a few with the EX-I5 wording). Raw parsing turns them into timeline_source_… before the normalizer runs (normalizeRawLinkTarget, S/extraction/evidence-unit-extraction.ts:884: only source_note:<id> or an id from the answer passes unchanged), so a fix in the normalizer never sees them. (Tracked as OT-7, the bare source note link issue, to file before or with the extraction-envelope issue (EX-I5), whose wording makes these links more likely.)

  • Tightening the word matcher. It accepts a cause that contains an event's subject id as a substring, with no word boundary, and the same matcher serves relationship causes. Suggest a separate issue for both paths.

  • Adding the events a summary declares but the model left out. When the model skips such an event, its own anchors that point at it are dropped. That is the case decision D on EX-I11 covers with the EX-I5 prompt rule, not a server link loss.

  • Looking up link targets in the whole vault (EX-I11 option B, rejected).

Regression proof

Write first; it must fail on the current code.

In tests/long-term-memory-extraction-graph.regression.ts, next to the structured character cases (:586-616, :648). Use the file's compile helper (:102) with skipStructuredBackfill = false so the backfill runs through validation. Validation drops appear in compile().diagnostics as candidate_dropped_* with the validator code in details.validatorCode, so check both. Keep the fact text static: Learned the … matches CHARACTER_DEVELOPMENT_PATTERN and becomes a developments fact.

  • A facts line with caused_by: the night lesson, no matching event and units: []. Expect the added fact to be kept with no timeline_the_night_lesson link, and no unknown_link_target. It fails today.
  • The same line with a timeline unit night_lesson in the answer. Expect the link to resolve to that event's note id after the source suffix. It fails today, because the words don't equal the id.
  • A developments line whose cause matches nothing. Expect no timeline_<words> link. If the unit is dropped, the code is source_event_graph_open.
  • A guard: a line with caused_by: night_lesson and an event night_lesson keeps today's link. It passes today.
  • A cause in words that matches a timeline note already in the vault (existingNotes). Expect the link to that note. It fails today.
  • A character line with evidenced_by: <source note id>. Expect the link to the source note. It fails today.
  • A summary that declares market_fire in ## timeline_event, an answer without that event, and a developments line whose cause matches nothing. Expect source_event_graph_open and no unknown_link_target.

Environment

  • Marinara Engine version: 2.5.0 line (staging 2039583ca)
  • Package version: long-term-memory 1.4.54 (upstream/staging b1873710f)
  • Install type: source (code reading; live counts from a private vault copy)
  • OS + version: not platform-specific
  • Browser or app shell: any

Logs, screenshots, or video

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

Additional context

Tracker item EX-I11a (split from EX-I11; found by the T6 live extraction runs). Related: the bare source note link issue (OT-7) and the extraction-envelope issue (EX-I5).

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 20, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1505 Originally assigned to: @Promansis on GitHub. ## Summary When a chat summary uses the structured format, the server adds the character facts the model missed from the summary's `character_fact` section (the backfill). If one of those lines has a cause or evidence field written in words, for example `caused_by: the night lesson`, the server turns the words into an event id (`timeline_the_night_lesson`) without checking that any event has that id. None does, so validation drops the fact the server has just added. The extraction then reports a partial success with "Dropped a candidate that linked to a memory this extraction could not find or did not keep", although the model never wrote that link. Relationship lines with the same field already go through a resolver. It matches the words to an event in the answer or the vault, and adds an event if none matches. Character lines skip that resolver. In the live runs these are most of the "could not find" drops: up to 3 lost facts per run with today's code, on both models and in every prompt variant. ## Affected package Re-checked 2026-10-21 at `upstream/staging` edb9c4928 (long-term-memory 1.4.57, built on the Engine's host, capability API 1.341): the fix applies unchanged there; line numbers are at the commit named below. `long-term-memory` 1.4.54 (`upstream/staging` b1873710f). The same at #1473 head c4b1c0192, which doesn't change `structured-summary-normalizer.ts` or `evidence-unit-validation.ts`. `S` = `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory` ## Expected behavior - A fact the server adds from the summary follows the server's own link rule (`S/extraction/evidence-unit-extraction.ts:87`): it links only to an event in the same answer or a note the extraction already holds. - A static fact whose cause can't be matched is kept without that link. Static units need no event link (`:88`). - A cause or evidence value given as the id of a note the extraction holds (the source note included) links to that note. ## Actual behavior - `parseStructuredCharacterLine` (`S/extraction/structured-summary-normalizer.ts:1183`) reads a cause or evidence field at `:1256-1264`. `timelineLinkFromValue` (`:1588`) calls `timelineTargetFromValue` (`:1593-1600`), which turns any non-empty value into `timeline_<words>`. Nothing checks that id against the answer's events, the summary's own event ids (`hints.eventIds`) or the existing notes. - `characterTimelineRelation` (`:1639-1645`) keeps `caused_by` for `developments` and `progression` and turns it into `evidenced_by` for every other section. - `maybeAddStructuredCharacterUnits` (`:1132`) appends the unit when the model's answer doesn't already cover the fact. `normalizeStructuredSummaryEvidenceUnits` doesn't give it `existingNotes` (`:262-271`). - The relationship path handles the same field properly. `maybeAddStructuredRelationshipUnits` (`:642`) calls `resolveStructuredCauseTarget` (`:881-928`). That tries an exact id (`exactTargetFromCauseValue`, `:950`), then a word match (`fuzzyTimelineTargetFromCause`, `:961`) over the answer's events and the existing notes (`timelineTargetCandidates`, `:930`), then adds an event (`structuredCauseTimelineUnit`, `:991`). - `linkTargetDiagnostics` (`S/extraction/evidence-unit-validation.ts:676-697`) drops the added fact as `unknown_link_target` at `validationStage: "initial"`. - The backfill runs on every extraction of a structured summary. The first-pass call (`S/extraction/source-extraction.ts:554-565`) uses the default `addStructuredUnits = true` (`:210`). See the PL-3 correction in the hygiene issue (RT-4, RT-8, RS-4, PL-3). ### Measurement T6 harness on a private 15-source vault copy (private harness, real `prepareLongTermMemorySource`, responses cached). Models `claude-haiku-5-5` and `claude-sonnet-5-5` through `claude -p`. These are Claude models only, not every provider people use. Only aggregate counts are shared. Drops for a link target the extraction "could not find", per run, split by where the link came from: | Runs | All such drops | Added from the summary | Source note link | Other | |---|---|---|---|---| | today, Haiku (5 runs) | 2 / 4 / 3 / 3 / 0 | 2 / 2 / 3 / 3 / 0 | 0 / 0 / 0 / 0 / 0 | 0 / 2 / 0 / 0 / 0 | | today, Sonnet (2 runs) | 3 / 3 | 3 / 3 | 0 / 0 | 0 / 0 | | pre-#1417, Haiku / Sonnet | 2 / 2 | 2 / 2 | 0 / 0 | 0 / 0 | | EX-I5 `reduced`, Haiku / Sonnet | 0 / 4 | 0 / 4 | 0 / 0 | 0 / 0 | | EX-I5 `reduced2`, Haiku a / b, Sonnet | 2 / 11 / 2 | 2 / 0 / 2 | 0 / 2 / 0 | 0 / 9 / 0 | | EX-I5 `reduced3`, Haiku (6 runs) | 4 / 3 / 3 / 2 / 1 / 2 | 1 / 3 / 2 / 2 / 0 / 1 | 0 / 0 / 1 / 0 / 1 / 1 | 3 / 0 / 0 / 0 / 0 / 0 | | EX-I5 `reduced3`, Sonnet | 3 | 2 | 1 | 0 | - With today's code, 16 of the 18 such drops in seven runs are facts the server added from the summary. The other two are anchors that link to a summary event the answer left out, the model miss that EX-I11's decision D covers. - Every drop in the "summary" column is a fact the model did not return, because the backfill skips facts the answer already covers. Each one is lost. - They come from four summary lines in two sources. In one source, three `character_fact` lines give their cause in words. In the other, one line names an event id that no source in the vault has. - Source note links are 0 with today's prompt and 6 across the ten `reduced2`/`reduced3` runs. The EX-I5 wording drops the long link descriptions, and models then sometimes cite the source note with `evidenced_by` instead of `extracted_from`. - "Other" in the EX-I5 rows: 9 in `reduced2` Haiku b come from events rejected for a missing `sectionKey`, and 3 in `reduced3` Haiku a are anchors like the two above. ## Steps to reproduce 1. Use a roleplay chat summary in the structured format. Give it a `## timeline_event` section and a `## character_fact` line such as `- Mara | sectionKey: facts | Learned the observatory script. | caused_by: the night lesson`. 2. Extract it with a model whose answer leaves that fact out. 3. The draft's diagnostics show `unknown_link_target` with `details.linkTarget: "timeline_the_night_lesson"` on a unit the server added. ## Minimal fix One PR, patch bump. Only `S/extraction/structured-summary-normalizer.ts`. - **`maybeAddStructuredCharacterUnits` (`:1132`)**: pass in `existingNotes` from `:262`. For each cause or evidence value on a character line, resolve it the way relationships do: `exactTargetFromCauseValue`, then `fuzzyTimelineTargetFromCause`, over `timelineTargetCandidates(next, existingNotes)`. Hand that resolver to `parseStructuredCharacterLine` in `options` and call it in place of `timelineLinkFromValue` at `:1258`. - **When nothing matches** on a `developments` or `progression` line, use the existing fallback (`deriveTimelineLinkForStructuredCharacter`, `:1602`: an event id named in the line, or the only event), but keep its link only when the extraction holds that event. On any other line leave the link out. (The fallback can pick an event the summary declares in `## timeline_event` even when the model left that event out, which would drop the fact again as `unknown_link_target`. Values that are empty, such as `caused_by: none`, keep today's fallback.) - **An exact id the extraction holds** (the source note, an existing note, or a note from the same answer) keeps its link, the same target set validation uses. - A static fact without a link is valid and is kept. - A change fact still without an event is dropped by `closeSourceEventGraph` (`S/extraction/evidence-unit-extraction.ts:1742`) as `source_event_graph_open`, which names the real problem. - Don't add an event the way the relationship path does. Most of these lines are static facts. A character's "because of" field is supporting detail, not a story beat of its own. - Each unit the backfill adds joins the set of held targets, so a later line can name it, as it can a unit from the answer. - **CHANGELOG under `## Unreleased`**: "Memories added from a structured chat summary are no longer dropped when their 'because of' note doesn't match an event." **Not included** - **Model links to the source note by its bare id** (the "Source note link" column above: none today, a few with the EX-I5 wording). Raw parsing turns them into `timeline_source_…` before the normalizer runs (`normalizeRawLinkTarget`, `S/extraction/evidence-unit-extraction.ts:884`: only `source_note:<id>` or an id from the answer passes unchanged), so a fix in the normalizer never sees them. (Tracked as OT-7, the bare source note link issue, to file before or with the extraction-envelope issue (EX-I5), whose wording makes these links more likely.) - Tightening the word matcher. It accepts a cause that contains an event's subject id as a substring, with no word boundary, and the same matcher serves relationship causes. Suggest a separate issue for both paths. - Adding the events a summary declares but the model left out. When the model skips such an event, its own anchors that point at it are dropped. That is the case decision D on EX-I11 covers with the EX-I5 prompt rule, not a server link loss. - Looking up link targets in the whole vault (EX-I11 option B, rejected). ## Regression proof Write first; it must fail on the current code. In `tests/long-term-memory-extraction-graph.regression.ts`, next to the structured character cases (`:586-616`, `:648`). Use the file's `compile` helper (`:102`) with `skipStructuredBackfill = false` so the backfill runs through validation. Validation drops appear in `compile().diagnostics` as `candidate_dropped_*` with the validator code in `details.validatorCode`, so check both. Keep the fact text static: `Learned the …` matches `CHARACTER_DEVELOPMENT_PATTERN` and becomes a `developments` fact. - A `facts` line with `caused_by: the night lesson`, no matching event and `units: []`. Expect the added fact to be kept with no `timeline_the_night_lesson` link, and no `unknown_link_target`. It fails today. - The same line with a timeline unit `night_lesson` in the answer. Expect the link to resolve to that event's note id after the source suffix. It fails today, because the words don't equal the id. - A `developments` line whose cause matches nothing. Expect no `timeline_<words>` link. If the unit is dropped, the code is `source_event_graph_open`. - A guard: a line with `caused_by: night_lesson` and an event `night_lesson` keeps today's link. It passes today. - A cause in words that matches a timeline note already in the vault (`existingNotes`). Expect the link to that note. It fails today. - A character line with `evidenced_by: <source note id>`. Expect the link to the source note. It fails today. - A summary that declares `market_fire` in `## timeline_event`, an answer without that event, and a `developments` line whose cause matches nothing. Expect `source_event_graph_open` and no `unknown_link_target`. ## Environment - Marinara Engine version: 2.5.0 line (`staging` 2039583ca) - Package version: long-term-memory 1.4.54 (`upstream/staging` b1873710f) - Install type: source (code reading; live counts from a private vault copy) - OS + version: not platform-specific - Browser or app shell: any ## Logs, screenshots, or video None. The counts come from a private vault copy, so only aggregates are shared. ## Additional context Tracker item EX-I11a (split from EX-I11; found by the T6 live extraction runs). Related: the bare source note link issue (OT-7) and the extraction-envelope issue (EX-I5). ## 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:41 +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#1496
No description provided.