[GH-ISSUE #7044] [Issue]: Limit LTM recall input to filtered conversation history #3944

Closed
opened 2026-10-21 06:08:56 +07:00 by bsakaguchi · 0 comments
Owner

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

Originally assigned to: @Promansis on GitHub.

Summary

Engine sends the assembled prompt, including preset/agent injections, as Long-Term Memory (LTM) recall input. Non-history text can occupy the package's recent-message query window and add or displace memories unrelated to the actual conversation.

Expected behavior

Pass only conversation-history messages to LTM, after the existing Advanced Memory history filtering. Preserve legitimate narrator/system history and existing audience/character/history-start restrictions. Leave query-window size, query construction, retrieval and ranking in the package.

Actual behavior

The generation handoff maps sharedPromptForAgents(finalMessages) directly to role/content. The shared Advanced Memory helper intentionally retains non-history prompt messages, and the handoff then discards their contextKind origin metadata. The package takes the last configured number of supplied messages, so tail injections can enter the query and displace recent conversation turns.

Steps to reproduce

Earlier investigation exercised actual Engine prompt/history helpers and the activated LTM package with synthetic notes. A real-provider/browser generation-route reproduction has not been run:

  1. Use a four-message recall window and four conversation turns about an observatory, with synthetic observatory and pineapple notes.
  2. Append one or more non-history preset/agent injections about pineapples after the history, then pass the current Engine handoff to LTM.
  3. Capture the package query and injected-memory artifact. The earlier fixture showed one tail injection replacing one history turn; four tail injections removed all four history turns from the query. The injected topic added/displaced recalled notes, while the history-only control retained the conversation topic.

Environment

  • Marinara Engine version: upstream staging, source inspected at 35621d44bbe7bf3336943e1076e4e8065a8b835a; no release-build reproduction claimed.
  • Install type: source inspection and earlier disposable helper-to-runtime fixtures, not an installer/container test.
  • OS + version: Linux investigation host; distribution/version not recorded.
  • Browser or app shell: not exercised.

Logs, screenshots, or video

Earlier synthetic characterization covered 18 cases. Its characterization assertions passed; the desired history-only assertion failed at the first tail-injection case. With a one-chunk budget, the injected topic could displace the conversation-relevant note. The history-only control also preserved narrator/system history and did not reintroduce history excluded by Advanced Memory.

That fixture was not rerun for this filing. Live-chat frequency, provider/model quality and full HTTP/browser behavior remain unmeasured. Current Engine handoff and current package query selection still retain the reported behavior; recent Agents diagnostic additions do not change this input selection.

Current source references:

Additional context

Keep this as a small Engine input-boundary fix:

  • Filter by message origin/history metadata at the LTM handoff, after existing Advanced Memory filtering and before metadata is stripped. Do not filter by role alone: legitimate history may have a system/narrator role.
  • Do not change sharedPromptForAgents globally: other agents still need their existing prompt inputs. Preserve current recall enablement/regeneration behavior and the final provider prompt/injection placement.
  • Do not reintroduce filtered-out history or change group-chat targeting, query-window settings, scoring, ranking or memory budgets. Target-character recall is already handled separately in Marinara-Agents #1194 / PR #1196.
  • This issue is independent of profile restore, connection-save refresh and deferred sidecar identity work. No new Engine memory query builder, cache or indexing code is required.

Implementation proof should capture the actual package query for no-injection, before/after-history injection, multiple tail injections, and Advanced Memory enabled/disabled cases. Preserve narrator/system history and audience/history-start exclusions; verify other agents and the final provider prompt remain unchanged. Reuse prompt-scope/Advanced Memory regression infrastructure and a focused package-runtime handoff proof, then run repository-required validation. None of the post-fix gates has been run for this filing.

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 4, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/7044 Originally assigned to: @Promansis on GitHub. ## Summary Engine sends the assembled prompt, including preset/agent injections, as Long-Term Memory (LTM) recall input. Non-history text can occupy the package's recent-message query window and add or displace memories unrelated to the actual conversation. ## Expected behavior Pass only conversation-history messages to LTM, after the existing Advanced Memory history filtering. Preserve legitimate narrator/system history and existing audience/character/history-start restrictions. Leave query-window size, query construction, retrieval and ranking in the package. ## Actual behavior The generation handoff maps `sharedPromptForAgents(finalMessages)` directly to role/content. The shared Advanced Memory helper intentionally retains non-history prompt messages, and the handoff then discards their `contextKind` origin metadata. The package takes the last configured number of supplied messages, so tail injections can enter the query and displace recent conversation turns. ## Steps to reproduce Earlier investigation exercised actual Engine prompt/history helpers and the activated LTM package with synthetic notes. A real-provider/browser generation-route reproduction has not been run: 1. Use a four-message recall window and four conversation turns about an observatory, with synthetic observatory and pineapple notes. 2. Append one or more non-history preset/agent injections about pineapples after the history, then pass the current Engine handoff to LTM. 3. Capture the package query and injected-memory artifact. The earlier fixture showed one tail injection replacing one history turn; four tail injections removed all four history turns from the query. The injected topic added/displaced recalled notes, while the history-only control retained the conversation topic. ## Environment - Marinara Engine version: upstream `staging`, source inspected at `35621d44bbe7bf3336943e1076e4e8065a8b835a`; no release-build reproduction claimed. - Install type: source inspection and earlier disposable helper-to-runtime fixtures, not an installer/container test. - OS + version: Linux investigation host; distribution/version not recorded. - Browser or app shell: not exercised. ## Logs, screenshots, or video Earlier synthetic characterization covered 18 cases. Its characterization assertions passed; the desired history-only assertion failed at the first tail-injection case. With a one-chunk budget, the injected topic could displace the conversation-relevant note. The history-only control also preserved narrator/system history and did not reintroduce history excluded by Advanced Memory. That fixture was not rerun for this filing. Live-chat frequency, provider/model quality and full HTTP/browser behavior remain unmeasured. Current Engine handoff and current package query selection still retain the reported behavior; recent Agents diagnostic additions do not change this input selection. Current source references: - [LTM generation handoff](https://github.com/Pasta-Devs/Marinara-Engine/blob/35621d44bbe7bf3336943e1076e4e8065a8b835a/packages/server/src/routes/generate.routes.ts#L6764-L6772). - [Shared history filter retaining non-history messages](https://github.com/Pasta-Devs/Marinara-Engine/blob/35621d44bbe7bf3336943e1076e4e8065a8b835a/packages/server/src/services/generation/prompt-message-scope.ts#L273-L286). - [Package recent-message query construction](https://github.com/Pasta-Devs/Marinara-Agents/blob/ef64aeb7b4d82a509ce70c98412f2ec89367913e/packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/generation-injection.ts#L124-L128). ## Additional context Keep this as a small Engine input-boundary fix: - Filter by message origin/history metadata at the LTM handoff, after existing Advanced Memory filtering and before metadata is stripped. Do not filter by role alone: legitimate history may have a system/narrator role. - Do not change `sharedPromptForAgents` globally: other agents still need their existing prompt inputs. Preserve current recall enablement/regeneration behavior and the final provider prompt/injection placement. - Do not reintroduce filtered-out history or change group-chat targeting, query-window settings, scoring, ranking or memory budgets. Target-character recall is already handled separately in [Marinara-Agents #1194](https://github.com/Pasta-Devs/Marinara-Agents/issues/1194) / [PR #1196](https://github.com/Pasta-Devs/Marinara-Agents/pull/1196). - This issue is independent of profile restore, connection-save refresh and deferred sidecar identity work. No new Engine memory query builder, cache or indexing code is required. Implementation proof should capture the actual package query for no-injection, before/after-history injection, multiple tail injections, and Advanced Memory enabled/disabled cases. Preserve narrator/system history and audience/history-start exclusions; verify other agents and the final provider prompt remain unchanged. Reuse prompt-scope/Advanced Memory regression infrastructure and a focused package-runtime handoff proof, then run repository-required validation. None of the post-fix gates has been run for this filing. ## 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-21 06:08:56 +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#3944
No description provided.