[GH-ISSUE #1085] [Feature]: Bounded post-extraction reconciliation for Long-Term Memory extraction #551

Closed
opened 2026-10-20 17:28:31 +07:00 by bsakaguchi · 0 comments
Owner

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

Originally assigned to: @Promansis on GitHub.

What problem does this solve?

Long-Term Memory extraction currently relies on the provider prompt to reuse existing note IDs. evidence-unit-extraction.ts instructs the model: "Do not intentionally target an existing note id unless that exact note appears in existingTypedNotes."

Only character_fact and relationship_state subjects receive code-side canonical resolution through the trusted catalog. Every other stream (timeline_event, thread, world_fact, tone, anchor) derives its target note id directly from the model-chosen subjectId via noteIdForEvidenceUnit (evidence-unit-validation.ts). As the vault grows we want canonical identity to be code-owned, but removing model-visible note IDs without a code-side replacement makes the model re-invent subjectIds for notes that already exist, producing duplicate notes.

This issue builds the missing code-side reconciliation first, while the existing prompt is still in place, so a later prompt change has a proven replacement.

Proposed package or change

Package: long-term-memory (server extraction).

Add bounded, deterministic post-extraction reconciliation that resolves extracted candidates to existing notes in code, before validation and compilation:

  • Retrieve existing notes per candidate by scope and mode, narrowed by bucket, section, subject mentions/aliases, and existing indexed text/content keys.
  • Exactly one compatible match: reuse that existing note id and remap the candidate's target and links.
  • No compatible match: allow a create.
  • Multiple plausible matches: retain the ambiguity diagnostic and require review.
  • Preserve existing scope filters and source-like-note exclusions.
  • Keep deduplication and mutation compilation deterministic; keep retrieval bounded (no fallback to the whole vault) and deterministic.

Focus the new work on the non-character streams that currently rely most directly on model-visible IDs. Keep character/relationship resolution in subject-identity.ts as-is unless focused tests prove it must participate.

Keep unchanged: prompt contents and existingTypedNotes; LtmEvidenceUnit structure; draft/review/apply, locks, fingerprints, index rebuild; deterministic game-mode extraction. Do not add vector/embedding search or a second LLM stage.

Proof: focused tests covering deduplication, create behavior, ambiguity, scope isolation, link/event closure, and mutation kinds; plus boundedness and retrieval recall measured against a recorded baseline, including a vault larger than the current prompt could hold.

Why should this be optional?

This is a behavior change inside the existing downloadable long-term-memory Agent package's server extraction code. It belongs in the package payload, not the lightweight Engine core, consistent with the catalog model: change source/builders, then rebuild generated bundles and the catalog lane separately.

Alternatives considered

  • Remove existing notes from the prompt first without a code-side matcher: produces duplicate notes; rejected.
  • Vector/embedding retrieval or a second LLM adjudication pass: explicitly deferred; existing BM25, subject-catalog, and index helpers should be tried first.
  • Change the LtmEvidenceUnit shape: not needed; the type already carries subjectNames/subjectKeys hints.

Additional context

First of two sequenced issues. The prompt-decoupling issue depends on this reconciliation being in place and proven. Target branch: staging.

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 (Sep 26, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1085 Originally assigned to: @Promansis on GitHub. ## What problem does this solve? Long-Term Memory extraction currently relies on the provider prompt to reuse existing note IDs. `evidence-unit-extraction.ts` instructs the model: "Do not intentionally target an existing note id unless that exact note appears in existingTypedNotes." Only `character_fact` and `relationship_state` subjects receive code-side canonical resolution through the trusted catalog. Every other stream (`timeline_event`, `thread`, `world_fact`, `tone`, `anchor`) derives its target note id directly from the model-chosen `subjectId` via `noteIdForEvidenceUnit` (`evidence-unit-validation.ts`). As the vault grows we want canonical identity to be code-owned, but removing model-visible note IDs without a code-side replacement makes the model re-invent `subjectId`s for notes that already exist, producing duplicate notes. This issue builds the missing code-side reconciliation first, while the existing prompt is still in place, so a later prompt change has a proven replacement. ## Proposed package or change Package: `long-term-memory` (server extraction). Add bounded, deterministic post-extraction reconciliation that resolves extracted candidates to existing notes in code, before validation and compilation: - Retrieve existing notes per candidate by scope and mode, narrowed by bucket, section, subject mentions/aliases, and existing indexed text/content keys. - Exactly one compatible match: reuse that existing note id and remap the candidate's target and links. - No compatible match: allow a create. - Multiple plausible matches: retain the ambiguity diagnostic and require review. - Preserve existing scope filters and source-like-note exclusions. - Keep deduplication and mutation compilation deterministic; keep retrieval bounded (no fallback to the whole vault) and deterministic. Focus the new work on the non-character streams that currently rely most directly on model-visible IDs. Keep character/relationship resolution in `subject-identity.ts` as-is unless focused tests prove it must participate. Keep unchanged: prompt contents and `existingTypedNotes`; `LtmEvidenceUnit` structure; draft/review/apply, locks, fingerprints, index rebuild; deterministic game-mode extraction. Do not add vector/embedding search or a second LLM stage. Proof: focused tests covering deduplication, create behavior, ambiguity, scope isolation, link/event closure, and mutation kinds; plus boundedness and retrieval recall measured against a recorded baseline, including a vault larger than the current prompt could hold. ## Why should this be optional? This is a behavior change inside the existing downloadable `long-term-memory` Agent package's server extraction code. It belongs in the package payload, not the lightweight Engine core, consistent with the catalog model: change source/builders, then rebuild generated bundles and the catalog lane separately. ## Alternatives considered - Remove existing notes from the prompt first without a code-side matcher: produces duplicate notes; rejected. - Vector/embedding retrieval or a second LLM adjudication pass: explicitly deferred; existing BM25, subject-catalog, and index helpers should be tried first. - Change the `LtmEvidenceUnit` shape: not needed; the type already carries `subjectNames`/`subjectKeys` hints. ## Additional context First of two sequenced issues. The prompt-decoupling issue depends on this reconciliation being in place and proven. Target branch: `staging`. ## 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-20 17:28:31 +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#551
No description provided.