[GH-ISSUE #1303] [Issue]: Long-Term Memory doesn't register the Engine's refresh hook for embedding changes #664

Closed
opened 2026-10-20 17:29:32 +07:00 by bsakaguchi · 0 comments
Owner

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

Originally assigned to: @Promansis on GitHub.

Summary

When a connection or agent save changes Long-Term Memory's embedding configuration, the Engine calls refresh({ signal }) on the long-term-memory:runtime service. The Engine added this in Pasta-Devs/Marinara-Engine#7148, for Pasta-Devs/Marinara-Engine#7042. LTM never registers refresh, so every such save shows:

Configuration saved. Long-Term Memory index refresh is unavailable; enable or update the package to refresh immediately.

Updating doesn't help, because no LTM version registers the hook. The whole vault is then re-embedded inline during the next chat's recall.

Affected package

long-term-memory (Long-Term Memory) 1.4.23

Expected behavior

LTM implements refresh. It brings the recall index up to date for the new embedding source while the save is in progress, and returns { status: "refreshed" }. The Engine then shows "Configuration saved and Long-Term Memory indexes refreshed."

Actual behavior

  • server-entry.ts L37-L49`` registers recall, recordPromptAccepted and withVaultMutation, but not refresh.
  • The Engine sees no refresh and sets X-Marinara-LTM-Refresh: unavailable (long-term-memory-runtime.ts L74-L77),```` and the client shows the warning toast (api-client.ts L273-L278).
  • On the next recall, loadOrRebuildLongTermMemoryIndexes sees a spaceId mismatch and tryUpgradeSemanticIndex re-embeds the whole vault inside recall (rebuild.ts L59-L82).````` That happens under the vault lock and within the agent call timeout, so the first reply after a switch waits for it.
  • If that inline upgrade fails for a reason other than cancellation, the process-local autoUpgradeFailures guard turns semantic search off for that space until a manual rebuild or a restart. Recall silently falls back to lexical-only.

Steps to reproduce

  1. Install Long-Term Memory 1.4.23 and save some memories.
  2. In Connections, change the embedding model of the connection LTM uses, or assign another connection with "apply to all agents".
  3. Save. The toast says the refresh is unavailable, and the response carries X-Marinara-LTM-Refresh: unavailable.
  4. Send a chat message. Recall re-embeds the vault before the reply is generated.

Environment

  • Marinara Engine version: 2.5.0 (staging at ecd62a2e4678d82fae753dd19f0f15cfbe48bba0)
  • Package version: 1.4.23 (staging at 11c8a563e7ef33b03442909814366f11330e1aad)
  • Install type: source. Found by code inspection, not reproduced in a running install.
  • OS + version: not applicable
  • Browser or app shell: not applicable

Logs, screenshots, or video

Toast text from the Engine's agents.longTermMemory.embeddingRefresh.unavailable string (en.json L68).

Additional context

Minimal fix

In rebuild.ts, export a small helper. clearAutoUpgradeFailure, getUsableEmbeddingState and resolvePackageEmbeddingAdapter are already available in that module.

export async function refreshLongTermMemoryIndexes(root: string, signal?: AbortSignal) {
  const adapter = await resolvePackageEmbeddingAdapter();
  // An explicit configuration save is a deliberate retry of a space that failed before.
  clearAutoUpgradeFailure(root, adapter ?? null);
  const index = await loadOrRebuildLongTermMemoryIndexes(root, adapter ?? null, undefined, signal);
  if (adapter && index.embeddings.chunks.length > 0 && !getUsableEmbeddingState(index, adapter)) {
    throw new Error("Long-term memory could not embed the vault with the new embedding source");
  }
}

In server-entry.ts, add refresh to the long-term-memory:runtime service:

refresh: async ({ signal }: { signal: AbortSignal }) => {
  await refreshLongTermMemoryIndexes(activationRoot, signal);
  return { status: "refreshed" as const };
},
  • Up-to-date indexes aren't rebuilt. loadOrRebuildLongTermMemoryIndexes does nothing when the index already matches the new space. This matters because the Engine also calls refresh when only the request identity changes, such as credentials, while spaceId stays the same (long-term-memory-runtime.ts L47-L48).``````
  • The throw is deliberate. Without it, an upgrade that fails inside tryUpgradeSemanticIndex is swallowed, and the user would see "refreshed" while semantic search is actually off. With it, the Engine reports failed, and the save itself still succeeds.
  • Locking, cancellation and timeout are already handled. The rebuild runs under withLtmVaultLock and honors signal. The Engine reports a timeout as timeout, and because cancellation doesn't set the guard, the next recall retries.
  • Regression: register a fake adapter with space A and build. Switch to space B and call refresh: the index is rebuilt with B's spaceId and the result is { status: "refreshed" }. Call it again: there is no second rebuild. With an adapter that fails, refresh rejects.
  • Bump the package version and CHANGELOG as the repository requires.

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 @Promansis on GitHub (Oct 11, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1303 Originally assigned to: @Promansis on GitHub. ## Summary When a connection or agent save changes Long-Term Memory's embedding configuration, the Engine calls `refresh({ signal })` on the `long-term-memory:runtime` service. The Engine added this in Pasta-Devs/Marinara-Engine#7148, for Pasta-Devs/Marinara-Engine#7042. LTM never registers `refresh`, so every such save shows: > Configuration saved. Long-Term Memory index refresh is unavailable; enable or update the package to refresh immediately. Updating doesn't help, because no LTM version registers the hook. The whole vault is then re-embedded inline during the next chat's recall. ## Affected package `long-term-memory` (Long-Term Memory) 1.4.23 ## Expected behavior LTM implements `refresh`. It brings the recall index up to date for the new embedding source while the save is in progress, and returns `{ status: "refreshed" }`. The Engine then shows "Configuration saved and Long-Term Memory indexes refreshed." ## Actual behavior - [server-entry.ts L37-L49](``https://github.com/Pasta-Devs/Marinara-Agents/blob/11c8a563e7ef33b03442909814366f11330e1aad/packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/server-entry.ts#L37-L49)`` registers `recall`, `recordPromptAccepted` and `withVaultMutation`, but not `refresh`. - The Engine sees no `refresh` and sets `X-Marinara-LTM-Refresh: unavailable` ([long-term-memory-runtime.ts L74-L77](````https://github.com/Pasta-Devs/Marinara-Engine/blob/ecd62a2e4678d82fae753dd19f0f15cfbe48bba0/packages/server/src/services/generation/long-term-memory-runtime.ts#L74-L77)),```` and the client shows the warning toast ([api-client.ts L273-L278](https://github.com/Pasta-Devs/Marinara-Engine/blob/ecd62a2e4678d82fae753dd19f0f15cfbe48bba0/packages/client/src/lib/api-client.ts#L273-L278)). - On the next recall, `loadOrRebuildLongTermMemoryIndexes` sees a `spaceId` mismatch and `tryUpgradeSemanticIndex` re-embeds the whole vault inside recall ([rebuild.ts L59-L82](`````https://github.com/Pasta-Devs/Marinara-Agents/blob/11c8a563e7ef33b03442909814366f11330e1aad/packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/rebuild.ts#L59-L82)).````` That happens under the vault lock and within the agent call timeout, so the first reply after a switch waits for it. - If that inline upgrade fails for a reason other than cancellation, the process-local `autoUpgradeFailures` guard turns semantic search off for that space until a manual rebuild or a restart. Recall silently falls back to lexical-only. ## Steps to reproduce 1. Install Long-Term Memory 1.4.23 and save some memories. 2. In Connections, change the embedding model of the connection LTM uses, or assign another connection with "apply to all agents". 3. Save. The toast says the refresh is unavailable, and the response carries `X-Marinara-LTM-Refresh: unavailable`. 4. Send a chat message. Recall re-embeds the vault before the reply is generated. ## Environment - Marinara Engine version: 2.5.0 (`staging` at `ecd62a2e4678d82fae753dd19f0f15cfbe48bba0`) - Package version: 1.4.23 (`staging` at `11c8a563e7ef33b03442909814366f11330e1aad`) - Install type: source. Found by code inspection, not reproduced in a running install. - OS + version: not applicable - Browser or app shell: not applicable ## Logs, screenshots, or video Toast text from the Engine's `agents.longTermMemory.embeddingRefresh.unavailable` string ([en.json L68](https://github.com/Pasta-Devs/Marinara-Engine/blob/ecd62a2e4678d82fae753dd19f0f15cfbe48bba0/packages/client/src/localization/locales/en.json#L68)). ## Additional context ### Minimal fix In `rebuild.ts`, export a small helper. `clearAutoUpgradeFailure`, `getUsableEmbeddingState` and `resolvePackageEmbeddingAdapter` are already available in that module. ```ts export async function refreshLongTermMemoryIndexes(root: string, signal?: AbortSignal) { const adapter = await resolvePackageEmbeddingAdapter(); // An explicit configuration save is a deliberate retry of a space that failed before. clearAutoUpgradeFailure(root, adapter ?? null); const index = await loadOrRebuildLongTermMemoryIndexes(root, adapter ?? null, undefined, signal); if (adapter && index.embeddings.chunks.length > 0 && !getUsableEmbeddingState(index, adapter)) { throw new Error("Long-term memory could not embed the vault with the new embedding source"); } } ``` In `server-entry.ts`, add `refresh` to the `long-term-memory:runtime` service: ```ts refresh: async ({ signal }: { signal: AbortSignal }) => { await refreshLongTermMemoryIndexes(activationRoot, signal); return { status: "refreshed" as const }; }, ``` - **Up-to-date indexes aren't rebuilt.** `loadOrRebuildLongTermMemoryIndexes` does nothing when the index already matches the new space. This matters because the Engine also calls `refresh` when only the request identity changes, such as credentials, while `spaceId` stays the same ([long-term-memory-runtime.ts L47-L48](``````https://github.com/Pasta-Devs/Marinara-Engine/blob/ecd62a2e4678d82fae753dd19f0f15cfbe48bba0/packages/server/src/services/generation/long-term-memory-runtime.ts#L47-L48)).`````` - **The throw is deliberate.** Without it, an upgrade that fails inside `tryUpgradeSemanticIndex` is swallowed, and the user would see "refreshed" while semantic search is actually off. With it, the Engine reports `failed`, and the save itself still succeeds. - **Locking, cancellation and timeout are already handled.** The rebuild runs under `withLtmVaultLock` and honors `signal`. The Engine reports a timeout as `timeout`, and because cancellation doesn't set the guard, the next recall retries. - **Regression:** register a fake adapter with space A and build. Switch to space B and call `refresh`: the index is rebuilt with B's `spaceId` and the result is `{ status: "refreshed" }`. Call it again: there is no second rebuild. With an adapter that fails, `refresh` rejects. - Bump the package version and CHANGELOG as the repository requires. ### Related - Pasta-Devs/Marinara-Engine#7042 and Pasta-Devs/Marinara-Engine#7148, the Engine side, already merged. - #1193 covered rebuilds after LTM's own settings saves and left the Engine save notification to the Engine issue above. - #1302 and Pasta-Devs/Marinara-Engine#7429 (query/document input type). Neither changes `spaceId`, so they don't trigger this path. - #1304 (show LTM's embedding source and how to change it). - #1295, section 4. ## 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.
bsakaguchi 2026-10-20 17:29:32 +07:00
  • closed this issue
  • added the
    bug
    label
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#664
No description provided.