[PR #1370] [MERGED] fix(long-term-memory): 1.4.32 — stop re-scanning and re-embedding the whole vault on recall (#1364) #1427

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

📋 Pull Request Information

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

Base: staging ← Head: fix(long-term-memory)/1364-recall-vault-scan


📝 Commits (8)

  • ea55c1c fix(long-term-memory): reuse unchanged vectors when rebuilding the recall index (#1364)
  • 4ffac76 fix(long-term-memory): skip the index rebuild after extraction that applied nothing (#1364)
  • dad761c perf(long-term-memory): reuse the verified recall index until a mutation changes the vault (#1364)
  • 5d5197c chore(long-term-memory): 1.4.32 — rebuild package, changelog and architecture note (#1364)
  • ed7d5b6 Merge upstream/staging into fix(long-term-memory)/1364-recall-vault-scan
  • 645adb3 fix(long-term-memory): state the recall cache's limits and test the dimension fallback (#1364)
  • 8df9cba Merge upstream/staging (LTM 1.4.31) into fix(long-term-memory)/1364-recall-vault-scan
  • 5dd4328 Merge branch 'staging' into fix(long-term-memory)/1364-recall-vault-scan

📊 Changes

21 files changed (+404 additions, -111 deletions)

View changed files

➕ artifacts/long-term-memory-1.4.32.zip (+0 -0)
📝 catalog/catalog.json (+8 -8)
📝 catalog/notes.json (+6 -6)
📝 catalog/v2/catalog.json (+8 -8)
📝 catalog/v2/notes.json (+6 -6)
📝 catalog/v3/catalog.json (+8 -8)
📝 catalog/v3/notes.json (+6 -6)
📝 packages/long-term-memory/CHANGELOG.md (+4 -0)
📝 packages/long-term-memory/client.js (+1 -1)
📝 packages/long-term-memory/docs/ARCHITECTURE.md (+11 -0)
📝 packages/long-term-memory/manifest.json (+5 -5)
📝 packages/long-term-memory/server.mjs (+40 -40)
📝 packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/index-state.ts (+13 -0)
📝 packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/rebuild.ts (+108 -14)
📝 packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/source-processing.ts (+5 -4)
📝 packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/vault-snapshot.ts (+28 -1)
📝 packages/long-term-memory/src/engine/packages/shared/src/features/agents/long-term-memory/schema.ts (+5 -0)
📝 scripts/build-feature-packages.mjs (+1 -1)
📝 tests/long-term-memory-extraction-graph.regression.ts (+15 -1)
📝 tests/long-term-memory-extraction-reliability.regression.ts (+2 -2)

...and 1 more files

📄 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 #1364

Why this change

  • On a large vault, every recall re-read, re-validated and re-hashed every memory, and any edit re-embedded every memory. The issue measured this on 1.4.8 with 2,000 memories and an instant fake embedder: 1.7-1.9 s per recall with an up-to-date index, and 5.0 s after editing one tag.
  • Extraction that applied nothing still rebuilt the recall index.

What changed

long-term-memory 1.4.31 → 1.4.32.

 recall (loadOrRebuildLongTermMemoryIndexes)
+  if this vault has a cached index, the index state is clean,
+     and the revision, recall.json identity and stop words are unchanged
+    return the cached index                         # no vault scan
   parse recall.json, list notes, hash chunks
   if stale → rebuild
+  if fresh but dirty only from unindexed notes → mark verified (revision + 1), then cache

 rebuild (rebuildLongTermMemoryIndexes)
-  embed every chunk
+  reuse the previous index's vectors by textHash when the embedding space matches
+  embed only new texts; a new dimension in the same space → embed everything

 extraction (source-processing.ts, both sites)
-  rebuild when the draft proposed mutations
+  rebuild only when the commit applied mutations
  • textHash is a new optional field on each embedding entry: the sha256 of the embedded text. It ignores tags, scope and status, so editing a tag re-embeds nothing.
  • Every package mutation clears the cache, through the revision bump and invalidateLtmVaultSnapshot. Whole-vault swaps (restore, identity repair, note fork) and malformed-note quarantine clear it too.
  • Generated outputs rebuilt from source: server.mjs, client.js, manifest hashes, artifacts/long-term-memory-1.4.32.zip, catalog/{,v2/,v3/}catalog.json and notes.json.
  • Merges upstream/staging, which brings 1.4.31 from #1362. The changelog keeps the 1.4.31 entry under 1.4.32.

Package and security impact

  • Affected package IDs: long-term-memory
  • Engine compatibility impact: none. The range is unchanged (>=2.4.1 <4.0.0).
  • New or changed permissions/entrypoints: none. Executable server code changes on the recall and rebuild paths; see the validation notes.
  • Restart, storage, update, or uninstall impact:
    • recall.json gains an optional textHash on each embedding entry. The first rebuild after updating re-embeds everything once, because 1.4.30 and 1.4.31 indexes have no textHash.
    • After a downgrade, the older package reads the index as malformed, quarantines it and rebuilds once. The index is derived data, so nothing is lost.
    • Recall can now write the index state: it marks the state verified (revision + 1) when the index is fresh and the state is dirty only because unindexed notes (sources, drafts) changed. As a result, Memory Status can go from "stale" to "healthy" after a recall.

Known limits

  • Notes edited outside Marinara while it runs, or by a second process on the same vault, aren't seen until a restart or the process's next mutation. The vault lock only works within one process. This is marked with a ponytail: comment in rebuild.ts, which also names the upgrade path.
  • With a warm cache, recall alone no longer starts the daily retention run. Any other storage operation, or a restart, still starts it.
  • The first recall in each process, and the first after a rebuild, still run the full check.
  • With an instant embedder, the edit case is not faster: chunking runs twice (about 1.0 s each) and recall.json is parsed three times. A real embedder should benefit from the skipped embeds, but that wasn't measured offline. Removing the double chunking is a possible follow-up.

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

Local run on 8df9cbaff, Node v24.15.0, against Marinara-Engine 2039583ca (clean). The tree was snapshotted before and after the checks, and the two snapshots match.

Check Exit
node scripts/build-feature-packages.mjs long-term-memory (both roots set) 0, no diff
npm run check 0 (0 errors; the warnings were there before this change)
node scripts/test-catalog-lanes.mjs 0
node scripts/validate-package-locales.mjs 0
node scripts/validate-catalog.mjs 0
node scripts/tests/catalog-release-notes.regression.mjs 0
git diff --check upstream/staging...HEAD 0
test-ltm.sh all (every LTM regression, including runtime, extraction-graph and extraction-reliability) 0

New regressions in tests/long-term-memory-runtime.regression.ts:

tag edit                         → 0 re-embeds
text edit                        → 1 re-embed
other embedding space            → all re-embedded
unreadable previous index        → all re-embedded
new dimension in the same space  → all re-embedded, dimension stored
                                   (fails with the fallback disabled: checked by mutation)
extraction that applies nothing  → no rebuild
indexed / unindexed mutation     → cache cleared
stop-word change                 → cache miss
right after a rebuild            → verified once, then cached
  • In long-term-memory-extraction-reliability, one assertion went from 2 note scans to 1. This is the intended step 3 behaviour: no rebuild after an extraction that applies nothing.
  • Write-path audit for the cache:
    • Restore, malformed-note quarantine and delete-all were checked with a scratch script that is not committed.
    • The identity-repair and note-fork swaps were reasoned from the code only.
    • Concurrent mutation from another process was reasoned only (see Known limits).
  • A read-only review found no blocker or high-severity issue. Its 3 low findings, 1 test gap and 2 nits are addressed in 645adb330.
  • Not done:
    • the issue's step 1 timings at 200, 1,000 and 2,000 memories
    • installing or updating the package through Marinara Engine
    • hosted CI (pending)

Documentation impact

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

packages/long-term-memory/docs/ARCHITECTURE.md describes the cache, when it is used, and its limits.

Merge danger

Door: two-way. The index is derived data. Reverting costs one full re-embed, plus one quarantined index per vault.

Blast radius: recall. A stale cached index would mean memories recalled from an older vault state until the next mutation or restart. Every in-process write path clears the cache.

UI evidence (if applicable)

Not applicable: no UI change.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Improvements
    • Long-Term Memory 1.4.32 reuses verified recall indexes, reducing repeat checks of unchanged vaults after the initial check following a restart.
    • When rebuilding indexes, unchanged memory text can reuse existing embeddings; edited text is re-embedded. The first rebuild after updating still processes the full vault.
    • Extraction that applies no changes no longer triggers an index rebuild.

🔄 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/1370 **Author:** [@Promansis](https://github.com/Promansis) **Created:** 10/13/2026 **Status:** ✅ Merged **Merged:** 10/14/2026 **Merged by:** [@Promansis](https://github.com/Promansis) **Base:** `staging` ← **Head:** `fix(long-term-memory)/1364-recall-vault-scan` --- ### 📝 Commits (8) - [`ea55c1c`](https://github.com/Pasta-Devs/Marinara-Agents/commit/ea55c1c6f783cd48772876143fae7baf486af070) fix(long-term-memory): reuse unchanged vectors when rebuilding the recall index (#1364) - [`4ffac76`](https://github.com/Pasta-Devs/Marinara-Agents/commit/4ffac76534f67b70fa9281f16c67ca41e608c6bc) fix(long-term-memory): skip the index rebuild after extraction that applied nothing (#1364) - [`dad761c`](https://github.com/Pasta-Devs/Marinara-Agents/commit/dad761c282e8d6d5144913eef009aeb5f05368f6) perf(long-term-memory): reuse the verified recall index until a mutation changes the vault (#1364) - [`5d5197c`](https://github.com/Pasta-Devs/Marinara-Agents/commit/5d5197c50ecb846631cabce4932cf9127de73f05) chore(long-term-memory): 1.4.32 — rebuild package, changelog and architecture note (#1364) - [`ed7d5b6`](https://github.com/Pasta-Devs/Marinara-Agents/commit/ed7d5b638781ee8279c37f786413f8183bbb4b8e) Merge upstream/staging into fix(long-term-memory)/1364-recall-vault-scan - [`645adb3`](https://github.com/Pasta-Devs/Marinara-Agents/commit/645adb330c62f2472054580af95389a9637817fd) fix(long-term-memory): state the recall cache's limits and test the dimension fallback (#1364) - [`8df9cba`](https://github.com/Pasta-Devs/Marinara-Agents/commit/8df9cbaff67f2987ba2c1afa1f717182f7a5d376) Merge upstream/staging (LTM 1.4.31) into fix(long-term-memory)/1364-recall-vault-scan - [`5dd4328`](https://github.com/Pasta-Devs/Marinara-Agents/commit/5dd4328cc3587f59f9c2d9970cce8bc9db5a785d) Merge branch 'staging' into fix(long-term-memory)/1364-recall-vault-scan ### 📊 Changes **21 files changed** (+404 additions, -111 deletions) <details> <summary>View changed files</summary> ➕ `artifacts/long-term-memory-1.4.32.zip` (+0 -0) 📝 `catalog/catalog.json` (+8 -8) 📝 `catalog/notes.json` (+6 -6) 📝 `catalog/v2/catalog.json` (+8 -8) 📝 `catalog/v2/notes.json` (+6 -6) 📝 `catalog/v3/catalog.json` (+8 -8) 📝 `catalog/v3/notes.json` (+6 -6) 📝 `packages/long-term-memory/CHANGELOG.md` (+4 -0) 📝 `packages/long-term-memory/client.js` (+1 -1) 📝 `packages/long-term-memory/docs/ARCHITECTURE.md` (+11 -0) 📝 `packages/long-term-memory/manifest.json` (+5 -5) 📝 `packages/long-term-memory/server.mjs` (+40 -40) 📝 `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/index-state.ts` (+13 -0) 📝 `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/rebuild.ts` (+108 -14) 📝 `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/source-processing.ts` (+5 -4) 📝 `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/vault-snapshot.ts` (+28 -1) 📝 `packages/long-term-memory/src/engine/packages/shared/src/features/agents/long-term-memory/schema.ts` (+5 -0) 📝 `scripts/build-feature-packages.mjs` (+1 -1) 📝 `tests/long-term-memory-extraction-graph.regression.ts` (+15 -1) 📝 `tests/long-term-memory-extraction-reliability.regression.ts` (+2 -2) _...and 1 more files_ </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 #1364 ## Why this change - On a large vault, every recall re-read, re-validated and re-hashed every memory, and any edit re-embedded every memory. The issue measured this on 1.4.8 with 2,000 memories and an instant fake embedder: 1.7-1.9 s per recall with an up-to-date index, and 5.0 s after editing one tag. - Extraction that applied nothing still rebuilt the recall index. ## What changed `long-term-memory` 1.4.31 → 1.4.32. ```diff recall (loadOrRebuildLongTermMemoryIndexes) + if this vault has a cached index, the index state is clean, + and the revision, recall.json identity and stop words are unchanged + return the cached index # no vault scan parse recall.json, list notes, hash chunks if stale → rebuild + if fresh but dirty only from unindexed notes → mark verified (revision + 1), then cache rebuild (rebuildLongTermMemoryIndexes) - embed every chunk + reuse the previous index's vectors by textHash when the embedding space matches + embed only new texts; a new dimension in the same space → embed everything extraction (source-processing.ts, both sites) - rebuild when the draft proposed mutations + rebuild only when the commit applied mutations ``` - `textHash` is a new optional field on each embedding entry: the sha256 of the embedded text. It ignores tags, scope and status, so editing a tag re-embeds nothing. - Every package mutation clears the cache, through the revision bump and `invalidateLtmVaultSnapshot`. Whole-vault swaps (restore, identity repair, note fork) and malformed-note quarantine clear it too. - Generated outputs rebuilt from source: `server.mjs`, `client.js`, manifest hashes, `artifacts/long-term-memory-1.4.32.zip`, `catalog/{,v2/,v3/}catalog.json` and `notes.json`. - Merges `upstream/staging`, which brings 1.4.31 from #1362. The changelog keeps the 1.4.31 entry under 1.4.32. ## Package and security impact - Affected package IDs: `long-term-memory` - Engine compatibility impact: none. The range is unchanged (`>=2.4.1 <4.0.0`). - New or changed permissions/entrypoints: none. Executable server code changes on the recall and rebuild paths; see the validation notes. - Restart, storage, update, or uninstall impact: - `recall.json` gains an optional `textHash` on each embedding entry. The first rebuild after updating re-embeds everything once, because 1.4.30 and 1.4.31 indexes have no `textHash`. - After a downgrade, the older package reads the index as malformed, quarantines it and rebuilds once. The index is derived data, so nothing is lost. - Recall can now write the index state: it marks the state verified (revision + 1) when the index is fresh and the state is dirty only because unindexed notes (sources, drafts) changed. As a result, Memory Status can go from "stale" to "healthy" after a recall. ### Known limits - Notes edited outside Marinara while it runs, or by a second process on the same vault, aren't seen until a restart or the process's next mutation. The vault lock only works within one process. This is marked with a `ponytail:` comment in `rebuild.ts`, which also names the upgrade path. - With a warm cache, recall alone no longer starts the daily retention run. Any other storage operation, or a restart, still starts it. - The first recall in each process, and the first after a rebuild, still run the full check. - With an instant embedder, the edit case is not faster: chunking runs twice (about 1.0 s each) and `recall.json` is parsed three times. A real embedder should benefit from the skipped embeds, but that wasn't measured offline. Removing the double chunking is a possible follow-up. ## 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 Local run on `8df9cbaff`, Node v24.15.0, against Marinara-Engine `2039583ca` (clean). The tree was snapshotted before and after the checks, and the two snapshots match. | Check | Exit | |---|---| | `node scripts/build-feature-packages.mjs long-term-memory` (both roots set) | 0, no diff | | `npm run check` | 0 (0 errors; the warnings were there before this change) | | `node scripts/test-catalog-lanes.mjs` | 0 | | `node scripts/validate-package-locales.mjs` | 0 | | `node scripts/validate-catalog.mjs` | 0 | | `node scripts/tests/catalog-release-notes.regression.mjs` | 0 | | `git diff --check upstream/staging...HEAD` | 0 | | `test-ltm.sh all` (every LTM regression, including runtime, extraction-graph and extraction-reliability) | 0 | New regressions in `tests/long-term-memory-runtime.regression.ts`: ```text tag edit → 0 re-embeds text edit → 1 re-embed other embedding space → all re-embedded unreadable previous index → all re-embedded new dimension in the same space → all re-embedded, dimension stored (fails with the fallback disabled: checked by mutation) extraction that applies nothing → no rebuild indexed / unindexed mutation → cache cleared stop-word change → cache miss right after a rebuild → verified once, then cached ``` - In `long-term-memory-extraction-reliability`, one assertion went from 2 note scans to 1. This is the intended step 3 behaviour: no rebuild after an extraction that applies nothing. - Write-path audit for the cache: - Restore, malformed-note quarantine and delete-all were checked with a scratch script that is not committed. - The identity-repair and note-fork swaps were reasoned from the code only. - Concurrent mutation from another process was reasoned only (see Known limits). - A read-only review found no blocker or high-severity issue. Its 3 low findings, 1 test gap and 2 nits are addressed in 645adb330. - Not done: - the issue's step 1 timings at 200, 1,000 and 2,000 memories - installing or updating the package through Marinara Engine - hosted CI (pending) ## Documentation impact - [ ] No documentation changes needed - [ ] Updated this README catalog and package guidance - [ ] Updated linked Marinara Engine documentation `packages/long-term-memory/docs/ARCHITECTURE.md` describes the cache, when it is used, and its limits. ## Merge danger **Door:** two-way. The index is derived data. Reverting costs one full re-embed, plus one quarantined index per vault. **Blast radius:** recall. A stale cached index would mean memories recalled from an older vault state until the next mutation or restart. Every in-process write path clears the cache. ## UI evidence (if applicable) Not applicable: no UI change. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Improvements** * Long-Term Memory 1.4.32 reuses verified recall indexes, reducing repeat checks of unchanged vaults after the initial check following a restart. * When rebuilding indexes, unchanged memory text can reuse existing embeddings; edited text is re-embedded. The first rebuild after updating still processes the full vault. * Extraction that applies no changes no longer triggers an index rebuild. <!-- 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:11:18 +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#1427
No description provided.