[PR #1445] [MERGED] fix(long-term-memory): expire accepted receipt ids and invalidated drafts (1.4.48) #1465

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

📋 Pull Request Information

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

Base: staging ← Head: fix(long-term-memory)/1443-retention-followups


📝 Commits (4)

  • 1e89422 fix(long-term-memory): expire accepted receipt ids and invalidated drafts (#1443)
  • e97f5c9 Merge upstream/staging into fix(long-term-memory)/1443-retention-followups; release long-term-memory 1.4.48
  • fb929fe fix(long-term-memory): stop checking the unused usageRetentionDays against the audit window (#1443)
  • af916a6 Merge branch 'staging' into fix(long-term-memory)/1443-retention-followups

📊 Changes

17 files changed (+169 additions, -142 deletions)

View changed files

➕ artifacts/long-term-memory-1.4.48.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 (+6 -0)
📝 packages/long-term-memory/client.js (+1 -1)
📝 packages/long-term-memory/manifest.json (+5 -5)
📝 packages/long-term-memory/server.mjs (+39 -39)
📝 packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/default-config.ts (+1 -0)
📝 packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/retention.ts (+16 -31)
📝 packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/storage.ts (+0 -17)
📝 packages/long-term-memory/src/engine/packages/shared/src/features/agents/long-term-memory/schema.ts (+2 -1)
📝 scripts/build-feature-packages.mjs (+1 -1)
📝 tests/long-term-memory-storage.regression.ts (+56 -5)

📄 Description

Linked issue

Closes #1443

Why this change

#1404 (1.4.42) stopped writing per-memory usage counters and started deleting finished drafts. Three things were left:

  • Dead cleanup code. Retention and permanent delete still pruned usage counters that nothing writes any more. Old counters stayed in vaults that hadn't injected a memory since the update, because only an injection cleared them.
  • Accepted receipt ids were kept for 180 days. usage.json gains one id per injected reply and is read and rewritten under the vault lock on every one of those replies. A copy of a real vault held 810 ids (about 55 KB) after about 2.5 weeks. The ids only stop the same prepared prompt from being recorded twice, and Engine ignores the result (long-term-memory-runtime.ts:138-148 at 2039583ca only logs a failure).
  • Invalidated drafts were never deleted. A draft is invalidated when the memory or detail it targets is deleted. It can't be applied, and Review only offers "Discard". Drafts nobody discarded stayed forever and were read on every draft listing.

What changed

  • retention.ts, step 2:
    • The usage.chats loop is replaced with: if usage.chats has any entries, set it to {}. The usageChatsPruned result field is removed; nothing read it.
    • acceptedReceipts entries expire after ACCEPTED_RECEIPT_RETENTION_MS (one day, beside RETENTION_INTERVAL_MS) instead of receiptRetentionDays. Retention runs at most daily, so an id lives one to two days. The duplicate check in usage.ts is unchanged.
    • Step 3's per-chat receipt files keep receiptRetentionDays, because each holds that chat's last recall.
  • retention.ts, step 6: invalidated joins the statuses deleted after auditWindowDays (30 days by default). Invalidation sets updatedAt, so the window counts from the invalidation. Pending drafts are still kept. The set is renamed EXPIRING_DRAFT_STATUSES, because "finished" no longer describes it.
  • storage.ts: permanent delete no longer reads or rewrites usage.json.
  • usageRetentionDays stays in the settings schema and defaults, with a comment, so older settings files and backups still parse. It is no longer checked against auditWindowDays (CodeRabbit repair, fb929fe80), so an audit window over 180 days no longer fails validation unless that unused setting is raised too.
  • long-term-memory 1.4.48: CHANGELOG entry, version, manifest, rebuilt server.mjs, artifact and catalog entries. The branch was merged with upstream/staging (1.4.47, #1444) at land, with no source conflicts.

Diff: source +25/−48 lines (including the CHANGELOG), tests +56/−5 lines, before the release merge.

Not in this PR: the per-chat receipt files and their 180-day window. There is one small file per chat, and it holds that chat's last recall.

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:
    • Storage: the first retention run after the update rewrites usage.json once, without old counters and with only the last day's accepted ids. It also deletes invalidated drafts older than the audit window. Nothing else in the vault changes.
    • Data loss: the deleted data has no reader. The counters haven't been read since 1.4.42. An accepted id matters only for a repeat of the same dispatch, which arrives within moments. An invalidated draft can only be discarded. A Review screen left open across a retention run can get a 404 on "Discard" for a draft retention just removed. The draft is gone either way.
    • Merge danger: one-way for the deleted counters, ids and drafts, which a rollback can't restore. The code itself rolls back cleanly.

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 in tests/long-term-memory-storage.regression.ts, beside the #1404 retention cases:
    • An invalidated draft older than the audit window is removed, and a recent one is kept. An old pending draft is kept.
    • Retention clears leftover usage counters, however recent. It removes an accepted id older than one day and keeps one from today.
    • A permanent delete leaves usage.json byte-for-byte unchanged.
  • Before the fix: each new case failed on the unfixed source. Three drafts were removed instead of four, the counter and the day-old id were kept, and permanent delete rewrote usage.json.
  • On source commit 1e894227f, these passed: test-ltm.sh storage, index-keys, runtime, routes and routes-drafts.
  • Schema repair: a temporary probe showed that { auditWindowDays: 365 } with every used retention period at 365 failed to parse before the repair and parses after it. A receipt period shorter than the window is still rejected. The probe was deleted.
  • On release HEAD fb929fe80 (after merging 1.4.47 and the 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 storage, index-keys, runtime, routes and routes-drafts, plus branch-recall.
  • Not done: a live retention run in Engine, and test-ltm.sh installation for the 1.4.48 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

Summary by CodeRabbit

  • Updates
    • Updated Long-Term Memory to version 1.4.48.
  • Maintenance
    • Invalidated drafts are cleaned up after the audit window; pending drafts remain.
    • Reply deduplication IDs are retained for 24 hours, and legacy usage counters are cleared during daily cleanup.
    • Permanently deleting a memory no longer changes usage records.
    • Audit windows longer than 180 days no longer require adjusting the legacy usage-retention setting.

🔄 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/1445 **Author:** [@Promansis](https://github.com/Promansis) **Created:** 10/17/2026 **Status:** ✅ Merged **Merged:** 10/17/2026 **Merged by:** [@Promansis](https://github.com/Promansis) **Base:** `staging` ← **Head:** `fix(long-term-memory)/1443-retention-followups` --- ### 📝 Commits (4) - [`1e89422`](https://github.com/Pasta-Devs/Marinara-Agents/commit/1e894227f8947f1b84660657515c5febf65dab50) fix(long-term-memory): expire accepted receipt ids and invalidated drafts (#1443) - [`e97f5c9`](https://github.com/Pasta-Devs/Marinara-Agents/commit/e97f5c9c3df2613d9f15485dab3cdaafd1a31d93) Merge upstream/staging into fix(long-term-memory)/1443-retention-followups; release long-term-memory 1.4.48 - [`fb929fe`](https://github.com/Pasta-Devs/Marinara-Agents/commit/fb929fe803cf9edd8a409876d6e5ede710e80f0e) fix(long-term-memory): stop checking the unused usageRetentionDays against the audit window (#1443) - [`af916a6`](https://github.com/Pasta-Devs/Marinara-Agents/commit/af916a6cd40cd90187cedf2458f9703b12a899aa) Merge branch 'staging' into fix(long-term-memory)/1443-retention-followups ### 📊 Changes **17 files changed** (+169 additions, -142 deletions) <details> <summary>View changed files</summary> ➕ `artifacts/long-term-memory-1.4.48.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` (+6 -0) 📝 `packages/long-term-memory/client.js` (+1 -1) 📝 `packages/long-term-memory/manifest.json` (+5 -5) 📝 `packages/long-term-memory/server.mjs` (+39 -39) 📝 `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/default-config.ts` (+1 -0) 📝 `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/retention.ts` (+16 -31) 📝 `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/storage.ts` (+0 -17) 📝 `packages/long-term-memory/src/engine/packages/shared/src/features/agents/long-term-memory/schema.ts` (+2 -1) 📝 `scripts/build-feature-packages.mjs` (+1 -1) 📝 `tests/long-term-memory-storage.regression.ts` (+56 -5) </details> ### 📄 Description ## Linked issue Closes #1443 ## Why this change #1404 (1.4.42) stopped writing per-memory usage counters and started deleting finished drafts. Three things were left: - **Dead cleanup code.** Retention and permanent delete still pruned usage counters that nothing writes any more. Old counters stayed in vaults that hadn't injected a memory since the update, because only an injection cleared them. - **Accepted receipt ids were kept for 180 days.** `usage.json` gains one id per injected reply and is read and rewritten under the vault lock on every one of those replies. A copy of a real vault held 810 ids (about 55 KB) after about 2.5 weeks. The ids only stop the same prepared prompt from being recorded twice, and Engine ignores the result (`long-term-memory-runtime.ts:138-148` at 2039583ca only logs a failure). - **Invalidated drafts were never deleted.** A draft is invalidated when the memory or detail it targets is deleted. It can't be applied, and Review only offers "Discard". Drafts nobody discarded stayed forever and were read on every draft listing. ## What changed - `retention.ts`, step 2: - The `usage.chats` loop is replaced with: if `usage.chats` has any entries, set it to `{}`. The `usageChatsPruned` result field is removed; nothing read it. - `acceptedReceipts` entries expire after `ACCEPTED_RECEIPT_RETENTION_MS` (one day, beside `RETENTION_INTERVAL_MS`) instead of `receiptRetentionDays`. Retention runs at most daily, so an id lives one to two days. The duplicate check in `usage.ts` is unchanged. - Step 3's per-chat receipt files keep `receiptRetentionDays`, because each holds that chat's last recall. - `retention.ts`, step 6: `invalidated` joins the statuses deleted after `auditWindowDays` (30 days by default). Invalidation sets `updatedAt`, so the window counts from the invalidation. Pending drafts are still kept. The set is renamed `EXPIRING_DRAFT_STATUSES`, because "finished" no longer describes it. - `storage.ts`: permanent delete no longer reads or rewrites `usage.json`. - `usageRetentionDays` stays in the settings schema and defaults, with a comment, so older settings files and backups still parse. It is no longer checked against `auditWindowDays` (CodeRabbit repair, `fb929fe80`), so an audit window over 180 days no longer fails validation unless that unused setting is raised too. - `long-term-memory` 1.4.48: CHANGELOG entry, version, manifest, rebuilt `server.mjs`, artifact and catalog entries. The branch was merged with `upstream/staging` (1.4.47, #1444) at land, with no source conflicts. Diff: source +25/−48 lines (including the CHANGELOG), tests +56/−5 lines, before the release merge. Not in this PR: the per-chat receipt files and their 180-day window. There is one small file per chat, and it holds that chat's last recall. ## 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: - **Storage:** the first retention run after the update rewrites `usage.json` once, without old counters and with only the last day's accepted ids. It also deletes invalidated drafts older than the audit window. Nothing else in the vault changes. - **Data loss:** the deleted data has no reader. The counters haven't been read since 1.4.42. An accepted id matters only for a repeat of the same dispatch, which arrives within moments. An invalidated draft can only be discarded. A Review screen left open across a retention run can get a 404 on "Discard" for a draft retention just removed. The draft is gone either way. - **Merge danger:** one-way for the deleted counters, ids and drafts, which a rollback can't restore. The code itself rolls back cleanly. ## 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** in `tests/long-term-memory-storage.regression.ts`, beside the #1404 retention cases: - An invalidated draft older than the audit window is removed, and a recent one is kept. An old pending draft is kept. - Retention clears leftover usage counters, however recent. It removes an accepted id older than one day and keeps one from today. - A permanent delete leaves `usage.json` byte-for-byte unchanged. - **Before the fix:** each new case failed on the unfixed source. Three drafts were removed instead of four, the counter and the day-old id were kept, and permanent delete rewrote `usage.json`. - On source commit `1e894227f`, these passed: `test-ltm.sh storage`, `index-keys`, `runtime`, `routes` and `routes-drafts`. - **Schema repair:** a temporary probe showed that `{ auditWindowDays: 365 }` with every used retention period at 365 failed to parse before the repair and parses after it. A receipt period shorter than the window is still rejected. The probe was deleted. - On release HEAD `fb929fe80` (after merging 1.4.47 and the 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 storage`, `index-keys`, `runtime`, `routes` and `routes-drafts`, plus `branch-recall`. - Not done: a live retention run in Engine, and `test-ltm.sh installation` for the 1.4.48 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) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Updates** - Updated Long-Term Memory to version 1.4.48. - **Maintenance** - Invalidated drafts are cleaned up after the audit window; pending drafts remain. - Reply deduplication IDs are retained for 24 hours, and legacy usage counters are cleared during daily cleanup. - Permanently deleting a memory no longer changes usage records. - Audit windows longer than 180 days no longer require adjusting the legacy usage-retention setting. <!-- 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:47 +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#1465
No description provided.