[GH-ISSUE #2284] [Issue]: Memory-recall embedding blocks every assistant turn and re-embeds the whole chat one request at a time (no defer, no watermark, no batch) #1121

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

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

Originally assigned to: @SpicyMarinara on GitHub.

Summary

In the refactor, memory-recall chunking/embedding runs synchronously right before the generation "done" event, re-embeds every visible chunk on each turn (no incremental watermark), and issues one embedding HTTP request per chunk (no batch). Main defers it fire-and-forget, embeds only the newly completed chunk, and batches in a single request.

Expected behavior

Memory embedding should not block the user-visible turn, should embed only new chunks incrementally, and should batch chunk texts into one embedding request, matching main's deferred/incremental/batched design.

Actual behavior

refreshMemoryRecallSafely is awaited before yield { type: "done" }, and refresh_chat_memories loops over all visible chunks awaiting one embedding round-trip each with no skip of already-embedded chunks, then overwrites the whole memories array. A K-chunk chat performs K blocking embedding round-trips every turn (O(n), compounding with chat length) when a remote embedding connection is configured.

Steps to reproduce

  1. Configure a remote embedding-capable connection.
  2. In conversation mode (or an active scene), build up a long chat.
  3. Generate repeatedly and observe the turn stalls before completion, growing with chat length.

Impact area

  • Chat mode
  • Runtime systems: generation, world-state, visuals, tracker, or haptics
  • Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime

Regression notes

Worked better on main. Main runs fire-and-forget after generation with a .catch not await (packages/server/src/routes/generate.routes.ts:11093-11098), is incremental via an after cursor (memory-recall.ts:86-121), and batches all chunk texts into one POST (memory-recall.ts:155-156, base-provider.ts:615). The refactor awaits refreshMemoryRecallSafely before done (src/engine/generation/start-generation.ts:3095,3227, gate :1741), and refresh_chat_memories loops all chunks (src-tauri/src/commands/storage/chats.rs:781-857, esp. :784-787,:849) awaiting embed_text per chunk (prompts.rs:512-523), with no batch path anywhere (llm.rs:127-132 also one-at-a-time) and no tokio::spawn. Lexical-only configs avoid the network cost but the synchronous full re-embed before done remains.

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/2284 Originally assigned to: @SpicyMarinara on GitHub. ## Summary In the refactor, memory-recall chunking/embedding runs synchronously right before the generation "done" event, re-embeds every visible chunk on each turn (no incremental watermark), and issues one embedding HTTP request per chunk (no batch). Main defers it fire-and-forget, embeds only the newly completed chunk, and batches in a single request. ## Expected behavior Memory embedding should not block the user-visible turn, should embed only new chunks incrementally, and should batch chunk texts into one embedding request, matching main's deferred/incremental/batched design. ## Actual behavior `refreshMemoryRecallSafely` is awaited before `yield { type: "done" }`, and `refresh_chat_memories` loops over all visible chunks awaiting one embedding round-trip each with no skip of already-embedded chunks, then overwrites the whole memories array. A K-chunk chat performs K blocking embedding round-trips every turn (O(n), compounding with chat length) when a remote embedding connection is configured. ## Steps to reproduce 1. Configure a remote embedding-capable connection. 2. In conversation mode (or an active scene), build up a long chat. 3. Generate repeatedly and observe the turn stalls before completion, growing with chat length. ## Impact area - [x] Chat mode - [x] Runtime systems: generation, world-state, visuals, tracker, or haptics - [x] Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime ## Regression notes Worked better on main. Main runs fire-and-forget after generation with a `.catch` not `await` (`packages/server/src/routes/generate.routes.ts:11093-11098`), is incremental via an `after` cursor (`memory-recall.ts:86-121`), and batches all chunk texts into one POST (`memory-recall.ts:155-156`, `base-provider.ts:615`). The refactor awaits `refreshMemoryRecallSafely` before done (`src/engine/generation/start-generation.ts:3095,3227`, gate `:1741`), and `refresh_chat_memories` loops all chunks (`src-tauri/src/commands/storage/chats.rs:781-857`, esp. `:784-787,:849`) awaiting `embed_text` per chunk (`prompts.rs:512-523`), with no batch path anywhere (`llm.rs:127-132` also one-at-a-time) and no `tokio::spawn`. Lexical-only configs avoid the network cost but the synchronous full re-embed before done remains. ## 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:17 +07:00
Author
Owner

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

Pretty straightforward to fix.

<!-- gh-comment-id:4637991721 --> @SpicyMarinara commented on GitHub (Jun 6, 2026): Pretty straightforward to fix.
Author
Owner

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

Fixed on refactor in 5775f354.

What changed:

  • Memory Recall refresh is scheduled after saved generation work instead of being awaited before the visible done event.
  • refresh_chat_memories now preserves existing complete five-message chunks when the span/content and embedding source/model still match.
  • New chunks are embedded in a batch through the existing embedding batch helper, with lexical fallback still local.
  • The refresh result now reports embedded and reused counts in addition to the existing chunk payload.

Validation:

  • cargo test --manifest-path src-tauri/Cargo.toml -p marinara-engine refresh_chat_memories_reuses_existing_complete_chunks
  • pnpm typecheck
  • cargo check --manifest-path src-tauri/Cargo.toml
  • pnpm check:architecture

Closing as completed.

<!-- gh-comment-id:4638053596 --> @SpicyMarinara commented on GitHub (Jun 6, 2026): Fixed on `refactor` in `5775f354`. What changed: - Memory Recall refresh is scheduled after saved generation work instead of being awaited before the visible `done` event. - `refresh_chat_memories` now preserves existing complete five-message chunks when the span/content and embedding source/model still match. - New chunks are embedded in a batch through the existing embedding batch helper, with lexical fallback still local. - The refresh result now reports `embedded` and `reused` counts in addition to the existing chunk payload. Validation: - `cargo test --manifest-path src-tauri/Cargo.toml -p marinara-engine refresh_chat_memories_reuses_existing_complete_chunks` - `pnpm typecheck` - `cargo check --manifest-path src-tauri/Cargo.toml` - `pnpm check:architecture` Closing as completed.
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#1121
No description provided.