[GH-ISSUE #2695] [Issue]: Cross-chat memory recall caps candidates by recency (MAX_CHUNKS=500) before similarity, dropping older relevant memories #1339

Closed
opened 2026-10-21 05:31:48 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @kolacheee on GitHub (Jun 21, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2695

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Cross-chat memory recall selects which memory chunks to score by recency, not relevance: it loads only the MAX_CHUNKS = 500 most-recent chunks (ORDER BY lastMessageAt DESC LIMIT 500) and runs cosine similarity only over those. In a long-lived chat (or one with many imported cross-chat memories) that exceeds 500 chunks, a highly relevant but older memory is excluded from scoring entirely and can never be recalled — silently defeating the whole point of semantic recall.

Expected behavior

Semantic memory recall should surface the most relevant memories regardless of age — an old-but-highly-similar memory should be recallable even when newer (less relevant) memories exist.

Actual behavior

recallMemories loads candidate chunks with .orderBy(desc(memoryChunks.lastMessageAt)).limit(MAX_CHUNKS) (MAX_CHUNKS = 500), then computes cosine scores and top-K selection only over those 500 rows. The candidate cutoff is applied at the DB layer by recency before similarity is ever computed, so any relevant chunk older than the 500 most-recent is never considered.

How it breaks the pipeline

Code trace (staging @ b826f8f4):

  • packages/server/src/services/memory-recall.ts:220, :232-233 — .orderBy(desc(memoryChunks.lastMessageAt)).limit(MAX_CHUNKS) (MAX_CHUNKS = 500).
  • :240-261 — cosine scoring + top-K run only over the loaded rows.

Steps to reproduce

  1. Accumulate (or import) more than 500 memory chunks in a chat's recall scope.
  2. Reference an event from early in the history whose matching chunk has an older lastMessageAt than the 500 most-recent chunks.
  3. The relevant chunk is never loaded and never recalled, even though its similarity would beat the recent 500.

Suggested fix

Do similarity scoring at the storage layer (an ANN / vector index over the full set), or at least raise/remove the recency-ordered cap, or pre-filter candidates by something other than pure recency so old high-similarity chunks remain eligible for scoring.

Environment

  • Marinara Engine version: 2.0.0 (staging @ b826f8f4)
  • Install type: source
  • OS + version: All (code-level defect, platform-independent)
  • Browser or app shell: All

Additional context

Found via a systematic multi-agent audit of conditional prompt insertion. Affects long-lived chats and heavy cross-chat-memory users; matches reports of "it forgets old things even though it should remember them." Part of a set of conditional-injection issues filed together.

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.
Originally created by @kolacheee on GitHub (Jun 21, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2695 Originally assigned to: @SpicyMarinara on GitHub. ## Summary Cross-chat memory recall selects which memory chunks to score by **recency**, not relevance: it loads only the `MAX_CHUNKS = 500` most-recent chunks (`ORDER BY lastMessageAt DESC LIMIT 500`) and runs cosine similarity only over those. In a long-lived chat (or one with many imported cross-chat memories) that exceeds 500 chunks, a highly relevant but older memory is excluded from scoring entirely and can never be recalled — silently defeating the whole point of semantic recall. ## Expected behavior Semantic memory recall should surface the most *relevant* memories regardless of age — an old-but-highly-similar memory should be recallable even when newer (less relevant) memories exist. ## Actual behavior `recallMemories` loads candidate chunks with `.orderBy(desc(memoryChunks.lastMessageAt)).limit(MAX_CHUNKS)` (`MAX_CHUNKS = 500`), then computes cosine scores and top-K selection **only** over those 500 rows. The candidate cutoff is applied at the DB layer by recency before similarity is ever computed, so any relevant chunk older than the 500 most-recent is never considered. ## How it breaks the pipeline Code trace (staging @ `b826f8f4`): - `packages/server/src/services/memory-recall.ts:220`, `:232-233` — `.orderBy(desc(memoryChunks.lastMessageAt)).limit(MAX_CHUNKS)` (`MAX_CHUNKS = 500`). - `:240-261` — cosine scoring + top-K run only over the loaded rows. ## Steps to reproduce 1. Accumulate (or import) more than 500 memory chunks in a chat's recall scope. 2. Reference an event from early in the history whose matching chunk has an older `lastMessageAt` than the 500 most-recent chunks. 3. The relevant chunk is never loaded and never recalled, even though its similarity would beat the recent 500. ## Suggested fix Do similarity scoring at the storage layer (an ANN / vector index over the full set), or at least raise/remove the recency-ordered cap, or pre-filter candidates by something other than pure recency so old high-similarity chunks remain eligible for scoring. ## Environment - Marinara Engine version: 2.0.0 (staging @ `b826f8f4`) - Install type: source - OS + version: All (code-level defect, platform-independent) - Browser or app shell: All ## Additional context Found via a systematic multi-agent audit of conditional prompt insertion. Affects long-lived chats and heavy cross-chat-memory users; matches reports of "it forgets old things even though it should remember them." Part of a set of conditional-injection issues filed together. ## 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.
Author
Owner

@SpicyMarinara commented on GitHub (Jun 21, 2026):

Fixed in branch codex/spicy-issue-sweep-2026-06-21.

What changed:

  • Removed the recency-ordered MAX_CHUNKS = 500 pre-cap from memory recall.
  • Recall now loads every embedded chunk in the selected chat scope, scores by cosine similarity, then applies the normal top-K result limit.

Final repo checks will run after the full issue sweep.

<!-- gh-comment-id:4761538989 --> @SpicyMarinara commented on GitHub (Jun 21, 2026): Fixed in branch `codex/spicy-issue-sweep-2026-06-21`. What changed: - Removed the recency-ordered `MAX_CHUNKS = 500` pre-cap from memory recall. - Recall now loads every embedded chunk in the selected chat scope, scores by cosine similarity, then applies the normal top-K result limit. Final repo checks will run after the full issue sweep.
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-Engine#1339
No description provided.