[GH-ISSUE #1197] [Issue]: Long-Term Memory: debug recall explanation must reflect injected chunks and weighted-lane threshold #611

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

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

Originally assigned to: @Promansis on GitHub.

Summary

The Long-Term Memory recall debug event (recall_explanation) reports the pre-serialization candidate list and per-lane score, so it can show memories that were never injected, and it never explains the threshold decision. Fix the diagnostics and the user-facing threshold wording only — do not change scoring or ranking.

Affected package

  • long-term-memory

Expected behavior

  • The debug event's selected list and counts reflect the chunks actually injected into the prompt, i.e. the serialized artifact, not the pre-serialization candidate list.
  • The debug event distinguishes the fused rank score from the per-lane relevanceScore, and exposes whether the threshold accepted or rejected a candidate.
  • Threshold wording explains that the compared value is a lane score capped by the lane's weight, not the fused rank score or a relative top-result normalization.
  • Ranking, threshold values, tiers, and dedup behavior are unchanged.

Actual behavior

  • generation-injection.ts (packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/generation-injection.ts) builds the recall_explanation event from retrieval.chunks (uiSummary ~line 121, selected mapping ~134-141, rejected ~142-149).
  • serializeLongTermMemoryPrompt (.../prompt.ts) can drop chunks to fit the framing/preamble/maxTokens budget (prompt.ts:63-108), returning only the chunks in artifact.chunks. The receipt and UI use the injected artifact, but the debug event can list extra memories that were never sent.
  • score: candidate.relevanceScore in the debug details is max(normalizedRawScore * lane.weight) (.../ranking.ts:60), while ordering uses the fused candidate.score; the threshold also compares candidate.relevanceScore (.../budget.ts:105-114). Debug therefore shows a score that does not explain either rank or the threshold outcome.

Steps to reproduce

  1. Enable Long-Term Memory debug for a chat with more recall candidates than the recall token budget can hold.
  2. Send a generation that triggers recall with a tight maxTokens / budgetTokens.
  3. Open the recall debug event.

Observed in the 2026-10-01 tight-budget fixture: the debug event listed two selected chunks while serializeLongTermMemoryPrompt injected only one.

Environment

  • Marinara Engine version: 2.4.1 or newer (package engine.min)
  • Package version: 1.3.39 (current upstream staging)
  • Install type: source
  • OS + version: server-side; not OS-specific
  • Browser or app shell: debug event viewer (client)

Logs, screenshots, or video

The debug details contain, for each selected/rejected candidate, score: relevanceScore, lanes, reasons, and (for rejected) rejectionReason. They do not contain the fused score or the threshold comparison result. Example threshold behavior under balanced weights (from the characterization fixtures): at threshold=0.50 the #1-ranked candidate is rejected while the #2-ranked candidate is kept.

Additional context

  • Findings record: Part I unit 11 (A16/B11/B1), read-only investigation under marinara-workflow.
  • A16: debug lists pre-serialization chunks.
  • B11: debug shows lane score, not fusion.
  • B1: threshold uses the lane-weight-capped relevanceScore. Per-lane ceilings under balanced weights: direct 1.00, vector 0.60, bm25 0.30, keyword 0.20, graph 0.10, so any threshold >= 0.60 rejects every vector-only match even at high cosine. The threshold is inert by default (0).
  • Scope guard: this must not alter threshold calculations, rank order, budget selection, tier policy, dedup, or the injected prompt content. It is a diagnostics/wording change plus whatever minimal artifact plumbing is needed to report injected chunks accurately.
  • Related but separate: unit 12 removes the unused warnings/cooldown plumbing; unit 6 (A18) changes vector reuse and tone hashing.

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 2, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1197 Originally assigned to: @Promansis on GitHub. ## Summary The Long-Term Memory recall debug event (`recall_explanation`) reports the pre-serialization candidate list and per-lane score, so it can show memories that were never injected, and it never explains the threshold decision. Fix the diagnostics and the user-facing threshold wording only — do not change scoring or ranking. ## Affected package - `long-term-memory` ## Expected behavior - The debug event's selected list and counts reflect the chunks actually injected into the prompt, i.e. the serialized artifact, not the pre-serialization candidate list. - The debug event distinguishes the fused rank score from the per-lane `relevanceScore`, and exposes whether the threshold accepted or rejected a candidate. - Threshold wording explains that the compared value is a lane score capped by the lane's weight, not the fused rank score or a relative top-result normalization. - Ranking, threshold values, tiers, and dedup behavior are unchanged. ## Actual behavior - `generation-injection.ts` (`packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/generation-injection.ts`) builds the `recall_explanation` event from `retrieval.chunks` (uiSummary ~line 121, selected mapping ~134-141, rejected ~142-149). - `serializeLongTermMemoryPrompt` (`.../prompt.ts`) can drop chunks to fit the framing/preamble/maxTokens budget (`prompt.ts:63-108`), returning only the chunks in `artifact.chunks`. The receipt and UI use the injected artifact, but the debug event can list extra memories that were never sent. - `score: candidate.relevanceScore` in the debug details is `max(normalizedRawScore * lane.weight)` (`.../ranking.ts:60`), while ordering uses the fused `candidate.score`; the threshold also compares `candidate.relevanceScore` (`.../budget.ts:105-114`). Debug therefore shows a score that does not explain either rank or the threshold outcome. ## Steps to reproduce 1. Enable Long-Term Memory debug for a chat with more recall candidates than the recall token budget can hold. 2. Send a generation that triggers recall with a tight `maxTokens` / `budgetTokens`. 3. Open the recall debug event. Observed in the 2026-10-01 tight-budget fixture: the debug event listed two selected chunks while `serializeLongTermMemoryPrompt` injected only one. ## Environment - Marinara Engine version: 2.4.1 or newer (package `engine.min`) - Package version: `1.3.39` (current upstream `staging`) - Install type: source - OS + version: server-side; not OS-specific - Browser or app shell: debug event viewer (client) ## Logs, screenshots, or video The debug details contain, for each selected/rejected candidate, `score: relevanceScore`, `lanes`, `reasons`, and (for rejected) `rejectionReason`. They do not contain the fused score or the threshold comparison result. Example threshold behavior under balanced weights (from the characterization fixtures): at `threshold=0.50` the #1-ranked candidate is rejected while the #2-ranked candidate is kept. ## Additional context - Findings record: Part I unit 11 (`A16/B11/B1`), read-only investigation under `marinara-workflow`. - `A16`: debug lists pre-serialization chunks. - `B11`: debug shows lane score, not fusion. - `B1`: threshold uses the lane-weight-capped `relevanceScore`. Per-lane ceilings under balanced weights: direct 1.00, vector 0.60, bm25 0.30, keyword 0.20, graph 0.10, so any threshold >= 0.60 rejects every vector-only match even at high cosine. The threshold is inert by default (`0`). - Scope guard: this must not alter threshold calculations, rank order, budget selection, tier policy, dedup, or the injected prompt content. It is a diagnostics/wording change plus whatever minimal artifact plumbing is needed to report injected chunks accurately. - Related but separate: unit 12 removes the unused `warnings`/cooldown plumbing; unit 6 (A18) changes vector reuse and tone hashing. ## 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:01 +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#611
No description provided.