mirror of
https://github.com/Pasta-Devs/Marinara-Agents.git
synced 2026-12-03 18:55:07 +07:00
[GH-ISSUE #1404] [Issue]: Long-Term Memory: finished drafts are never deleted, and every reply rewrites usage counters nothing reads #713
Labels
No labels
agent: chess
agent: conversation-calls
agent: eightball
agent: haptic
agent: hierarchical-maps
agent: hierarchical-maps
agent: illustrator
agent: poker
agent: rock-paper-scissors
agent: tic-tac-toe
agent: uno
artifacts
bug
bugfix
build
catalog
ci
client
dependencies
docs
documentation
enhancement
feature
fixed-in-staging
in-pr
normal-scope
packages
pull-request
qol
regression
roadmap
scope-risk
server
soup
upstream
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Agents#713
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Promansis on GitHub (Oct 15, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1404
Originally assigned to: @Promansis on GitHub.
Summary
Two Long-Term Memory stores grow with use and are read in full on frequent paths:
usage.jsonis rewritten whole on every reply that injects memories. Each time it gains per-chat, per-memory counters under the vault lock. Nothing reads those counters except the code that expires and deletes them.This is the remainder of finding 4 from the 1.4.8 architecture audit. #1328 (1.4.29) fixed the other parts: repair backups and the rejected-suggestion cap.
Affected package
long-term-memory1.4.38 (upstream/stagingeb4af30d0), underpackages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/:draft-store.ts:listDrafts(270-292) reads and validates every draft file, then filters by status.retention.ts:runLongTermMemoryRetentionUnsafe. Its five steps (131-226) prune quarantine, usage, receipts, events and incomplete generations, but not drafts.usage.ts:recordLongTermMemoryInjection(107-160).usage.chatsare retention step 2 (retention.ts:144-178) and the permanent-delete cleanup (storage.ts:1299-1311).Expected behavior
Actual behavior
pending,accepted,auto_applied,supersededorinvalidated./drafts/pending-count, and/drafts/review?includeInvalidated=truefrom Review and Activity).draft-store.ts:406,routes.ts:1630). Retention never deletes drafts.listDraftsparses every file before filtering. It runs on:/status;/drafts/pending-count, fetched when the screen opens (LongTermMemoryDetail.tsx:56);supersedeOlderPendingDrafts,draft-store.ts:243-244);storage.ts:556).usage.json.recordLongTermMemoryInjection(usage.ts:114-143), under the vault lock that recall also takes:retrievalCount,injectionCount,totalInjectedTokens,lastRetrievedAtandlastInjectedAtfor every injected memory in that chat;acceptedReceipts;usageRetentionDaysandreceiptRetentionDays, both 180 by default.readLongTermMemoryUsageis called only by retention, the permanent-delete cleanup and the writer itself.Measured on one real vault (a read-only copy taken 2026-10-08; aggregate counts only):
drafts/indexes/usage.jsonBoth grow with use: drafts without limit, usage counters for 180 days.
Steps to reproduce
<dataDir>/long-term-memory/drafts/. Every finished draft is still there, including after the daily retention run.indexes/usage.jsongrow. Searching the package forusage.chatsfinds only retention and the delete cleanup.Environment
>=2.4.1 <4.0.0)upstream/stagingeb4af30d0); sizes come from a vault written by earlier 1.4.x releasesLogs, screenshots, or video
See the size table above. It holds aggregate counts only, with no vault content.
Additional context
Minimal fix, one commit each:
runLongTermMemoryRetentionUnsafe. It deletes draft files whose status isaccepted,auto_appliedorsupersededand whoseupdatedAtis older thanconfig.auditWindowDays(30 by default). Reusing that existing retention field leaves the config schema unchanged.pendingandinvalidateddrafts. Count removals in the result, as the other steps do.getDraftalready returnsnullfor a missing file, andsubject-choice-review.ts:51already returnsdraft: nullwhen a resolved identity decision has no draft. Confirm the Review client handlesnullfor a decision whose draft was pruned.tests/long-term-memory-storage.regression.ts, beside the retention cases at 360-410: an accepted and a superseded draft older than the window are removed, while a recent accepted draft, a pending draft and an invalidated draft are kept.recordLongTermMemoryInjection, stop updatingusage.chatsand writechats: {}. That drops the existing counters on the next reply.acceptedReceiptsand the duplicate check as they are, so the dispatch result returned to the Engine does not change.tests/long-term-memory-index-keys.regression.ts:693-715to checkacceptedReceiptsonly.usage.jsonhas no per-memory entries, and a repeated accounting id still returnsnull.Notes:
chats, and an empty object is valid for older versions too.acceptedReceiptsstill gains one id per injected reply forreceiptRetentionDays(about 55 KB in the sample). Shortening that window needs a check of what the Engine does with the dispatch result.Template check
Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked: