[GH-ISSUE #1524] [Issue]: Long-Term Memory: extraction drops a memory that cites its source by the source note id #1504

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

Originally assigned to: @Promansis on GitHub.

Summary

The extraction request tells the model it may link to the source note by its id (sourceNote.id), and asks every event to do so with extracted_from. When the model cites that id with any event relation instead, such as {"target":"source_chat_summary_…","relation":"evidenced_by"}, the server turns it into an event id that doesn't exist, timeline_source_chat_summary_…, and validation drops the whole unit as "linked to a memory this extraction could not find". Two steps do this. Raw parsing reads the bare id as an event name. And on a source whose text has section headings (## world_fact and the like), the structured-summary normalizer adds the timeline_ prefix again after raw parsing. The written-out form source_note:<id> gets past raw parsing, but on a source with headings the normalizer prefixes it too, so today it survives only on sources without headings.

In live runs with the 1.4.55 prompt it never happened. With the shorter wording that the extraction request has sent since 1.4.65 (#1517), it cost one memory in 4 of 7 runs (measured on the version of that wording planned before #1517 merged).

Affected package

long-term-memory 1.4.55 (upstream/staging 8b72729f1); line references below are on 8b72729f1. Still present on 1.4.66 (77acb942b). Since #1517 the request no longer carries the two schema descriptions quoted below, which is the shorter wording that produced the drops in the measurement.

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

Expected behavior

A link whose target is the source note's own id keeps that id, whatever the relation, whether it is written bare or as source_note:<id>, and whether or not the source has section headings. Validation then judges the link as it does today.

Actual behavior

  • The request offers the bare id: "Every link target must resolve to sourceNote.id or a target note derived from a unit in the same response", and "Every timeline_event must link to sourceNote.id with extracted_from" (S/extraction/evidence-unit-extraction.ts:87-88). The provider schema describes a link target as a note id "or the source note id" (:498), and the prompt's schema text says targets may be "copied exactly from sourceNote.id" (:1248). On 1.4.66 both schema descriptions are gone (#1517) and the two rules remain (:77-78).
  • Raw parsing: normalizeRawLinkTarget (:884-913) keeps a target unchanged only when it is written source_note:<id> (:889, :893), is a note id derived from a unit in the same answer (targetNoteIds, :896), or carries a note prefix (timeline_, thread_, world_, tone_, rel_, char_; :72, :901). Source note ids start with source_ (S/sources/source-identity.ts:13), so a bare one matches none of these. For an event relation (occurred_in, triggered_by, resolved_in, evidenced_by, caused_by, planted_in, paid_off_in; :75-83) it is then prefixed as an event (:903). For blocks it becomes a thread_ id (:904). extracted_from is not an event relation, so that one keeps the bare id, which is why most source links work.
  • Structured-summary normalizer: when the source text has section headings, normalizeStructuredSummaryEvidenceUnits (S/extraction/structured-summary-normalizer.ts:201) passes every unit through normalizeUnit (:238-242), which normalizes each link with normalizeLinkTarget (:527, :1574, :1647-1660). That keeps a target unchanged only when it carries a note prefix (NOTE_ID_PREFIX_PATTERN, :69, which has no source_), and otherwise prefixes the target of an event relation with timeline_ (:1655; relations :86-94) and of blocks with thread_ (:1656). It runs on the units raw parsing returns, in source extraction (S/extraction/source-extraction.ts:554) and again in compileEvidenceUnitExtraction (S/extraction/evidence-unit-extraction.ts:1536). Raw parsing turns source_note:<id> into the bare id (:893), so the normalizer re-prefixes that form too. Without headings (:226-235) it doesn't call normalizeLinkTarget.
  • linkTargetDiagnostics (S/extraction/evidence-unit-validation.ts:676-697) then drops the unit with unknown_link_target and details.linkTarget: "timeline_source_…".

Measurement

Live extraction runs on a private 15-source vault copy, with Claude Haiku 5.5 and Claude Sonnet 5.5 through claude -p (Claude models only). Only aggregate counts are shared.

Runs Units dropped for a bare source note link
the 1.4.55 prompt, 9 runs (both models) 0
the shorter wording, as planned for #1517, 7 runs (6 Haiku, 1 Sonnet) 4, one each in 4 runs
two earlier versions of that wording, 7 runs 5, in 3 runs

All 9 dropped units were static: 7 world_fact, 1 thread and 1 anchor. Their links to the bare source id were 8 evidenced_by and 1 planted_in (the anchor). The drops came from 4 sources, all with section headings (13 of the 15 sources have them), so fixing raw parsing alone would not have kept any of them.

Steps to reproduce

  1. Take a source note whose text has a section heading, such as ## world_fact. Call parseEvidenceUnitPayload with a static world_fact unit whose only link is { target: <source note id>, relation: "evidenced_by" }, passing source_note:<source note id> as trusted evidence, as extraction does (:1445-1450).
  2. The link's target is timeline_<source note id>. Written as source_note:<source note id>, the target parses to the bare id instead.
  3. Compile the parsed units with compileEvidenceUnitExtraction. In both forms the fact is dropped with unknown_link_target. On a source without headings only the bare form is dropped.

Minimal fix

One PR, patch bump. Two files, one guard each; both are needed.

  • Raw parsing (S/extraction/evidence-unit-extraction.ts): in normalizeEvidenceUnitResponse (:674), after the target hints are built (:686), add the id of every source_note:<id> in the trusted evidence to targetNoteIds. Extraction passes the source note's evidence as trusted evidence (evidenceFromSourceNote, :188-191), whose first entry is source_note:<source note id>, so the bare id then passes unchanged at :896, exactly as the source_note:<id> form does.
  • Normalizer (S/extraction/structured-summary-normalizer.ts): give StructuredSummaryHints (:44-51) an optional sourceNoteId, set it from sourceNote?.id where the hints are built (:238), and in normalizeLinkTarget return an identifier equal to it unchanged, beside the note-prefix check (:1654).
  • Both match the source note's exact id. Any other source_… id, or an event subject that happens to start with source_, is prefixed as today.
  • CHANGELOG under ## Unreleased: "Extraction no longer drops a memory that cites the chat summary or import it came from, for example as its evidence."

Not included

  • Accepting any source_ id. A source the extraction doesn't hold can't be a valid link target, and validation would drop it anyway.
  • Changing the request wording. It already names sourceNote.id; the server now agrees with it.

Regression proof

In tests/long-term-memory-extraction-graph.regression.ts, right after the "Source-prefixed link normalization" case (:1338-1357), which covers source_note:<id> in raw parsing:

  • A chat-summary source note whose text is a ## world_fact section. Parse two static world_fact units with source_note:<source id> as trusted evidence. The first's only link is evidenced_by to the bare source id; the second's is evidenced_by to source_chat_other_summary, a source this extraction doesn't hold.
  • Expect the second link to parse to timeline_source_chat_other_summary, so only the exact id is kept.
  • Compile both with the file's compile helper (compileEvidenceUnitExtraction, which applies the structured normalizer). Expect one unit kept, with its evidenced_by link to the source note. It fails today (none kept), and it also fails with either guard alone.

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; 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 OT-7. Found while reviewing the structured-summary backfill fix (#1505, merged as #1511). Its first version kept a bare source_ id in the summary normalizer, which on its own keeps nothing: raw parsing has already turned a bare id into timeline_source_… by then. The normalizer does receive the bare id when the model writes source_note:<id> (raw parsing unwraps it), and with this fix also when the model writes the bare id. On a source with section headings it then prefixes it again, so both places need the guard.

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/1524 Originally assigned to: @Promansis on GitHub. ## Summary The extraction request tells the model it may link to the source note by its id (`sourceNote.id`), and asks every event to do so with `extracted_from`. When the model cites that id with any event relation instead, such as `{"target":"source_chat_summary_…","relation":"evidenced_by"}`, the server turns it into an event id that doesn't exist, `timeline_source_chat_summary_…`, and validation drops the whole unit as "linked to a memory this extraction could not find". Two steps do this. Raw parsing reads the bare id as an event name. And on a source whose text has section headings (`## world_fact` and the like), the structured-summary normalizer adds the `timeline_` prefix again after raw parsing. The written-out form `source_note:<id>` gets past raw parsing, but on a source with headings the normalizer prefixes it too, so today it survives only on sources without headings. In live runs with the 1.4.55 prompt it never happened. With the shorter wording that the extraction request has sent since 1.4.65 (#1517), it cost one memory in 4 of 7 runs (measured on the version of that wording planned before #1517 merged). ## Affected package `long-term-memory` 1.4.55 (`upstream/staging` 8b72729f1); line references below are on 8b72729f1. Still present on 1.4.66 (77acb942b). Since #1517 the request no longer carries the two schema descriptions quoted below, which is the shorter wording that produced the drops in the measurement. `S` = `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory` ## Expected behavior A link whose target is the source note's own id keeps that id, whatever the relation, whether it is written bare or as `source_note:<id>`, and whether or not the source has section headings. Validation then judges the link as it does today. ## Actual behavior - The request offers the bare id: "Every link target must resolve to sourceNote.id or a target note derived from a unit in the same response", and "Every timeline_event must link to sourceNote.id with extracted_from" (`S/extraction/evidence-unit-extraction.ts:87-88`). The provider schema describes a link target as a note id "or the source note id" (`:498`), and the prompt's schema text says targets may be "copied exactly from sourceNote.id" (`:1248`). On 1.4.66 both schema descriptions are gone (#1517) and the two rules remain (`:77-78`). - Raw parsing: `normalizeRawLinkTarget` (`:884-913`) keeps a target unchanged only when it is written `source_note:<id>` (`:889`, `:893`), is a note id derived from a unit in the same answer (`targetNoteIds`, `:896`), or carries a note prefix (`timeline_`, `thread_`, `world_`, `tone_`, `rel_`, `char_`; `:72`, `:901`). Source note ids start with `source_` (`S/sources/source-identity.ts:13`), so a bare one matches none of these. For an event relation (`occurred_in`, `triggered_by`, `resolved_in`, `evidenced_by`, `caused_by`, `planted_in`, `paid_off_in`; `:75-83`) it is then prefixed as an event (`:903`). For `blocks` it becomes a `thread_` id (`:904`). `extracted_from` is not an event relation, so that one keeps the bare id, which is why most source links work. - Structured-summary normalizer: when the source text has section headings, `normalizeStructuredSummaryEvidenceUnits` (`S/extraction/structured-summary-normalizer.ts:201`) passes every unit through `normalizeUnit` (`:238-242`), which normalizes each link with `normalizeLinkTarget` (`:527`, `:1574`, `:1647-1660`). That keeps a target unchanged only when it carries a note prefix (`NOTE_ID_PREFIX_PATTERN`, `:69`, which has no `source_`), and otherwise prefixes the target of an event relation with `timeline_` (`:1655`; relations `:86-94`) and of `blocks` with `thread_` (`:1656`). It runs on the units raw parsing returns, in source extraction (`S/extraction/source-extraction.ts:554`) and again in `compileEvidenceUnitExtraction` (`S/extraction/evidence-unit-extraction.ts:1536`). Raw parsing turns `source_note:<id>` into the bare id (`:893`), so the normalizer re-prefixes that form too. Without headings (`:226-235`) it doesn't call `normalizeLinkTarget`. - `linkTargetDiagnostics` (`S/extraction/evidence-unit-validation.ts:676-697`) then drops the unit with `unknown_link_target` and `details.linkTarget: "timeline_source_…"`. ### Measurement Live extraction runs on a private 15-source vault copy, with Claude Haiku 5.5 and Claude Sonnet 5.5 through `claude -p` (Claude models only). Only aggregate counts are shared. | Runs | Units dropped for a bare source note link | |---|---| | the 1.4.55 prompt, 9 runs (both models) | 0 | | the shorter wording, as planned for #1517, 7 runs (6 Haiku, 1 Sonnet) | 4, one each in 4 runs | | two earlier versions of that wording, 7 runs | 5, in 3 runs | All 9 dropped units were static: 7 `world_fact`, 1 `thread` and 1 `anchor`. Their links to the bare source id were 8 `evidenced_by` and 1 `planted_in` (the anchor). The drops came from 4 sources, all with section headings (13 of the 15 sources have them), so fixing raw parsing alone would not have kept any of them. ## Steps to reproduce 1. Take a source note whose text has a section heading, such as `## world_fact`. Call `parseEvidenceUnitPayload` with a static `world_fact` unit whose only link is `{ target: <source note id>, relation: "evidenced_by" }`, passing `source_note:<source note id>` as trusted evidence, as extraction does (`:1445-1450`). 2. The link's target is `timeline_<source note id>`. Written as `source_note:<source note id>`, the target parses to the bare id instead. 3. Compile the parsed units with `compileEvidenceUnitExtraction`. In both forms the fact is dropped with `unknown_link_target`. On a source without headings only the bare form is dropped. ## Minimal fix One PR, patch bump. Two files, one guard each; both are needed. - Raw parsing (`S/extraction/evidence-unit-extraction.ts`): in `normalizeEvidenceUnitResponse` (`:674`), after the target hints are built (`:686`), add the id of every `source_note:<id>` in the trusted evidence to `targetNoteIds`. Extraction passes the source note's evidence as trusted evidence (`evidenceFromSourceNote`, `:188-191`), whose first entry is `source_note:<source note id>`, so the bare id then passes unchanged at `:896`, exactly as the `source_note:<id>` form does. - Normalizer (`S/extraction/structured-summary-normalizer.ts`): give `StructuredSummaryHints` (`:44-51`) an optional `sourceNoteId`, set it from `sourceNote?.id` where the hints are built (`:238`), and in `normalizeLinkTarget` return an identifier equal to it unchanged, beside the note-prefix check (`:1654`). - Both match the source note's exact id. Any other `source_…` id, or an event subject that happens to start with `source_`, is prefixed as today. - **CHANGELOG under `## Unreleased`**: "Extraction no longer drops a memory that cites the chat summary or import it came from, for example as its evidence." **Not included** - Accepting any `source_` id. A source the extraction doesn't hold can't be a valid link target, and validation would drop it anyway. - Changing the request wording. It already names `sourceNote.id`; the server now agrees with it. ## Regression proof In `tests/long-term-memory-extraction-graph.regression.ts`, right after the "Source-prefixed link normalization" case (`:1338-1357`), which covers `source_note:<id>` in raw parsing: - A chat-summary source note whose text is a `## world_fact` section. Parse two static `world_fact` units with `source_note:<source id>` as trusted evidence. The first's only link is `evidenced_by` to the bare source id; the second's is `evidenced_by` to `source_chat_other_summary`, a source this extraction doesn't hold. - Expect the second link to parse to `timeline_source_chat_other_summary`, so only the exact id is kept. - Compile both with the file's `compile` helper (`compileEvidenceUnitExtraction`, which applies the structured normalizer). Expect one unit kept, with its `evidenced_by` link to the source note. It fails today (none kept), and it also fails with either guard alone. ## 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; 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 OT-7. Found while reviewing the structured-summary backfill fix (#1505, merged as #1511). Its first version kept a bare `source_` id in the summary normalizer, which on its own keeps nothing: raw parsing has already turned a bare id into `timeline_source_…` by then. The normalizer does receive the bare id when the model writes `source_note:<id>` (raw parsing unwraps it), and with this fix also when the model writes the bare id. On a source with section headings it then prefixes it again, so both places need the guard. ## 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:46 +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#1504
No description provided.