[GH-ISSUE #2286] [Issue]: Memory recall scores every stored memory in long chats; the web build capped the working set at 500 chunks #1124

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

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

Originally assigned to: @Xelvanis on GitHub.

Summary

The refactor's buildMemoryRecallBlock loads and cosine-scores the entire memories array for the chat on every generation, with no cap. The web build bounded the recall working set to at most 500 chunks (and 50 chats) before scoring.

Expected behavior

Recall should bound the number of stored memories it scores per generation (main caps at 500 most-recent chunks), so recall cost does not grow unboundedly with chat length.

Actual behavior

The refactor reads the whole memories array (no LIMIT) and maps cosine + lexical scoring over every memory before slicing the top 8, so a 10k-message chat scores ~2,000 memories every turn in the prompt-assembly hot path. Each cosine op is cheap and it is single-chat scoped, so the slowdown only shows on very long chats.

Steps to reproduce

  1. Build up a very long single chat (thousands of messages) with memory recall enabled.
  2. Generate.
  3. Observe recall scoring cost grows with total chat length (unbounded), unlike main's 500-chunk cap.

Impact area

  • Chat mode
  • Runtime systems: generation, world-state, visuals, tracker, or haptics
  • React-free engine behavior, contracts, agents, or capability ports

Regression notes

Worked bounded on main. Main caps to 50 chat ids and .limit(MAX_CHUNKS) with MAX_CHUNKS 500 ("capped to prevent memory blowup") before scoring (packages/server/src/services/memory-recall.ts:217-233,240-261). The refactor loads the entire array (src/engine/generation/prompt-assembly.ts:1837, storage-api.ts:435-437, Rust chat_array_field no LIMIT at commands/storage/chats.rs:747-750) and scores all before .slice(0,8) (prompt-assembly.ts:1855-1872); the read-behind filter at :1842 does not bound the count. Both chunk at 5 (memory-recall.ts:16, chats.rs:10) with no stored-count cap (chats.rs:781-856). Runs once per generation from prompt-assembly.ts:2892. Minor because single-chat scoped and cheap per op.

Environment

  • Branch or commit: refactor @ 5ddb9840 (compared against main @ b4ab97f)
  • Run mode: Tauri desktop
  • OS + version: Windows 11
  • Node + pnpm versions: not relevant (static source comparison)
  • Rust version, if relevant: not relevant (static source comparison)
  • Remote Runtime URL configured? not relevant
  • Provider, model, or integration, if relevant: see body

Template check

Please uncheck 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 @Romuromylus on GitHub (Jun 5, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2286 Originally assigned to: @Xelvanis on GitHub. ## Summary The refactor's `buildMemoryRecallBlock` loads and cosine-scores the entire memories array for the chat on every generation, with no cap. The web build bounded the recall working set to at most 500 chunks (and 50 chats) before scoring. ## Expected behavior Recall should bound the number of stored memories it scores per generation (main caps at 500 most-recent chunks), so recall cost does not grow unboundedly with chat length. ## Actual behavior The refactor reads the whole memories array (no LIMIT) and maps cosine + lexical scoring over every memory before slicing the top 8, so a 10k-message chat scores ~2,000 memories every turn in the prompt-assembly hot path. Each cosine op is cheap and it is single-chat scoped, so the slowdown only shows on very long chats. ## Steps to reproduce 1. Build up a very long single chat (thousands of messages) with memory recall enabled. 2. Generate. 3. Observe recall scoring cost grows with total chat length (unbounded), unlike main's 500-chunk cap. ## Impact area - [x] Chat mode - [x] Runtime systems: generation, world-state, visuals, tracker, or haptics - [x] React-free engine behavior, contracts, agents, or capability ports ## Regression notes Worked bounded on main. Main caps to 50 chat ids and `.limit(MAX_CHUNKS)` with MAX_CHUNKS 500 ("capped to prevent memory blowup") before scoring (`packages/server/src/services/memory-recall.ts:217-233,240-261`). The refactor loads the entire array (`src/engine/generation/prompt-assembly.ts:1837`, `storage-api.ts:435-437`, Rust `chat_array_field` no LIMIT at `commands/storage/chats.rs:747-750`) and scores all before `.slice(0,8)` (`prompt-assembly.ts:1855-1872`); the read-behind filter at `:1842` does not bound the count. Both chunk at 5 (`memory-recall.ts:16`, `chats.rs:10`) with no stored-count cap (`chats.rs:781-856`). Runs once per generation from `prompt-assembly.ts:2892`. Minor because single-chat scoped and cheap per op. ## Environment - Branch or commit: refactor @ 5ddb9840 (compared against main @ b4ab97f) - Run mode: Tauri desktop - OS + version: Windows 11 - Node + pnpm versions: not relevant (static source comparison) - Rust version, if relevant: not relevant (static source comparison) - Remote Runtime URL configured? not relevant - Provider, model, or integration, if relevant: see body ## Template check Please uncheck 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.
bsakaguchi 2026-10-21 05:27:23 +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-Engine#1124
No description provided.