[PR #1088] [MERGED] feat(long-term-memory): reconcile extracted candidates against existing notes (1.3.22) (#1085) #1288

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

📋 Pull Request Information

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

Base: staging ← Head: feature(long-term-memory)/1085-extraction-reconciliation


📝 Commits (5)

  • eb1c0c9 feat(long-term-memory): reconcile extracted candidates against existing notes (1.3.22) (#1085)
  • 8127b34 fix(long-term-memory): gate reconciliation on a complete, note-diverse candidate set
  • 60d7cd7 Merge branch 'staging' into feature(long-term-memory)/1085-extraction-reconciliation
  • 4d82ace fix(long-term-memory): keep chunk-only truncation complete and warn on unconfirmed creates
  • 7216fa8 Merge remote-tracking branch 'origin/feature(long-term-memory)/1085-extraction-reconciliation' into feature(long-term-memory)/1085-extraction-reconciliation

📊 Changes

20 files changed (+1484 additions, -110 deletions)

View changed files

➕ artifacts/long-term-memory-1.3.22.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 (+5 -0)
📝 packages/long-term-memory/manifest.json (+3 -3)
📝 packages/long-term-memory/server.mjs (+58 -58)
➕ packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/candidate-reconciliation.ts (+252 -0)
📝 packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/evidence-unit-validation.ts (+1 -1)
📝 packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/retrieval.ts (+25 -5)
📝 packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/scoped-targets.ts (+11 -1)
📝 packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/source-extraction.ts (+40 -2)
📝 packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/source-processing.ts (+9 -1)
📝 scripts/build-feature-packages.mjs (+1 -1)
📝 tests/README.md (+2 -2)
➕ tests/long-term-memory-candidate-reconciliation.regression.ts (+753 -0)
➕ tests/long-term-memory-reconciliation-recall.regression.ts (+288 -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 #1085

Why this change

  • Source extraction derived every non-character target from the model-chosen subjectId. When the model named the same subject differently across sources, the agent created a second note under a new id instead of reusing the existing note, so the vault accumulated duplicates and recall had to surface both.
  • Follow-up tracked separately: #1087 covers the residual case where a note committed after preparation (concurrent imports, or a sibling source in the same import batch) is not seen by reconciliation. That is a pre-existing preparation-snapshot limitation, is documented, and did not regress with this change.

What changed

  • long-term-memory 1.3.22: new candidate-reconciliation.ts runs a bounded, deterministic post-extraction reconciliation for timeline_event, thread, world_fact, tone, and anchor candidates before target resolution. Exactly one in-scope compatible match reuses that note; no match still creates; several plausible matches stay unattached and require review (candidate_reconciliation_ambiguous), so an ambiguous duplicate is never created or auto-applied.
  • Matching stays code-owned and out of the provider prompt: identity (title/subject names/subject keys) first, then section-text similarity. Character and relationship candidates remain owned by subject-identity.ts and scoped-targets.ts.
  • retrieval.ts gains optional noteTypes (pre-budget type filter so unrelated chunks cannot crowd a bounded window) and dedupeExactText (reconciliation keeps identical-text notes visible as a genuine ambiguity). scoped-targets.ts exports remapEvidenceUnitTargets plus a reachability guard so a match never compiles against a different new note. source-processing.ts forces review when a reconciliation ambiguity is present.
  • Generated outputs rebuilt from source: server.mjs, manifest.json (1.3.22), artifacts/long-term-memory-1.3.22.zip, catalog lanes v2/v3 and legacy, and catalog/notes.json.
  • Tests: new tests/long-term-memory-candidate-reconciliation.regression.ts and tests/long-term-memory-reconciliation-recall.regression.ts; tests/README.md ownership table updated.
  • Review follow-up: retrieval.ts now reports truncation per ranked note, so chunk-budget drops of a note already inside the window no longer mark reconciliation incomplete, and candidate-reconciliation.ts warns candidate_reconciliation_incomplete when an incomplete window shows compatible candidates but no match, instead of compiling a create blind. Two regression cases added and verified red before the fix.

Package and security impact

  • Affected package IDs: long-term-memory
  • Engine compatibility impact: none. Engine range is unchanged (min 2.4.1, maxExclusive 4.0.0) and engine-boundary.json is unchanged — no new private Engine imports.
  • New or changed permissions/entrypoints: none; permissions and entrypoints are unchanged.
  • Restart, storage, update, or uninstall impact: restartRequired unchanged, no schema or migration change. The pass adds a draft diagnostic and can set a draft to review-required.

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

  • Baseline revision d29e32ce (upstream/staging); change HEAD 7216fa81 (feature work 8127b34c, review repair 4d82ace9, merged with staging through origin's 60d7cd73). Engine 41d5d12.
  • node scripts/typecheck-packages.mjs long-term-memory, npm run check, and git diff --check pass.
  • Repository gates pass on the rebuilt tree: node scripts/test-catalog-lanes.mjs, node scripts/validate-package-locales.mjs, node scripts/validate-catalog.mjs (38 packages; v2=38, v3=38, legacy=v2), and node scripts/tests/catalog-release-notes.regression.mjs.
  • Rebuilt with node scripts/build-feature-packages.mjs long-term-memory; the 1.3.22 payload and catalog entry are regenerated from source (no hand-edited bundles, hashes, or sizes).
  • 17 affected LTM regressions pass against the rebuilt tree with MARINARA_AGENTS_ROOT/MARINARA_ENGINE_ROOT set: storage, extraction-graph, extraction-reliability, runtime, conversation-summary-import, scope-targets, scope-fallback-labels, local-characters, review-queue-ambiguous-link, source-task, index-keys, debug-log, routes, routes-scope-identity, candidate-reconciliation, reconciliation-recall, and installation (exact ZIP install).
  • Publish proof: tested inputs captured on HEAD and re-verified unchanged before push with assertPublishProof (repository digest 58d13c3b04bbe50c775786af999f405da1609a6c36f0de5c41ff44672013f51a, engine digest 16d84b2dc18c246dfa4f271f11933260bc1b09fa82392ec02a89f0fb40519d09).
  • Not run: browser and lifecycle suites (Playwright); hosted CI. Those remain unverified.

Documentation impact

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

UI evidence (if applicable)

No UI changes in this PR.

Summary by CodeRabbit

  • New Features
    • Long-Term Memory version 1.3.22 reuses an existing memory when an extracted candidate refers to the same subject, helping prevent duplicate notes.
  • Bug Fixes
    • When a candidate could match multiple existing memories, it is left unattached and flagged for review instead of being applied automatically.
    • Candidates are also left unattached for review when the available search results may be incomplete, preventing uncertain matches from being applied automatically.

🔄 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/1088 **Author:** [@Promansis](https://github.com/Promansis) **Created:** 9/26/2026 **Status:** ✅ Merged **Merged:** 9/27/2026 **Merged by:** [@Promansis](https://github.com/Promansis) **Base:** `staging` ← **Head:** `feature(long-term-memory)/1085-extraction-reconciliation` --- ### 📝 Commits (5) - [`eb1c0c9`](https://github.com/Pasta-Devs/Marinara-Agents/commit/eb1c0c9ddbe9706272e0706f2c740e498f50a71d) feat(long-term-memory): reconcile extracted candidates against existing notes (1.3.22) (#1085) - [`8127b34`](https://github.com/Pasta-Devs/Marinara-Agents/commit/8127b34c0afb198115587404d7ec5f9048b87929) fix(long-term-memory): gate reconciliation on a complete, note-diverse candidate set - [`60d7cd7`](https://github.com/Pasta-Devs/Marinara-Agents/commit/60d7cd734a51e5f6be4bda58085a85654d6e2282) Merge branch 'staging' into feature(long-term-memory)/1085-extraction-reconciliation - [`4d82ace`](https://github.com/Pasta-Devs/Marinara-Agents/commit/4d82ace98848aba0824656e7fef607ad670cc2e0) fix(long-term-memory): keep chunk-only truncation complete and warn on unconfirmed creates - [`7216fa8`](https://github.com/Pasta-Devs/Marinara-Agents/commit/7216fa81782acdb5629711dd8a375c0ab043d2c1) Merge remote-tracking branch 'origin/feature(long-term-memory)/1085-extraction-reconciliation' into feature(long-term-memory)/1085-extraction-reconciliation ### 📊 Changes **20 files changed** (+1484 additions, -110 deletions) <details> <summary>View changed files</summary> ➕ `artifacts/long-term-memory-1.3.22.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` (+5 -0) 📝 `packages/long-term-memory/manifest.json` (+3 -3) 📝 `packages/long-term-memory/server.mjs` (+58 -58) ➕ `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/candidate-reconciliation.ts` (+252 -0) 📝 `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/evidence-unit-validation.ts` (+1 -1) 📝 `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/retrieval.ts` (+25 -5) 📝 `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/scoped-targets.ts` (+11 -1) 📝 `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/source-extraction.ts` (+40 -2) 📝 `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/source-processing.ts` (+9 -1) 📝 `scripts/build-feature-packages.mjs` (+1 -1) 📝 `tests/README.md` (+2 -2) ➕ `tests/long-term-memory-candidate-reconciliation.regression.ts` (+753 -0) ➕ `tests/long-term-memory-reconciliation-recall.regression.ts` (+288 -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`. <!-- Open as a draft while implementation is in progress. Mark Ready for review only after validation and self-review. --> ## Linked issue <!-- Every PR should reference an issue or feature request. --> Closes #1085 ## Why this change <!-- What user problem, package bug, or catalog goal does this solve? --> - Source extraction derived every non-character target from the model-chosen `subjectId`. When the model named the same subject differently across sources, the agent created a second note under a new id instead of reusing the existing note, so the vault accumulated duplicates and recall had to surface both. - Follow-up tracked separately: #1087 covers the residual case where a note committed after preparation (concurrent imports, or a sibling source in the same import batch) is not seen by reconciliation. That is a pre-existing preparation-snapshot limitation, is documented, and did not regress with this change. ## What changed <!-- Include affected package IDs and generated outputs. --> - `long-term-memory` 1.3.22: new `candidate-reconciliation.ts` runs a bounded, deterministic post-extraction reconciliation for `timeline_event`, `thread`, `world_fact`, `tone`, and `anchor` candidates before target resolution. Exactly one in-scope compatible match reuses that note; no match still creates; several plausible matches stay unattached and require review (`candidate_reconciliation_ambiguous`), so an ambiguous duplicate is never created or auto-applied. - Matching stays code-owned and out of the provider prompt: identity (title/subject names/subject keys) first, then section-text similarity. Character and relationship candidates remain owned by `subject-identity.ts` and `scoped-targets.ts`. - `retrieval.ts` gains optional `noteTypes` (pre-budget type filter so unrelated chunks cannot crowd a bounded window) and `dedupeExactText` (reconciliation keeps identical-text notes visible as a genuine ambiguity). `scoped-targets.ts` exports `remapEvidenceUnitTargets` plus a reachability guard so a match never compiles against a different new note. `source-processing.ts` forces review when a reconciliation ambiguity is present. - Generated outputs rebuilt from source: `server.mjs`, `manifest.json` (1.3.22), `artifacts/long-term-memory-1.3.22.zip`, catalog lanes v2/v3 and legacy, and `catalog/notes.json`. - Tests: new `tests/long-term-memory-candidate-reconciliation.regression.ts` and `tests/long-term-memory-reconciliation-recall.regression.ts`; `tests/README.md` ownership table updated. - Review follow-up: `retrieval.ts` now reports truncation per ranked note, so chunk-budget drops of a note already inside the window no longer mark reconciliation incomplete, and `candidate-reconciliation.ts` warns `candidate_reconciliation_incomplete` when an incomplete window shows compatible candidates but no match, instead of compiling a create blind. Two regression cases added and verified red before the fix. ## Package and security impact - Affected package IDs: `long-term-memory` - Engine compatibility impact: none. Engine range is unchanged (`min` 2.4.1, `maxExclusive` 4.0.0) and `engine-boundary.json` is unchanged — no new private Engine imports. - New or changed permissions/entrypoints: none; permissions and entrypoints are unchanged. - Restart, storage, update, or uninstall impact: `restartRequired` unchanged, no schema or migration change. The pass adds a draft diagnostic and can set a draft to review-required. ## Validation <!-- These are human tasks. Never tick a box for a check that was not actually performed. --> - [ ] `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 <!-- Describe exactly what you tested, step by step. --> - Baseline revision `d29e32ce` (`upstream/staging`); change HEAD `7216fa81` (feature work `8127b34c`, review repair `4d82ace9`, merged with `staging` through origin's `60d7cd73`). Engine `41d5d12`. - `node scripts/typecheck-packages.mjs long-term-memory`, `npm run check`, and `git diff --check` pass. - Repository gates pass on the rebuilt tree: `node scripts/test-catalog-lanes.mjs`, `node scripts/validate-package-locales.mjs`, `node scripts/validate-catalog.mjs` (38 packages; v2=38, v3=38, legacy=v2), and `node scripts/tests/catalog-release-notes.regression.mjs`. - Rebuilt with `node scripts/build-feature-packages.mjs long-term-memory`; the 1.3.22 payload and catalog entry are regenerated from source (no hand-edited bundles, hashes, or sizes). - 17 affected LTM regressions pass against the rebuilt tree with `MARINARA_AGENTS_ROOT`/`MARINARA_ENGINE_ROOT` set: storage, extraction-graph, extraction-reliability, runtime, conversation-summary-import, scope-targets, scope-fallback-labels, local-characters, review-queue-ambiguous-link, source-task, index-keys, debug-log, routes, routes-scope-identity, candidate-reconciliation, reconciliation-recall, and installation (exact ZIP install). - Publish proof: tested inputs captured on HEAD and re-verified unchanged before push with `assertPublishProof` (repository digest `58d13c3b04bbe50c775786af999f405da1609a6c36f0de5c41ff44672013f51a`, engine digest `16d84b2dc18c246dfa4f271f11933260bc1b09fa82392ec02a89f0fb40519d09`). - Not run: browser and lifecycle suites (Playwright); hosted CI. Those remain unverified. ## Documentation impact - [ ] No documentation changes needed - [ ] Updated this README catalog and package guidance - [ ] Updated linked Marinara Engine documentation ## UI evidence (if applicable) <!-- Add before/after screenshots or recordings for package UI changes. --> No UI changes in this PR. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Long-Term Memory version 1.3.22 reuses an existing memory when an extracted candidate refers to the same subject, helping prevent duplicate notes. * **Bug Fixes** * When a candidate could match multiple existing memories, it is left unattached and flagged for review instead of being applied automatically. * Candidates are also left unattached for review when the available search results may be incomplete, preventing uncertain matches from being applied automatically. <!-- 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:07: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#1288
No description provided.