[GH-ISSUE #1881] [Issue]: A quoted importance score drops every memory in a chat piece, and the piece still reports success #1803

Closed
opened 2026-11-07 16:36:46 +07:00 by bsakaguchi · 0 comments
Owner

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

Originally assigned to: @Promansis on GitHub.

Summary

When the extraction model writes a memory's salience or confidence as quoted text ("0.5" instead of 0.5),
Long-Term Memory rejects that memory as malformed. If the model quotes it on every memory, as it tends to once it
starts, the whole piece of chat is lost. The piece still reports succeeded with nothing kept, so the player never
learns that part of the chat was skipped, and nothing offers a retry.

Affected package

long-term-memory (Long-Term Memory)

Expected behavior

  • A numeric score written as quoted text is read as that number, and the memory is kept.
  • If every memory the model returned for a piece is still rejected as malformed, the piece fails with the existing
    retryable "unusable output" error, instead of succeeding with nothing.

Actual behavior

ltmProviderEvidenceUnitSchema (server/src/services/long-term-memory/extraction/evidence-unit-extraction.ts:167)
is built from ltmEvidenceUnitSchema, whose confidence and salience are
z.number().finite().min(0).max(1) with no coercion
(shared/src/features/agents/long-term-memory/schema/notes.ts:193-194). normalizeEvidenceUnitResponse (:673)
runs first but does not touch either score. So in parseEvidenceUnitPayload (:1000-1080) each quoted candidate
fails safeParse and is dropped as invalid_format.

The caller (:1587-1598) only fails a parse with zero kept memories when the answer was cut off
(incomplete && parsed.response.units.length === 0 → ltm_model_output_truncated). A complete answer whose
candidates were all dropped falls through as a success.

Seen on 2026-10-29 in 1 of 124 extraction calls during a whole-chat measurement run: Sonnet wrote every unit's
salience as a string, all 16 candidates were dropped, and the piece reported succeeded with 0 kept.

Steps to reproduce

  1. Run Chat messages import with an extraction model that returns a complete evidence-unit response in which every
    unit has "salience": "0.5" (a string).
  2. Open the import's debug activity: evidence_unit_json_parse shows units: 0 and parserRejections equal to
    totalCandidates, each dropped as invalid_format.
  3. The piece is shown as succeeded, with no memories and no retry.

Environment

  • Marinara Engine version: staging host
  • Package version: Long-Term Memory 1.5.10 (code unchanged since at least 1.5.8)
  • Install type: source
  • OS + version: any
  • Browser or app shell: any

Logs, screenshots, or video

The model's response is kept privately; the cause is in the code paths above. No chat text is needed to reproduce it.

Additional context

Minimal fix (server only, no schema or settings change)

  1. Read quoted scores as numbers. In evidence-unit-extraction.ts, extend ltmProviderEvidenceUnitSchema
    (:167) so confidence and salience pass through a z.preprocess that turns a trimmed string which parses
    as a finite number into that number, then applies the existing ltmEvidenceUnitSchema.shape.confidence /
    .salience check. Anything else is left as is and still fails. Don't use z.coerce.number(): it turns ""
    and null into 0. The stored-unit schema in notes.ts stays strict.
  2. Fail a piece when every candidate was malformed. In the caller, next to the existing cut-off guard
    (:1593), throw the existing retryable error when parsed.totalCandidates > 0 && parsed.response.units.length === 0:
    new LtmServiceError("unusable_output: every extraction candidate was malformed; the source remains retryable", 400, "ltm_model_output_unusable"). It runs inside the existing try, so the error is logged as an
    evidence_unit_json_parse error event and rethrown along the same path as the current "no response object"
    error. An answer with no candidates (units: []) still succeeds: that piece really had nothing to keep.
  3. packages/long-term-memory/CHANGELOG.md: one line under ## Unreleased. Patch; the version is set at land.

Proof

Extend tests/long-term-memory-extraction-reliability.regression.ts:

  • parseEvidenceUnitPayload with "salience": "0.5" and "confidence": " 0.8 " keeps the unit with numbers 0.5
    and 0.8.
  • "salience": "high", "" and "1.5" are still dropped as invalid_format.
  • In the existing provider-response loop near line 128: a complete response whose units are all malformed throws
    ltm_model_output_unusable without a repair call; a complete {"summary":"…","units":[]} still succeeds; one
    valid plus one malformed unit keeps the valid one and does not throw.

Run that suite, tests/long-term-memory-extraction-graph.regression.ts, test-fast.sh and npm run check.

Non-goals

  • Changing notes.ts, the stored-unit schema or the JSON schema sent to the model (:479-480).
  • Coercing any other field.
  • Any UI change: the failed piece uses the existing retry.
  • Any Engine change.

Tracker: OT-26.

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @Promansis on GitHub (Oct 29, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1881 Originally assigned to: @Promansis on GitHub. ## Summary When the extraction model writes a memory's `salience` or `confidence` as quoted text (`"0.5"` instead of `0.5`), Long-Term Memory rejects that memory as malformed. If the model quotes it on every memory, as it tends to once it starts, the whole piece of chat is lost. The piece still reports `succeeded` with nothing kept, so the player never learns that part of the chat was skipped, and nothing offers a retry. ## Affected package `long-term-memory` (Long-Term Memory) ## Expected behavior - A numeric score written as quoted text is read as that number, and the memory is kept. - If every memory the model returned for a piece is still rejected as malformed, the piece fails with the existing retryable "unusable output" error, instead of succeeding with nothing. ## Actual behavior `ltmProviderEvidenceUnitSchema` (`server/src/services/long-term-memory/extraction/evidence-unit-extraction.ts:167`) is built from `ltmEvidenceUnitSchema`, whose `confidence` and `salience` are `z.number().finite().min(0).max(1)` with no coercion (`shared/src/features/agents/long-term-memory/schema/notes.ts:193-194`). `normalizeEvidenceUnitResponse` (`:673`) runs first but does not touch either score. So in `parseEvidenceUnitPayload` (`:1000-1080`) each quoted candidate fails `safeParse` and is dropped as `invalid_format`. The caller (`:1587-1598`) only fails a parse with zero kept memories when the answer was cut off (`incomplete && parsed.response.units.length === 0` → `ltm_model_output_truncated`). A complete answer whose candidates were all dropped falls through as a success. Seen on 2026-10-29 in 1 of 124 extraction calls during a whole-chat measurement run: Sonnet wrote every unit's `salience` as a string, all 16 candidates were dropped, and the piece reported `succeeded` with 0 kept. ## Steps to reproduce 1. Run Chat messages import with an extraction model that returns a complete evidence-unit response in which every unit has `"salience": "0.5"` (a string). 2. Open the import's debug activity: `evidence_unit_json_parse` shows `units: 0` and `parserRejections` equal to `totalCandidates`, each dropped as `invalid_format`. 3. The piece is shown as succeeded, with no memories and no retry. ## Environment - Marinara Engine version: staging host - Package version: Long-Term Memory 1.5.10 (code unchanged since at least 1.5.8) - Install type: source - OS + version: any - Browser or app shell: any ## Logs, screenshots, or video The model's response is kept privately; the cause is in the code paths above. No chat text is needed to reproduce it. ## Additional context ### Minimal fix (server only, no schema or settings change) 1. **Read quoted scores as numbers.** In `evidence-unit-extraction.ts`, extend `ltmProviderEvidenceUnitSchema` (`:167`) so `confidence` and `salience` pass through a `z.preprocess` that turns a trimmed string which parses as a finite number into that number, then applies the existing `ltmEvidenceUnitSchema.shape.confidence` / `.salience` check. Anything else is left as is and still fails. Don't use `z.coerce.number()`: it turns `""` and `null` into `0`. The stored-unit schema in `notes.ts` stays strict. 2. **Fail a piece when every candidate was malformed.** In the caller, next to the existing cut-off guard (`:1593`), throw the existing retryable error when `parsed.totalCandidates > 0 && parsed.response.units.length === 0`: `new LtmServiceError("unusable_output: every extraction candidate was malformed; the source remains retryable", 400, "ltm_model_output_unusable")`. It runs inside the existing `try`, so the error is logged as an `evidence_unit_json_parse` error event and rethrown along the same path as the current "no response object" error. An answer with no candidates (`units: []`) still succeeds: that piece really had nothing to keep. 3. `packages/long-term-memory/CHANGELOG.md`: one line under `## Unreleased`. Patch; the version is set at land. ### Proof Extend `tests/long-term-memory-extraction-reliability.regression.ts`: - `parseEvidenceUnitPayload` with `"salience": "0.5"` and `"confidence": " 0.8 "` keeps the unit with numbers `0.5` and `0.8`. - `"salience": "high"`, `""` and `"1.5"` are still dropped as `invalid_format`. - In the existing provider-response loop near line 128: a complete response whose units are all malformed throws `ltm_model_output_unusable` without a repair call; a complete `{"summary":"…","units":[]}` still succeeds; one valid plus one malformed unit keeps the valid one and does not throw. Run that suite, `tests/long-term-memory-extraction-graph.regression.ts`, `test-fast.sh` and `npm run check`. ### Non-goals - Changing `notes.ts`, the stored-unit schema or the JSON schema sent to the model (`:479-480`). - Coercing any other field. - Any UI change: the failed piece uses the existing retry. - Any Engine change. Tracker: OT-26. ## Template check - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-11-07 16:36:46 +07:00
  • closed this issue
  • added the
    bug
    server
    labels
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#1803
No description provided.