[PR #1454] [MERGED] fix(long-term-memory): ignore provider subject keys, strip late-drop links, blank template fallback (1.4.49) #1468

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

📋 Pull Request Information

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

Base: staging ← Head: fix(long-term-memory)/1448-extraction-identity-links


📝 Commits (3)

  • 494e71c fix(long-term-memory): ignore provider subject keys, strip late-drop links, blank template fallback
  • d39d20b chore(long-term-memory): release 1.4.49 (#1448)
  • f777500 fix(long-term-memory): keep candidate indexes in the late link closure (#1448)

📊 Changes

17 files changed (+443 additions, -129 deletions)

View changed files

➕ artifacts/long-term-memory-1.4.49.zip (+0 -0)
📝 catalog/catalog.json (+6 -6)
📝 catalog/notes.json (+6 -6)
📝 catalog/v2/catalog.json (+6 -6)
📝 catalog/v2/notes.json (+6 -6)
📝 catalog/v3/catalog.json (+6 -6)
📝 catalog/v3/notes.json (+6 -6)
📝 packages/long-term-memory/CHANGELOG.md (+6 -0)
📝 packages/long-term-memory/manifest.json (+3 -3)
📝 packages/long-term-memory/server.mjs (+39 -39)
📝 packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/evidence-unit-extraction.ts (+58 -18)
📝 packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/evidence-unit-validation.ts (+82 -29)
📝 packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/extraction-config.ts (+2 -1)
📝 packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/subject-identity.ts (+1 -2)
📝 scripts/build-feature-packages.mjs (+1 -1)
📝 tests/long-term-memory-extraction-graph.regression.ts (+159 -0)
📝 tests/long-term-memory-local-characters.regression.ts (+56 -0)

📄 Description

Linked issue

Closes #1448

Why this change

Three extraction defects in evidence-unit-extraction.ts (tracker EX-I2, EX-I1, EX-I9):

  • Wrong character. The extraction prompt showed the model every stored character key and told it not to use them. The parser still honoured a subjectKeys value the model returned, so "Alice prefers tea" with Bob's key was saved to Bob. That only raised a warning, so it could be applied automatically.
  • Dangling links after late drops. Link closure ran once, inside the validator. Three later passes (deduplicateUnits, dropLocalCharactersOutsideRoleplay, closeSourceEventGraph) drop units without closing links again. A memory linking to a dropped unit compiled with the link intact. Preflight then threw draft link target not found, the source failed at finalize with its fingerprint already saved, and every retry failed the same way. In manual review, the suggestion was blocked with a raw error.
  • Blank template. A template whose prompt is only spaces made Conversation and Game extraction use the Roleplay prompt.

What changed

 compileEvidenceUnits
   validateLtmEvidenceUnits
-    (link closure loop, inline)
+    closeLtmEvidenceUnitLinks          # exported, same codes and order
   deduplicateUnits
   dropLocalCharactersOutsideRoleplay
   closeSourceEventGraph
+  closeLtmEvidenceUnitLinks({ stripDanglingLinks: true })
+    strip dangling link → warning `unknown_link_target`
+    relationship change loses its cause → drop, counted as a validation rejection
  • Subject keys (evidence-unit-extraction.ts, subject-identity.ts): when the server resolves subjects from names, the parser drops subjectKeys, and the response schema leaves the field out. trustedLtmSubjectPromptCatalog sends { name, aliases } only. The prompt is its only reader. The internal resolver still sets keys for established and borrowed subjects, and resolveSubjectNames: false keeps provider keys.
  • Late drops (evidence-unit-validation.ts, evidence-unit-extraction.ts): the validator's closure loop is exported and reused after closeSourceEventGraph. A dangling non-structural link is stripped with a diagnostic. A relationship change whose only cause was dropped is dropped too (relationship_state_missing_caused_by) and added to the dropped-candidate accounting.
  • Blank template (extraction-config.ts, evidence-unit-extraction.ts): a template that is empty after trimming counts as absent, so the mode default applies (activePromptTemplateId: null). evidenceUnitMessages falls back to the mode's default, not the Roleplay one. SH/schema.ts keeps .min(1) without .trim(), so stored settings that already hold a blank template still load.
  • CodeRabbit repair (f77750017): the late closure reported each unit's position in the filtered list, so after the local-character pass dropped a unit, a stripped-link warning or a late drop named the wrong candidate. validateLtmEvidenceUnits now returns its kept-unit index map, and the late closure uses it. The earlier late passes (dropLocalCharactersOutsideRoleplay, closeSourceEventGraph) still index by position, as on staging.
  • long-term-memory 1.4.49: CHANGELOG entry, version, manifest, rebuilt server.mjs, artifact and catalog entries. No release merge was needed; the branch was already on upstream/staging 1f7954305.

Diff: source +140/−50 lines, tests +208/−0, CHANGELOG +6, before the release commit.

Differences from the issue's Minimal fix, accepted in review:

  • Strip-mode drops use the validator's own relationship_state_missing_caused_by rather than unknown_link_target. A dangling target is never an event id, so it cannot be what grounded an event. Event-grounding losses are still dropped by closeSourceEventGraph.
  • No extra fixpoint with closeSourceEventGraph: strip-mode only drops relationship units, never timeline events, so a second event-graph pass has nothing to drop.
  • Closure is not re-run for duplicateAliasClosure.units, which only produces set_title mutations and carries no links.

Not in this PR: resolving link targets outside the retrieval window (audit F7 part 2), the prompt-envelope work (EX-I5), and a dedicated drop message for unknown_link_target (EX-I6, #1450).

Package and security impact

  • Affected package IDs: long-term-memory
  • Engine compatibility impact: none
  • New or changed permissions/entrypoints: none
  • Restart, storage, update, or uninstall impact: none to stored data. Extractions after the update can save a fact to a different character than before (the one it names), and they keep memories that previously failed the whole source.
  • Merge danger: two-way door. Nothing already stored is rewritten. A rollback restores the old attribution and the failing retries. Blast radius: extraction and review drafts for new imports.

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

These checks were run by the coding agent, not by a person. Engine checkout 2039583ca, Node v24.15.0.

  • Regressions added:
    • tests/long-term-memory-local-characters.regression.ts: Alice's fact resolves to Alice with and without Bob's key; the serialized catalog has no key or ref; established and borrowed keys still resolve; a link to a local character dropped outside Roleplay is stripped, and its warning names the right candidate (index 1; it reported 0 before the repair).
    • tests/long-term-memory-extraction-graph.regression.ts: the probe-B fixture (a change thread with no event link, plus a world_fact linking to it) and a late relationship drop. No compiled create_note or add_link targets a dropped unit, the drop is counted, and the accounting balances. Also the Conversation-mode whitespace prompt and getLtmExtractionConfig with a blank active template.
  • Before the fix: each new case failed on the unfixed source (dangling char_mara link, subjectKeys in the schema, key/ref in the catalog, Roleplay prompt for a blank Conversation template, unbalanced accounting).
  • On source commit 494e71c27, these passed: test-ltm.sh extraction-graph, local-characters, extraction-reliability, routes-drafts, runtime, storage, routes-imports, conversation-summary-import, review-queue-ambiguous-link, source-task and routes, plus candidate-reconciliation and reconciliation-recall run directly.
  • On HEAD f77750017 (release plus the CodeRabbit repair), these all passed:
    • A package rebuild, which left the tree clean, so the committed outputs match the source.
    • test-fast.sh (npm run check, git diff --check) and typecheck-packages long-term-memory.
    • test-catalog-lanes, validate-package-locales, validate-catalog and catalog-release-notes.
    • test-ltm.sh extraction-graph, local-characters, extraction-reliability, routes-drafts and runtime, plus candidate-reconciliation and reconciliation-recall.
  • Not done: a live extraction in Engine, and test-ltm.sh installation for the 1.4.49 artifact. Hosted CI runs the full Long-Term Memory regression list.

Documentation impact

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

UI evidence (if applicable)

None. Nothing changes on screen.

🤖 Generated with Claude Code


🔄 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/1454 **Author:** [@Promansis](https://github.com/Promansis) **Created:** 10/18/2026 **Status:** ✅ Merged **Merged:** 10/18/2026 **Merged by:** [@Promansis](https://github.com/Promansis) **Base:** `staging` ← **Head:** `fix(long-term-memory)/1448-extraction-identity-links` --- ### 📝 Commits (3) - [`494e71c`](https://github.com/Pasta-Devs/Marinara-Agents/commit/494e71c276170aa2a707ad8c10d7c139dd74e1f1) fix(long-term-memory): ignore provider subject keys, strip late-drop links, blank template fallback - [`d39d20b`](https://github.com/Pasta-Devs/Marinara-Agents/commit/d39d20be93114a5d5a176ed16d0ee4b0cf46d976) chore(long-term-memory): release 1.4.49 (#1448) - [`f777500`](https://github.com/Pasta-Devs/Marinara-Agents/commit/f777500178d64a539178c7c9725b36976ef2c77e) fix(long-term-memory): keep candidate indexes in the late link closure (#1448) ### 📊 Changes **17 files changed** (+443 additions, -129 deletions) <details> <summary>View changed files</summary> ➕ `artifacts/long-term-memory-1.4.49.zip` (+0 -0) 📝 `catalog/catalog.json` (+6 -6) 📝 `catalog/notes.json` (+6 -6) 📝 `catalog/v2/catalog.json` (+6 -6) 📝 `catalog/v2/notes.json` (+6 -6) 📝 `catalog/v3/catalog.json` (+6 -6) 📝 `catalog/v3/notes.json` (+6 -6) 📝 `packages/long-term-memory/CHANGELOG.md` (+6 -0) 📝 `packages/long-term-memory/manifest.json` (+3 -3) 📝 `packages/long-term-memory/server.mjs` (+39 -39) 📝 `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/evidence-unit-extraction.ts` (+58 -18) 📝 `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/evidence-unit-validation.ts` (+82 -29) 📝 `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/extraction-config.ts` (+2 -1) 📝 `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/subject-identity.ts` (+1 -2) 📝 `scripts/build-feature-packages.mjs` (+1 -1) 📝 `tests/long-term-memory-extraction-graph.regression.ts` (+159 -0) 📝 `tests/long-term-memory-local-characters.regression.ts` (+56 -0) </details> ### 📄 Description ## Linked issue Closes #1448 ## Why this change Three extraction defects in `evidence-unit-extraction.ts` (tracker EX-I2, EX-I1, EX-I9): - **Wrong character.** The extraction prompt showed the model every stored character key and told it not to use them. The parser still honoured a `subjectKeys` value the model returned, so "Alice prefers tea" with Bob's key was saved to Bob. That only raised a warning, so it could be applied automatically. - **Dangling links after late drops.** Link closure ran once, inside the validator. Three later passes (`deduplicateUnits`, `dropLocalCharactersOutsideRoleplay`, `closeSourceEventGraph`) drop units without closing links again. A memory linking to a dropped unit compiled with the link intact. Preflight then threw `draft link target not found`, the source failed at `finalize` with its fingerprint already saved, and every retry failed the same way. In manual review, the suggestion was blocked with a raw error. - **Blank template.** A template whose prompt is only spaces made Conversation and Game extraction use the Roleplay prompt. ## What changed ```diff compileEvidenceUnits validateLtmEvidenceUnits - (link closure loop, inline) + closeLtmEvidenceUnitLinks # exported, same codes and order deduplicateUnits dropLocalCharactersOutsideRoleplay closeSourceEventGraph + closeLtmEvidenceUnitLinks({ stripDanglingLinks: true }) + strip dangling link → warning `unknown_link_target` + relationship change loses its cause → drop, counted as a validation rejection ``` - **Subject keys** (`evidence-unit-extraction.ts`, `subject-identity.ts`): when the server resolves subjects from names, the parser drops `subjectKeys`, and the response schema leaves the field out. `trustedLtmSubjectPromptCatalog` sends `{ name, aliases }` only. The prompt is its only reader. The internal resolver still sets keys for established and borrowed subjects, and `resolveSubjectNames: false` keeps provider keys. - **Late drops** (`evidence-unit-validation.ts`, `evidence-unit-extraction.ts`): the validator's closure loop is exported and reused after `closeSourceEventGraph`. A dangling non-structural link is stripped with a diagnostic. A relationship change whose only cause was dropped is dropped too (`relationship_state_missing_caused_by`) and added to the dropped-candidate accounting. - **Blank template** (`extraction-config.ts`, `evidence-unit-extraction.ts`): a template that is empty after trimming counts as absent, so the mode default applies (`activePromptTemplateId: null`). `evidenceUnitMessages` falls back to the mode's default, not the Roleplay one. `SH/schema.ts` keeps `.min(1)` without `.trim()`, so stored settings that already hold a blank template still load. - CodeRabbit repair (`f77750017`): the late closure reported each unit's position in the filtered list, so after the local-character pass dropped a unit, a stripped-link warning or a late drop named the wrong candidate. `validateLtmEvidenceUnits` now returns its kept-unit index map, and the late closure uses it. The earlier late passes (`dropLocalCharactersOutsideRoleplay`, `closeSourceEventGraph`) still index by position, as on staging. - `long-term-memory` 1.4.49: CHANGELOG entry, version, manifest, rebuilt `server.mjs`, artifact and catalog entries. No release merge was needed; the branch was already on `upstream/staging` 1f7954305. Diff: source +140/−50 lines, tests +208/−0, CHANGELOG +6, before the release commit. Differences from the issue's Minimal fix, accepted in review: - Strip-mode drops use the validator's own `relationship_state_missing_caused_by` rather than `unknown_link_target`. A dangling target is never an event id, so it cannot be what grounded an event. Event-grounding losses are still dropped by `closeSourceEventGraph`. - No extra fixpoint with `closeSourceEventGraph`: strip-mode only drops relationship units, never timeline events, so a second event-graph pass has nothing to drop. - Closure is not re-run for `duplicateAliasClosure.units`, which only produces `set_title` mutations and carries no links. Not in this PR: resolving link targets outside the retrieval window (audit F7 part 2), the prompt-envelope work (EX-I5), and a dedicated drop message for `unknown_link_target` (EX-I6, #1450). ## Package and security impact - Affected package IDs: `long-term-memory` - Engine compatibility impact: none - New or changed permissions/entrypoints: none - Restart, storage, update, or uninstall impact: none to stored data. Extractions after the update can save a fact to a different character than before (the one it names), and they keep memories that previously failed the whole source. - **Merge danger:** two-way door. Nothing already stored is rewritten. A rollback restores the old attribution and the failing retries. Blast radius: extraction and review drafts for new imports. ## 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 These checks were run by the coding agent, not by a person. Engine checkout `2039583ca`, Node `v24.15.0`. - **Regressions added:** - `tests/long-term-memory-local-characters.regression.ts`: Alice's fact resolves to Alice with and without Bob's key; the serialized catalog has no `key` or `ref`; established and borrowed keys still resolve; a link to a local character dropped outside Roleplay is stripped, and its warning names the right candidate (index 1; it reported 0 before the repair). - `tests/long-term-memory-extraction-graph.regression.ts`: the probe-B fixture (a `change` thread with no event link, plus a `world_fact` linking to it) and a late relationship drop. No compiled `create_note` or `add_link` targets a dropped unit, the drop is counted, and the accounting balances. Also the Conversation-mode whitespace prompt and `getLtmExtractionConfig` with a blank active template. - **Before the fix:** each new case failed on the unfixed source (dangling `char_mara` link, `subjectKeys` in the schema, `key`/`ref` in the catalog, Roleplay prompt for a blank Conversation template, unbalanced accounting). - On source commit `494e71c27`, these passed: `test-ltm.sh` `extraction-graph`, `local-characters`, `extraction-reliability`, `routes-drafts`, `runtime`, `storage`, `routes-imports`, `conversation-summary-import`, `review-queue-ambiguous-link`, `source-task` and `routes`, plus `candidate-reconciliation` and `reconciliation-recall` run directly. - On HEAD `f77750017` (release plus the CodeRabbit repair), these all passed: - A package rebuild, which left the tree clean, so the committed outputs match the source. - `test-fast.sh` (`npm run check`, `git diff --check`) and `typecheck-packages long-term-memory`. - `test-catalog-lanes`, `validate-package-locales`, `validate-catalog` and `catalog-release-notes`. - `test-ltm.sh` `extraction-graph`, `local-characters`, `extraction-reliability`, `routes-drafts` and `runtime`, plus `candidate-reconciliation` and `reconciliation-recall`. - Not done: a live extraction in Engine, and `test-ltm.sh installation` for the 1.4.49 artifact. Hosted CI runs the full Long-Term Memory regression list. ## Documentation impact - [ ] No documentation changes needed - [ ] Updated this README catalog and package guidance - [ ] Updated linked Marinara Engine documentation ## UI evidence (if applicable) None. Nothing changes on screen. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-21 05:11:48 +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#1468
No description provided.