mirror of
https://github.com/Pasta-Devs/Marinara-Agents.git
synced 2026-12-03 18:55:07 +07:00
[GH-ISSUE #1782] [Feature]: Long-Term Memory: give each chat-messages piece the end of the previous piece, its events and open threads #1751
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#1751
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 27, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1782
Originally assigned to: @Promansis on GitHub.
What problem does this solve?
Importing a chat's messages into Long-Term Memory splits the chat into pieces of about 24k characters and extracts each piece on its own. Each extraction sees only its piece, so two things break where a piece ends:
caused_bylink. The prompt rules forbid targeting a note outside the current response, so the model can't link back.Moving the cut to a scene break does not fix (1): consecutive scenes are usually linked by cause, so a cut exactly between two scenes still drops the link.
Measured on one long roleplay chat (366 messages, about 409k characters) with Sonnet, 2 runs per cut, at two cuts: one mid-scene and one exactly on a scene break.
With context plus threads, piece 2 updated the existing thread (
update_section+add_link) instead of creating a new one. The updated text advanced the thread's state correctly. No units were dropped, and no events from piece 1 were extracted again.Proposed package or change
Package-only change to Long-Term Memory's chat-messages import. No Engine change.
When a
chat_transcriptpiece is extracted and an earlier piece of the same chat exists, pass the model three context-only blocks:id,title), with permission to use them ascaused_by/triggered_bytargets;id,subjectId,title, current text), with the instruction to reuse a listedsubjectIdto update that thread instead of creating a new one.The first piece of a chat, and every non-chat source, keep today's prompt exactly.
Pieces of one chat must be prepared in order, so that piece n can read what piece n−1 committed. Different chats still run in parallel.
Minimal fix
Server, under
packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/:sources/interop.ts. The chat piece builder (aroundtranscriptPiecesand thechat_transcriptitems, ~670–691) records each piece's predecessor: the previous piece's source note id and the tail of itscontent. Piece starts recovered from existing source notes (~746) keep working, because the predecessor is simply the previous item of the same chat inpreviewOrder.extraction/source-processing.tsPrepareOptionsgains an optionalpreviousPiecewith fieldstail,events,threads.processLongTermMemorySourceBatchprepares items that share a chat and have a predecessor after that predecessor commits. Today all items are prepared concurrently, then committed in order. The events and threads are read from the committed vault: notes withextracted_from→ the previous piece's source note id, plus the batch overlay. Reading them from the vault also covers a re-import, where piece n−1 was committed in an earlier run.prepareLongTermMemorySourceforwardspreviousPieceto extraction, and passes the listed events and threads asexistingNotesso that dedup and link closure know them.extraction/evidence-unit-extraction.tsuserInstruction(~1277).serverEnforcedLinkRules()(~75): "Every link target must resolve to sourceNote.id or a target note derived from a unit in the same response" becomes "…or one of the listed previous-piece events and threads".targetNoteRules(~1267): "never target or invent an existing note id" gets the exception "except a listed open thread's subjectId".extraction/evidence-unit-validation.ts: probably no change.closeLtmEvidenceUnitLinks(~415) already acceptsexistingNotesids as targets, andhasRelationshipSupportalready accepts an existing timeline note ascaused_by. The regression proves this.extraction/dedup.ts: check thatdeduplicateUnits(units, existingNotes, scope)maps a thread unit with a reused subjectId to the existingthread_<subjectId>note as an update, not a create.Regression: a deterministic test with a fake language model and no network, in the package's tests next to the existing chat-import and extraction tests. A chat is split into two pieces:
caused_by→ a piece 1 event id survives validation and link closure, and is committed.Non-goals
update_section:state"rewrite" disposition, which forces one-at-a-time apply on later pieces (drafts/reconciliation.ts~958). That is a separate issue.Why should this be optional?
Long-Term Memory is already a catalog package, and this changes only its own extraction prompt for chat-messages imports. No new setting is needed: the extra blocks add about 3–5k characters to each piece after the first.
Alternatives considered
Additional context
Template check