[PR #902] [MERGED] fix(long-term-memory): subject identity ambiguity, participant backfill, and coverage (#899) #1185

Closed
opened 2026-10-21 05:04:54 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Agents/pull/902
Author: @Promansis
Created: 9/17/2026
Status: ✅ Merged
Merged: 9/18/2026
Merged by: @Promansis

Base: staging ← Head: fix/ltm-subject-identity-899


📝 Commits (7)

  • d022546 fix(long-term-memory): subject identity ambiguity, participant backfill, and coverage (#899)
  • d45e514 Merge branch 'staging' into fix/ltm-subject-identity-899
  • 61c9cc7 fix(long-term-memory): address subject identity review findings (#899)
  • 83e87a7 Merge remote-tracking branch 'origin/fix/ltm-subject-identity-899' into fix/ltm-subject-identity-899
  • 4afed61 Merge branch 'staging' into fix/ltm-subject-identity-899
  • 76a9565 fix(long-term-memory): publish subject identity repairs (#899)
  • f37df06 Merge remote-tracking branch 'origin/fix/ltm-subject-identity-899' into fix/ltm-subject-identity-899

📊 Changes

15 files changed (+700 additions, -113 deletions)

View changed files

➕ artifacts/long-term-memory-1.3.2.zip (+0 -0)
📝 catalog/catalog.json (+6 -6)
📝 catalog/notes.json (+6 -0)
📝 catalog/v2/catalog.json (+6 -6)
📝 catalog/v2/notes.json (+6 -0)
📝 catalog/v3/catalog.json (+6 -6)
📝 catalog/v3/notes.json (+6 -0)
📝 packages/long-term-memory/CHANGELOG.md (+4 -0)
📝 packages/long-term-memory/manifest.json (+3 -3)
📝 packages/long-term-memory/server.mjs (+49 -49)
📝 packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/source-extraction.ts (+1 -0)
📝 packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/structured-summary-normalizer.ts (+60 -12)
📝 packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/subject-identity.ts (+304 -30)
📝 scripts/build-feature-packages.mjs (+1 -1)
📝 tests/long-term-memory-local-characters.regression.ts (+242 -0)

📄 Description

Pull request

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #899

Why this change

In long-term memory extraction and structured backfills:

  1. Roster and catalog subject identity collisions dropped candidates without sufficient context in extraction diagnostics, preventing callers and review surfaces from distinguishing group-catalog vs local-note ambiguity.
  2. Structured backfill normalization for relationship and character sections omitted or discarded participant names, causing composite subjects to fail resolution or leak raw metadata prose into character fact texts.
  3. Multiple references to the same subject with different surface names (e.g. "Alice" and "Alice Vance") could fail coverage checks or create redundant backfill candidates due to mismatched or missing pre-resolution against the catalog index.

What changed

  • packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/subject-identity.ts:
    • Added provenance and sourceScope tracking across roster, notes, and local sources.
    • Implemented diagnoseCollision helper exposing collisionSource, competingSubjectKeys, and competingRecords in ambiguous_subject_identity diagnostics.
    • Preserved colliding local entries in ambiguousLocalEntries for failure-closed disambiguation.
    • Added on-demand subject resolution in resolveAndCacheSubjectName during named-unit subject resolution.
    • Fixed composite segmentation and trait matching to prevent surname-only false matches and prioritize trait prefixes unless composite connectors are present.
  • packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/structured-summary-normalizer.ts:
    • Added participant keys (characters, character, participants, participant, names, name) to metadata sets.
    • Parsed explicit relationship participant names into subjectNames without prose leakage.
    • Wired characterIdentityKey into maybeAddStructuredCharacterUnits and characterUnitIdentity to suppress redundant backfill for covered facts.
    • Tolerated standard plural/singular headings in structuredBucketFromHeading.
  • packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/source-extraction.ts:
    • Passed identityContext.identityKeyForUnit as characterIdentityKey to normalizeStructuredSummaryEvidenceUnits.
  • Rebuilt package artifacts and catalog lanes:
    • packages/long-term-memory/server.mjs, packages/long-term-memory/manifest.json, artifacts/long-term-memory-1.3.1.zip, catalog/catalog.json, catalog/v2/catalog.json, catalog/v3/catalog.json.
  • tests/long-term-memory-local-characters.regression.ts:
    • Added automated regressions for ambiguity diagnostics with competing records, structured backfill participant preservation, and multi-word surname/coverage deduplication.

Package and security impact

  • Affected package IDs: long-term-memory
  • Engine compatibility impact: None; compatible with engine >= 2.3.0 < 4.0.0
  • New or changed permissions/entrypoints: None
  • Restart, storage, update, or uninstall impact: None

Validation

  • node scripts/validate-catalog.mjs passes locally
  • git diff --check passes locally
  • Rebuilt every affected manifest, payload, artifact, and catalog entry
  • Installed or updated the affected package through Marinara Engine
  • Checked supported modes, restart behavior, and uninstall cleanup
  • Read and followed CONTRIBUTING.md

Manual verification notes

  1. Ran bash /home/damo/.config/opencode/marinara-agents-local/test-fast.sh (Prettier and ESLint check passed).
  2. Ran bash /home/damo/.config/opencode/marinara-agents-local/test-ltm.sh all (all 20+ regression suites passed including local-characters, extraction-graph, and extraction-reliability).
  3. Rebuilt long-term-memory package via scripts/build-feature-packages.mjs long-term-memory.
  4. Ran bash /home/damo/.config/opencode/marinara-agents-local/test-ci.sh (all catalog lanes, safety checks, and repo regression gates passed).
  5. Ran git diff --check with 0 whitespace issues.

Documentation impact

  • No documentation changes needed
  • Updated this README catalog and package guidance
  • Updated linked Marinara Engine documentation

UI evidence (if applicable)

N/A (Server-side extraction and normalization logic).

Summary by CodeRabbit

  • New Features

    • Improved structured-summary parsing for relationships, characters, timelines, world facts, and threads.
    • Enhanced character and relationship name handling, including participant details and identity matching.
    • Added clearer diagnostics for ambiguous local character names and competing matches.
    • Improved support for locally scoped characters, shared surnames, and structured-summary backfill.
  • Bug Fixes

    • Prevented redundant backfill candidates and incorrect trait-prefix matches in composite names.
  • Chores

    • Updated the package to version 1.3.2 with refreshed server and artifact builds.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Agents/pull/902 **Author:** [@Promansis](https://github.com/Promansis) **Created:** 9/17/2026 **Status:** ✅ Merged **Merged:** 9/18/2026 **Merged by:** [@Promansis](https://github.com/Promansis) **Base:** `staging` ← **Head:** `fix/ltm-subject-identity-899` --- ### 📝 Commits (7) - [`d022546`](https://github.com/Pasta-Devs/Marinara-Agents/commit/d022546758f32fcbf630cb4b4a00be5633d25e12) fix(long-term-memory): subject identity ambiguity, participant backfill, and coverage (#899) - [`d45e514`](https://github.com/Pasta-Devs/Marinara-Agents/commit/d45e5144b24101821bb771b7812097d9f4a909ef) Merge branch 'staging' into fix/ltm-subject-identity-899 - [`61c9cc7`](https://github.com/Pasta-Devs/Marinara-Agents/commit/61c9cc7403da828d0878ae318f082ac5a87770cf) fix(long-term-memory): address subject identity review findings (#899) - [`83e87a7`](https://github.com/Pasta-Devs/Marinara-Agents/commit/83e87a76ed847d4d688f84b462286428eca8a3dc) Merge remote-tracking branch 'origin/fix/ltm-subject-identity-899' into fix/ltm-subject-identity-899 - [`4afed61`](https://github.com/Pasta-Devs/Marinara-Agents/commit/4afed61e39f49c39909c1842adeb2bcf705d989d) Merge branch 'staging' into fix/ltm-subject-identity-899 - [`76a9565`](https://github.com/Pasta-Devs/Marinara-Agents/commit/76a95656b9dfa9b0bceaf6d914bd615683b6476e) fix(long-term-memory): publish subject identity repairs (#899) - [`f37df06`](https://github.com/Pasta-Devs/Marinara-Agents/commit/f37df06a0bd9d5f6ba7d65f36381b97a168eb0fe) Merge remote-tracking branch 'origin/fix/ltm-subject-identity-899' into fix/ltm-subject-identity-899 ### 📊 Changes **15 files changed** (+700 additions, -113 deletions) <details> <summary>View changed files</summary> ➕ `artifacts/long-term-memory-1.3.2.zip` (+0 -0) 📝 `catalog/catalog.json` (+6 -6) 📝 `catalog/notes.json` (+6 -0) 📝 `catalog/v2/catalog.json` (+6 -6) 📝 `catalog/v2/notes.json` (+6 -0) 📝 `catalog/v3/catalog.json` (+6 -6) 📝 `catalog/v3/notes.json` (+6 -0) 📝 `packages/long-term-memory/CHANGELOG.md` (+4 -0) 📝 `packages/long-term-memory/manifest.json` (+3 -3) 📝 `packages/long-term-memory/server.mjs` (+49 -49) 📝 `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/source-extraction.ts` (+1 -0) 📝 `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/structured-summary-normalizer.ts` (+60 -12) 📝 `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/subject-identity.ts` (+304 -30) 📝 `scripts/build-feature-packages.mjs` (+1 -1) 📝 `tests/long-term-memory-local-characters.regression.ts` (+242 -0) </details> ### 📄 Description # Pull request > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. ## Linked issue Closes #899 ## Why this change In long-term memory extraction and structured backfills: 1. Roster and catalog subject identity collisions dropped candidates without sufficient context in extraction diagnostics, preventing callers and review surfaces from distinguishing group-catalog vs local-note ambiguity. 2. Structured backfill normalization for relationship and character sections omitted or discarded participant names, causing composite subjects to fail resolution or leak raw metadata prose into character fact texts. 3. Multiple references to the same subject with different surface names (e.g. "Alice" and "Alice Vance") could fail coverage checks or create redundant backfill candidates due to mismatched or missing pre-resolution against the catalog index. ## What changed - `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/subject-identity.ts`: - Added `provenance` and `sourceScope` tracking across roster, notes, and local sources. - Implemented `diagnoseCollision` helper exposing `collisionSource`, `competingSubjectKeys`, and `competingRecords` in `ambiguous_subject_identity` diagnostics. - Preserved colliding local entries in `ambiguousLocalEntries` for failure-closed disambiguation. - Added on-demand subject resolution in `resolveAndCacheSubjectName` during named-unit subject resolution. - Fixed composite segmentation and trait matching to prevent surname-only false matches and prioritize trait prefixes unless composite connectors are present. - `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/structured-summary-normalizer.ts`: - Added participant keys (`characters`, `character`, `participants`, `participant`, `names`, `name`) to metadata sets. - Parsed explicit relationship participant names into `subjectNames` without prose leakage. - Wired `characterIdentityKey` into `maybeAddStructuredCharacterUnits` and `characterUnitIdentity` to suppress redundant backfill for covered facts. - Tolerated standard plural/singular headings in `structuredBucketFromHeading`. - `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/source-extraction.ts`: - Passed `identityContext.identityKeyForUnit` as `characterIdentityKey` to `normalizeStructuredSummaryEvidenceUnits`. - Rebuilt package artifacts and catalog lanes: - `packages/long-term-memory/server.mjs`, `packages/long-term-memory/manifest.json`, `artifacts/long-term-memory-1.3.1.zip`, `catalog/catalog.json`, `catalog/v2/catalog.json`, `catalog/v3/catalog.json`. - `tests/long-term-memory-local-characters.regression.ts`: - Added automated regressions for ambiguity diagnostics with competing records, structured backfill participant preservation, and multi-word surname/coverage deduplication. ## Package and security impact - Affected package IDs: `long-term-memory` - Engine compatibility impact: None; compatible with engine >= 2.3.0 < 4.0.0 - New or changed permissions/entrypoints: None - Restart, storage, update, or uninstall impact: None ## Validation - [ ] `node scripts/validate-catalog.mjs` passes locally - [ ] `git diff --check` passes locally - [ ] Rebuilt every affected manifest, payload, artifact, and catalog entry - [ ] Installed or updated the affected package through Marinara Engine - [ ] Checked supported modes, restart behavior, and uninstall cleanup - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes 1. Ran `bash /home/damo/.config/opencode/marinara-agents-local/test-fast.sh` (Prettier and ESLint check passed). 2. Ran `bash /home/damo/.config/opencode/marinara-agents-local/test-ltm.sh all` (all 20+ regression suites passed including local-characters, extraction-graph, and extraction-reliability). 3. Rebuilt long-term-memory package via `scripts/build-feature-packages.mjs long-term-memory`. 4. Ran `bash /home/damo/.config/opencode/marinara-agents-local/test-ci.sh` (all catalog lanes, safety checks, and repo regression gates passed). 5. Ran `git diff --check` with 0 whitespace issues. ## Documentation impact - [ ] No documentation changes needed - [ ] Updated this README catalog and package guidance - [ ] Updated linked Marinara Engine documentation ## UI evidence (if applicable) N/A (Server-side extraction and normalization logic). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Improved structured-summary parsing for relationships, characters, timelines, world facts, and threads. * Enhanced character and relationship name handling, including participant details and identity matching. * Added clearer diagnostics for ambiguous local character names and competing matches. * Improved support for locally scoped characters, shared surnames, and structured-summary backfill. * **Bug Fixes** * Prevented redundant backfill candidates and incorrect trait-prefix matches in composite names. * **Chores** * Updated the package to version 1.3.2 with refreshed server and artifact builds. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-21 05:04:54 +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#1185
No description provided.