[GH-ISSUE #1328] [Issue]: Long-Term Memory: robustness clean-up from the 1.4.8 architecture audit #677

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

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

Originally assigned to: @Promansis on GitHub.

Summary

Five robustness fixes left over from a read-only architecture audit of Long-Term Memory 1.4.8, rechecked against 1.4.28:

  1. "Delete all data" leaves full copies of the memory folder behind.
  2. Extraction stops working for good once 10,000 rejected suggestions are stored.
  3. One malformed memory, usage.json or receipt file can stop recall or activation.
  4. Every out-of-date recall index is kept as a full quarantine copy for 90 days.
  5. Merging duplicate memories leaves rejected suggestions pointing at the archived duplicate.

None of these change recall scoring or extraction output. They ship together as one release, one commit per fix.

Affected package

long-term-memory 1.4.28, under packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/:

  • identity-repair.ts, note-fork-repair.ts, backup-restore.ts
  • rejected-suggestions.ts
  • runtime.ts, usage.ts, storage.ts, rebuild.ts

Expected behavior

  1. "Delete all data" removes every copy of the user's memories the package wrote, including identity-repair and fork-repair backups, and those backups do not pile up.
  2. Extraction keeps working after many rejected suggestions. The least recently seen ones make room for new ones; saved identity decisions are never dropped.
  3. A malformed memory, usage.json or injection receipt does not stop the package from activating or from recalling the other memories. Writes still refuse to run over a vault they cannot fully read.
  4. An index that is only out of date is rebuilt in place. Only an unreadable index is quarantined.
  5. Identity repair and fork repair redirect rejected suggestions to the surviving memory, as renaming a memory already does.

Actual behavior

  1. Repair backups. createLtmIdentityRepairBackup (identity-repair.ts:167-185) and applyLtmNoteForkRepair (note-fork-repair.ts:216-219) copy the whole memory folder into <dataDir>/backups/long-term-memory-{identity-repairs,forks}/<uuid>/. The copy only serves the rollback inside that call; nothing reads or prunes it afterwards. deleteAllLongTermMemoryData (backup-restore.ts:186) replaces the memory folder only, so these copies survive "Delete all data".
  2. Rejected-suggestion cap. addRejectedSuggestions throws "rejected-suggestion limit reached" once the file holds 10,000 entries (rejected-suggestions.ts:230-231). It runs from the draft store's afterWrite hook (draft-store.ts:239), after the new draft is written and older drafts are superseded, so every later extraction that rejects anything fails until suggestions are deleted by hand.
  3. Unreadable files.
    • selfCheck validates usage.json and every injection receipt at activation (runtime.ts:22-23). One malformed file stops activation, and the Engine rolls the package back (the failure class 1.3.34 fixed for vault notes).
    • Recall's index load and rebuild read every note through listNotes() (rebuild.ts:132, :211), which throws on the first note that fails validation (storage.ts:240-241). ltmNoteSchema is .strict(), so a note written by a newer version with one extra field makes recall fail on every turn after a downgrade, until maintenance quarantines the note.
  4. Stale index copies. loadOrRebuildLongTermMemoryIndexes signals an out-of-date index by throwing "Stale long-term memory recall index." (rebuild.ts:216), and the shared catch quarantines it (rebuild.ts:230). Every memory edit followed by a recall moves a full recall.json (31 MB at 2,000 memories with 384-dimension vectors in the audit's measurement) into quarantine/indexes/, where retention keeps it for 90 days.
  5. Merge redirects. redirectReferences (storage.ts:735-816), used by identity repair and fork repair, rewrites links, section contributions and drafts but not rejected suggestions. renameNoteId does (storage.ts:900-915, via rewriteRejectedSuggestions). After a repair, a rejected suggestion whose source.sourceNoteId or candidate.recovery.noteId named the archived duplicate still names it.

Steps to reproduce

  1. Run an identity repair or a fork repair from Memory Settings, then Delete all data. <dataDir>/backups/long-term-memory-identity-repairs/ (or long-term-memory-forks/) still holds the old memory folder.
  2. Fill config/rejected-suggestions.json to 10,000 entries, then import a source that produces one rejected candidate. The extraction fails with "rejected-suggestion limit reached", and keeps failing.
  3. Add "futureField": true to one vault note's JSON and send a chat turn: recall fails. Separately, write not json to indexes/usage.json and restart: the package does not activate.
  4. Edit any memory's tags, then send a chat turn. quarantine/indexes/ gains a full copy of recall.json.
  5. Reject a suggestion whose recovery targets memory X, merge X into Y with identity repair, then open Review Queue: the suggestion still targets the archived X.

Environment

  • Marinara Engine version: 2.5.0 line (staging)
  • Package version: long-term-memory 1.4.28 (upstream/staging eea2a33f9)
  • Install type: source (code review; the audit measured recall against the package's real modules)
  • OS + version: not platform-specific
  • Browser or app shell: any

Logs, screenshots, or video

Not applicable; line references are against eea2a33f9.

Additional context

Minimal changes, one commit each:

  1. Repair backups. Add one pruneLtmRepairBackups(directory, keep = 3) helper beside getLtmIdentityRepairBackupsRoot that removes all but the newest keep backup folders by mtime, like the quarantine sweep in retention.ts:93-100. Call it after a successful applyLtmIdentityRepairs and applyLtmNoteForkRepair. In deleteAllLongTermMemoryData, remove both backup folders after the replace succeeds. Regression (long-term-memory-storage.regression.ts): a fourth repair leaves three backups; Delete all data leaves none.
  2. Rejected-suggestion cap. In addRejectedSuggestions, when a new entry would pass the limit, drop the least recently seen entries without identityResolution instead of throwing; throw only when every entry holds a saved identity decision. Regression (long-term-memory-storage.regression.ts): at the limit, adding one evicts the oldest unresolved entry and keeps resolved entries.
  3. Unreadable files.
    • Remove validateLongTermMemoryUsage and validateLongTermMemoryInjectionReceipts from selfCheck and delete both. A malformed receipt then only affects that chat's last-injection panel. In readLongTermMemoryUsage, quarantine a malformed usage.json with the existing quarantineLtmIndexArtifact (the file lives in indexes/) and start from empty; it only holds per-chat injection stats and the receipt de-duplication list.
    • Add a skipInvalid option to listNotes that skips notes failing validation and logs how many, and use it only for the two recall-index reads in rebuild.ts. Every other full read, including every write, keeps throwing, so no mutation silently skips a memory. Vault health and maintenance already report and quarantine invalid notes.
    • Regression (long-term-memory-storage.regression.ts, long-term-memory-runtime.regression.ts): activation succeeds with a malformed usage file and receipt; recall returns the valid memories while one note has an unknown field.
  4. Stale index copies. In loadOrRebuildLongTermMemoryIndexes, skip quarantineLtmIndexArtifact when the index parsed but its sourceHash is out of date; the rebuild's atomic write replaces it. An unreadable or malformed index is still quarantined. Regression (long-term-memory-runtime.regression.ts): a stale index rebuilds without adding to quarantine/indexes/; a corrupt one still does.
  5. Merge redirects. Move the rejected-suggestion mapper out of renameNoteId into a shared helper, and call rewriteRejectedSuggestions from redirectReferences too, adding its file to the same commitLtmMutation. Regression (long-term-memory-delta-review.regression.ts): after a fork repair, a rejected suggestion that named the archived note names the canonical note.

Out of scope:

  • Settings files still fail activation on an unknown field. long-term-memory-storage.regression.ts:284-291 pins that ("self-check must reject malformed settings"), so changing it needs its own decision.
  • redirectReferences and renameNoteId both fail on a draft file that is not valid JSON. The repair rolls back from its backup, so nothing is lost.
  • Recall cost growing with vault size and full re-embedding after every edit (audit findings 1 and 2) belong in a separate performance issue, after measuring realistic vault sizes.

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @Promansis on GitHub (Oct 12, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1328 Originally assigned to: @Promansis on GitHub. ## Summary Five robustness fixes left over from a read-only architecture audit of Long-Term Memory 1.4.8, rechecked against 1.4.28: 1. "Delete all data" leaves full copies of the memory folder behind. 2. Extraction stops working for good once 10,000 rejected suggestions are stored. 3. One malformed memory, `usage.json` or receipt file can stop recall or activation. 4. Every out-of-date recall index is kept as a full quarantine copy for 90 days. 5. Merging duplicate memories leaves rejected suggestions pointing at the archived duplicate. None of these change recall scoring or extraction output. They ship together as one release, one commit per fix. ## Affected package `long-term-memory` 1.4.28, under `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/`: - `identity-repair.ts`, `note-fork-repair.ts`, `backup-restore.ts` - `rejected-suggestions.ts` - `runtime.ts`, `usage.ts`, `storage.ts`, `rebuild.ts` ## Expected behavior 1. "Delete all data" removes every copy of the user's memories the package wrote, including identity-repair and fork-repair backups, and those backups do not pile up. 2. Extraction keeps working after many rejected suggestions. The least recently seen ones make room for new ones; saved identity decisions are never dropped. 3. A malformed memory, `usage.json` or injection receipt does not stop the package from activating or from recalling the other memories. Writes still refuse to run over a vault they cannot fully read. 4. An index that is only out of date is rebuilt in place. Only an unreadable index is quarantined. 5. Identity repair and fork repair redirect rejected suggestions to the surviving memory, as renaming a memory already does. ## Actual behavior 1. **Repair backups.** `createLtmIdentityRepairBackup` (`identity-repair.ts:167-185`) and `applyLtmNoteForkRepair` (`note-fork-repair.ts:216-219`) copy the whole memory folder into `<dataDir>/backups/long-term-memory-{identity-repairs,forks}/<uuid>/`. The copy only serves the rollback inside that call; nothing reads or prunes it afterwards. `deleteAllLongTermMemoryData` (`backup-restore.ts:186`) replaces the memory folder only, so these copies survive "Delete all data". 2. **Rejected-suggestion cap.** `addRejectedSuggestions` throws "rejected-suggestion limit reached" once the file holds 10,000 entries (`rejected-suggestions.ts:230-231`). It runs from the draft store's `afterWrite` hook (`draft-store.ts:239`), after the new draft is written and older drafts are superseded, so every later extraction that rejects anything fails until suggestions are deleted by hand. 3. **Unreadable files.** - `selfCheck` validates `usage.json` and every injection receipt at activation (`runtime.ts:22-23`). One malformed file stops activation, and the Engine rolls the package back (the failure class 1.3.34 fixed for vault notes). - Recall's index load and rebuild read every note through `listNotes()` (`rebuild.ts:132`, `:211`), which throws on the first note that fails validation (`storage.ts:240-241`). `ltmNoteSchema` is `.strict()`, so a note written by a newer version with one extra field makes recall fail on every turn after a downgrade, until maintenance quarantines the note. 4. **Stale index copies.** `loadOrRebuildLongTermMemoryIndexes` signals an out-of-date index by throwing "Stale long-term memory recall index." (`rebuild.ts:216`), and the shared `catch` quarantines it (`rebuild.ts:230`). Every memory edit followed by a recall moves a full `recall.json` (31 MB at 2,000 memories with 384-dimension vectors in the audit's measurement) into `quarantine/indexes/`, where retention keeps it for 90 days. 5. **Merge redirects.** `redirectReferences` (`storage.ts:735-816`), used by identity repair and fork repair, rewrites links, section contributions and drafts but not rejected suggestions. `renameNoteId` does (`storage.ts:900-915`, via `rewriteRejectedSuggestions`). After a repair, a rejected suggestion whose `source.sourceNoteId` or `candidate.recovery.noteId` named the archived duplicate still names it. ## Steps to reproduce 1. Run an identity repair or a fork repair from Memory Settings, then Delete all data. `<dataDir>/backups/long-term-memory-identity-repairs/` (or `long-term-memory-forks/`) still holds the old memory folder. 2. Fill `config/rejected-suggestions.json` to 10,000 entries, then import a source that produces one rejected candidate. The extraction fails with "rejected-suggestion limit reached", and keeps failing. 3. Add `"futureField": true` to one vault note's JSON and send a chat turn: recall fails. Separately, write `not json` to `indexes/usage.json` and restart: the package does not activate. 4. Edit any memory's tags, then send a chat turn. `quarantine/indexes/` gains a full copy of `recall.json`. 5. Reject a suggestion whose recovery targets memory X, merge X into Y with identity repair, then open Review Queue: the suggestion still targets the archived X. ## Environment - Marinara Engine version: 2.5.0 line (`staging`) - Package version: long-term-memory 1.4.28 (`upstream/staging` eea2a33f9) - Install type: source (code review; the audit measured recall against the package's real modules) - OS + version: not platform-specific - Browser or app shell: any ## Logs, screenshots, or video Not applicable; line references are against eea2a33f9. ## Additional context Minimal changes, one commit each: 1. **Repair backups.** Add one `pruneLtmRepairBackups(directory, keep = 3)` helper beside `getLtmIdentityRepairBackupsRoot` that removes all but the newest `keep` backup folders by mtime, like the quarantine sweep in `retention.ts:93-100`. Call it after a successful `applyLtmIdentityRepairs` and `applyLtmNoteForkRepair`. In `deleteAllLongTermMemoryData`, remove both backup folders after the replace succeeds. Regression (`long-term-memory-storage.regression.ts`): a fourth repair leaves three backups; Delete all data leaves none. 2. **Rejected-suggestion cap.** In `addRejectedSuggestions`, when a new entry would pass the limit, drop the least recently seen entries without `identityResolution` instead of throwing; throw only when every entry holds a saved identity decision. Regression (`long-term-memory-storage.regression.ts`): at the limit, adding one evicts the oldest unresolved entry and keeps resolved entries. 3. **Unreadable files.** - Remove `validateLongTermMemoryUsage` and `validateLongTermMemoryInjectionReceipts` from `selfCheck` and delete both. A malformed receipt then only affects that chat's last-injection panel. In `readLongTermMemoryUsage`, quarantine a malformed `usage.json` with the existing `quarantineLtmIndexArtifact` (the file lives in `indexes/`) and start from empty; it only holds per-chat injection stats and the receipt de-duplication list. - Add a `skipInvalid` option to `listNotes` that skips notes failing validation and logs how many, and use it only for the two recall-index reads in `rebuild.ts`. Every other full read, including every write, keeps throwing, so no mutation silently skips a memory. Vault health and maintenance already report and quarantine invalid notes. - Regression (`long-term-memory-storage.regression.ts`, `long-term-memory-runtime.regression.ts`): activation succeeds with a malformed usage file and receipt; recall returns the valid memories while one note has an unknown field. 4. **Stale index copies.** In `loadOrRebuildLongTermMemoryIndexes`, skip `quarantineLtmIndexArtifact` when the index parsed but its `sourceHash` is out of date; the rebuild's atomic write replaces it. An unreadable or malformed index is still quarantined. Regression (`long-term-memory-runtime.regression.ts`): a stale index rebuilds without adding to `quarantine/indexes/`; a corrupt one still does. 5. **Merge redirects.** Move the rejected-suggestion mapper out of `renameNoteId` into a shared helper, and call `rewriteRejectedSuggestions` from `redirectReferences` too, adding its file to the same `commitLtmMutation`. Regression (`long-term-memory-delta-review.regression.ts`): after a fork repair, a rejected suggestion that named the archived note names the canonical note. Out of scope: - Settings files still fail activation on an unknown field. `long-term-memory-storage.regression.ts:284-291` pins that ("self-check must reject malformed settings"), so changing it needs its own decision. - `redirectReferences` and `renameNoteId` both fail on a draft file that is not valid JSON. The repair rolls back from its backup, so nothing is lost. - Recall cost growing with vault size and full re-embedding after every edit (audit findings 1 and 2) belong in a separate performance issue, after measuring realistic vault sizes. ## Template check - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-20 17:29:39 +07:00
  • closed this issue
  • added the
    bug
    label
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#677
No description provided.