[GH-ISSUE #1998] feat(long-term-memory): recall can leave out what a caller added itself (SN-5) #1864

Closed
opened 2026-11-07 16:37:13 +07:00 by bsakaguchi · 0 comments
Owner

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

Originally assigned to: @Promansis on GitHub.

What problem does this solve?

Once Slurp hands its Creator records to Long-Term Memory (SN-4), those records come straight back. Slurp's next post plan or DM reply calls long-term-memory:recall for the same Creator and gets the same fact again under "From your memory", as if Long-Term Memory had learned it from a chat. Slurp already has the original in its continuity ledger, which renders in the same "What you already know" block. The prompt then states the fact twice, and the copy looks like independent confirmation.

Tracker: SN-5.

Proposed package or change

long-term-memory:recall takes a new optional input, excludeFrom: string[], a list of callers. Recall skips any note section whose content came only from records those callers added through long-term-memory:intake, and skips a note entirely when nothing else is left. Slurp passes excludeFrom: ["slurp2"], so it still gets what chats taught Long-Term Memory about its Creators, but not its own facts back.

Recall service version 1 is unchanged. An older Long-Term Memory strips the unknown key (recallInputSchema is a non-strict z.object), so Slurp can pass it without a version check. Long-Term Memory patch.

Decided by the user on 2026-10-30: the filter goes on LTM's side.

Minimal fix

L = packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory.

 L/services/storage-read.ts:6-11
+  export const ltmPackageCallerIdSchema = z.string().trim().regex(/^[a-z0-9][a-z0-9._:-]{0,63}$/iu)
   ltmPackageCallerSchema = ltmPackageCallerIdSchema.optional().catch(undefined)      (unchanged behaviour)
 L/services/recall.ts
   recallInputSchema (:24-32)
+    excludeFrom: z.array(ltmPackageCallerIdSchema).max(10).default([])
+      the strict id schema: ltmPackageCallerSchema has .catch(undefined), which would swallow a bad entry
+  fromExcluded(note, sectionKey, prefixes): the section exists, has contributions, and every one is
+    owner "source" with sourceNoteId starting with one of prefixes   (ltmPackageSourceNotePrefix, SN-4)
   whole mode (:80-104; chunk map :90-93)
+    chunkNoteSections(note).filter((chunk) => !fromExcluded(note, chunk.sectionKey, prefixes)).map(...)
   ranked mode (:105-133; `for (const { chunk } of retrieval.chunks)` :121-131)
+    continue when fromExcluded(note, chunk.sectionKey, prefixes)
  • The test is by contribution, not by section key, so a chat extraction that later writes into from_slurp2 keeps that section.
  • A chunk whose sectionKey has no stored section (the synthetic profile chunk, recall/chunking.ts:78, 102) is kept.
  • A note whose chunks are all skipped returns nothing: whole mode already skips empty text (:95), and ranked mode never adds the note.
  • docs/ARCHITECTURE.md § Services for Other Packages: excludeFrom? in the signature (:214-226) and one rule: "Sections that only hold records the named callers added through long-term-memory:intake are left out."
  • CHANGELOG (## Unreleased): an Agent can ask recall to leave out what it added itself, so its own facts don't come back as new.

Non-goals: excluding by provenance kind for chat sources; Slurp-side link rows.

Regression proof

In tests/long-term-memory-runtime.regression.ts, recall block (:327-533; whole-recall tests :416-438), add to the fixture a character note for the posting account with two sections: from_slurp2 with one contribution from ltmPackageSourceNoteId("slurp2", "fact:f1"), and history with a manual contribution. Three cases:

  1. Without excludeFrom, both sections return (current behaviour unchanged).
  2. With excludeFrom: ["slurp2"], the from_slurp2 text is gone and history stays, in both whole and ranked mode.
  3. A section with one Slurp contribution and one manual contribution stays.

Why should this be optional?

It is an optional input on an existing service. Callers that don't pass it get exactly what they get today.

Alternatives considered

  • Slurp dedupes by noteId using slurp2_continuity_links rows. Needs the link rows SN-3 deferred, and can only drop whole notes, so a character note mixing chat memories with a "From Slurp" section would lose the chat part too.
  • excludeProvenance on note provenance (the tracker's first wording). Recall never returns source notes, and only source notes carry provenance (notes.ts:314). The link from a memory to its Slurp record is the section contribution's sourceNoteId, so the filter keys on that.
  • Filter on the section key from_slurp2. Simpler, but a chat extraction could write into that section and its chat part would be dropped too.

Additional context

Depends on SN-4 part 1 for ltmPackageSourceNotePrefix. Before that ships, no section has such contributions and the filter is a no-op.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.

Local trace

Anchors (upstream/staging 655b7666d):

  • recall.ts:24-32 (schema, non-strict z.object), :58-64 (null rules), :80-104 (whole mode), :105-133 (ranked mode), :138 (recordLtmPackageRead).
  • recall/chunking.ts:63 (chunkNoteSections); chunks carry sectionKey (:78 and :102 synthetic profile, :111-117, :141).
  • storage-read.ts:6-11 (ltmPackageCallerSchema), :14-20 (isLtmNoteShareable; both modes already drop source notes with it).
  • notes.ts:221-236 (contributions).
  • docs/ARCHITECTURE.md:214-226 (recall signature incl. whole?).

Verified 2026-10-31: ranked retrieval.chunks[].chunk carries sectionKey (retrieval/budget.ts:35, 61, 89, generation-injection.ts:265, 312, 324, usage.ts:137 read it).

For the worker to check: whether the ranked path's note lookup for a chunk already has the full note with sections in scope, or needs the section read for fromExcluded.

Originally created by @Promansis on GitHub (Oct 31, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1998 Originally assigned to: @Promansis on GitHub. ## What problem does this solve? Once Slurp hands its Creator records to Long-Term Memory (SN-4), those records come straight back. Slurp's next post plan or DM reply calls `long-term-memory:recall` for the same Creator and gets the same fact again under "From your memory", as if Long-Term Memory had learned it from a chat. Slurp already has the original in its continuity ledger, which renders in the same "What you already know" block. The prompt then states the fact twice, and the copy looks like independent confirmation. Tracker: SN-5. ## Proposed package or change `long-term-memory:recall` takes a new optional input, `excludeFrom: string[]`, a list of callers. Recall skips any note section whose content came only from records those callers added through `long-term-memory:intake`, and skips a note entirely when nothing else is left. Slurp passes `excludeFrom: ["slurp2"]`, so it still gets what chats taught Long-Term Memory about its Creators, but not its own facts back. Recall service version 1 is unchanged. An older Long-Term Memory strips the unknown key (`recallInputSchema` is a non-strict `z.object`), so Slurp can pass it without a version check. Long-Term Memory patch. Decided by the user on 2026-10-30: the filter goes on LTM's side. ### Minimal fix L = `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory`. ```diff L/services/storage-read.ts:6-11 + export const ltmPackageCallerIdSchema = z.string().trim().regex(/^[a-z0-9][a-z0-9._:-]{0,63}$/iu) ltmPackageCallerSchema = ltmPackageCallerIdSchema.optional().catch(undefined) (unchanged behaviour) L/services/recall.ts recallInputSchema (:24-32) + excludeFrom: z.array(ltmPackageCallerIdSchema).max(10).default([]) + the strict id schema: ltmPackageCallerSchema has .catch(undefined), which would swallow a bad entry + fromExcluded(note, sectionKey, prefixes): the section exists, has contributions, and every one is + owner "source" with sourceNoteId starting with one of prefixes (ltmPackageSourceNotePrefix, SN-4) whole mode (:80-104; chunk map :90-93) + chunkNoteSections(note).filter((chunk) => !fromExcluded(note, chunk.sectionKey, prefixes)).map(...) ranked mode (:105-133; `for (const { chunk } of retrieval.chunks)` :121-131) + continue when fromExcluded(note, chunk.sectionKey, prefixes) ``` - The test is by contribution, not by section key, so a chat extraction that later writes into `from_slurp2` keeps that section. - A chunk whose `sectionKey` has no stored section (the synthetic `profile` chunk, `recall/chunking.ts:78, 102`) is kept. - A note whose chunks are all skipped returns nothing: whole mode already skips empty text (:95), and ranked mode never adds the note. - `docs/ARCHITECTURE.md` § Services for Other Packages: `excludeFrom?` in the signature (:214-226) and one rule: "Sections that only hold records the named callers added through `long-term-memory:intake` are left out." - **CHANGELOG** (`## Unreleased`): an Agent can ask recall to leave out what it added itself, so its own facts don't come back as new. Non-goals: excluding by provenance kind for chat sources; Slurp-side link rows. ### Regression proof In `tests/long-term-memory-runtime.regression.ts`, recall block (:327-533; whole-recall tests :416-438), add to the fixture a character note for the posting account with two sections: `from_slurp2` with one contribution from `ltmPackageSourceNoteId("slurp2", "fact:f1")`, and `history` with a manual contribution. Three cases: 1. Without `excludeFrom`, both sections return (current behaviour unchanged). 2. With `excludeFrom: ["slurp2"]`, the `from_slurp2` text is gone and `history` stays, in both whole and ranked mode. 3. A section with one Slurp contribution and one manual contribution stays. ## Why should this be optional? It is an optional input on an existing service. Callers that don't pass it get exactly what they get today. ## Alternatives considered - **Slurp dedupes by `noteId` using `slurp2_continuity_links` rows.** Needs the link rows SN-3 deferred, and can only drop whole notes, so a character note mixing chat memories with a "From Slurp" section would lose the chat part too. - **`excludeProvenance` on note provenance (the tracker's first wording).** Recall never returns source notes, and only source notes carry provenance (`notes.ts:314`). The link from a memory to its Slurp record is the section contribution's `sourceNoteId`, so the filter keys on that. - **Filter on the section key `from_slurp2`.** Simpler, but a chat extraction could write into that section and its chat part would be dropped too. ## Additional context Depends on SN-4 part 1 for `ltmPackageSourceNotePrefix`. Before that ships, no section has such contributions and the filter is a no-op. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details. ## Local trace Anchors (upstream/staging 655b7666d): - `recall.ts:24-32` (schema, non-strict `z.object`), `:58-64` (null rules), `:80-104` (whole mode), `:105-133` (ranked mode), `:138` (`recordLtmPackageRead`). - `recall/chunking.ts:63` (`chunkNoteSections`); chunks carry `sectionKey` (:78 and :102 synthetic `profile`, :111-117, :141). - `storage-read.ts:6-11` (`ltmPackageCallerSchema`), `:14-20` (`isLtmNoteShareable`; both modes already drop source notes with it). - `notes.ts:221-236` (contributions). - `docs/ARCHITECTURE.md:214-226` (recall signature incl. `whole?`). Verified 2026-10-31: ranked `retrieval.chunks[].chunk` carries `sectionKey` (`retrieval/budget.ts:35, 61, 89`, `generation-injection.ts:265, 312, 324`, `usage.ts:137` read it). For the worker to check: whether the ranked path's `note` lookup for a chunk already has the full note with sections in scope, or needs the section read for `fromExcluded`.
bsakaguchi 2026-11-07 16:37:13 +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#1864
No description provided.