[GH-ISSUE #1555] [Issue]: Long-Term Memory: an extraction answer cut off at the output limit loses its last memories on every retry #1544

Closed
opened 2026-10-23 04:02:50 +07:00 by bsakaguchi · 0 comments
Owner

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

Originally assigned to: @Promansis on GitHub.

Summary

When the extraction model's answer reaches the output token limit (default 8,192), Long-Term Memory keeps the complete memories written before the cut, marks the source incomplete and offers a retry. The retry sends the same request with the same limit, so it stops at the same place every time. The memories the model writes last are lost for good, usually recurring motifs, open threads and the tone note. Add an opt-in setting, "Finish cut-off answers", that asks the model for the rest of a cut-off answer, and tell users with the setting off why Retry won't help.

Affected package

  • Package: long-term-memory 1.4.80
  • Package type: Agent package (server extraction, Memory Settings)
  • Area: extraction truncation recovery (evidence-unit-extraction.ts), extraction settings, Memory Settings form

Expected behavior

  • With "Finish cut-off answers" on: a source whose answer is longer than the output limit is still extracted completely, within the user's "Maximum output tokens" setting, at the cost of one to three extra requests for that source only. Sources that aren't cut off make no extra request.
  • With it off (the default): nothing extra is spent, and a cut-off source says why Retry won't help and names the setting.

Actual behavior

The answer is cut, the salvaged memories are saved, the source is marked incomplete and retryable, and each retry is cut at the same place. The only message is "Extraction output was cut off by the model limit; the source remains retryable."

Steps to reproduce

  1. Choose an extraction model and a "Maximum output tokens" value small enough that a long chat summary doesn't fit (for example 4,096 with a long headed summary).
  2. Import or re-extract that summary.
  3. The source ends incomplete; Extraction details in Review show the cut-off warning.
  4. Retry: the answer stops at the same place and the same memories are missing.

Measured on 15 real chat summaries with Opus, Sonnet and Haiku as the extraction model at the default 8,192: 1 to 4 answers in 15 per model still pass the limit (worst about 11,200 tokens), losing 3 to 6% of the memories, always the ones written last.

Minimal fix

One PR, patch bump (1.5.0 is reserved for the planned migration release).

S = packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory, H = packages/long-term-memory/src/engine/packages/shared/src/features/agents/long-term-memory, C = packages/long-term-memory/src/engine/packages/client/src/features/long-term-memory.

  • Setting. A boolean extraction setting, default false, added the way aiKeywordExtraction is: H/schema/settings.ts (settings and resolved settings), the default in S/extraction/extraction-config.ts, passed through both extraction calls in S/extraction/source-extraction.ts.
  • Continuation in S/extraction/evidence-unit-extraction.ts, only when the setting is on. When the first answer is cut (finish reason length, max_tokens or token_limit) and at least one memory was salvaged, call the model again with the same messages, the same maxTokens and the same response format, plus a continuation object in the user JSON: an instruction to return only the memories not yet listed, starting with the interrupted stream, and alreadyExtracted: [{ bucket, subjectId, sectionKey, text }] with text cut to 100 characters. Append the new units and drop exact repeats. Repeat while the latest answer is still cut and added at least one unit, at most 3 continuation rounds. If a round adds nothing or the provider rejects the call, keep what is held and finish as today (incomplete, retryable). Record each round in the debug log (rounds, units added). An answer with nothing salvaged is unchanged: no extra call, ltm_model_output_truncated.
  • Hint. When the setting is off and the answer was cut after at least one memory was salvaged, the ltm_model_output_incomplete warning says: "The answer stopped at the output limit, so Retry will stop at the same place. Turn on 'Finish cut-off answers' in Memory Settings to fetch the rest." With the setting on and the last round still cut, the warning keeps today's text.
  • Memory Settings. A Toggle beside "Maximum output tokens" in C/settings/MemorySettings.tsx (form state as for aiKeywordExtraction), with two strings in C/locales/en.json:
    • label: "Finish cut-off answers"
    • help: "When the model's answer stops at the output limit, ask it for the rest. Up to 3 extra requests for that source, each sending the source again."
  • CHANGELOG under ## Unreleased: a new setting in Memory Settings, "Finish cut-off answers", off by default; with it on, an extraction cut off at the output limit asks the model for the rest (up to 3 extra requests for that source); with it off, a cut-off source now says Retry will stop at the same place and names the setting.

Not included

  • Raising the 8,192 default. Saved settings already store 8,192, and about 110 models in the Engine's model table can't produce more than 4,096 or 8,192 output tokens, so a larger request would be refused there.
  • Retrying with a doubled budget. It helps only models with room above the limit and overrides the user's setting.
  • A new draft diagnostic for the continuation. Draft diagnostics allow only warning and error; the debug log records the rounds.
  • Engine changes: clamping package requests to the model's known output limit, and passing that limit to packages.

Regression proof

  • tests/long-term-memory-extraction-reliability.regression.ts, next to the existing recovered-truncation case:
    • setting off: a cut answer with one salvaged unit makes exactly 1 call, stays incomplete, and the warning names the setting.
    • setting on: a cut answer, then a complete continuation. Expect 2 calls; the second request's user JSON carries continuation.alreadyExtracted with the salvaged unit; units are merged with exact repeats dropped; incomplete is false.
    • setting on, the continuation is cut again every time and keeps adding units: expect 1 + 3 calls and the final state incomplete, with today's warning text.
    • setting on, a continuation that adds nothing, and one where the provider throws: the run keeps the salvaged units and ends incomplete without failing.
    • setting on, nothing salvaged: still 1 call and ltm_model_output_truncated (the existing cases).
  • The off, on and round-limit cases fail today and pass with the fix.
  • tests/long-term-memory-storage.regression.ts: the new setting saves, reads back and defaults to false when absent.

Environment

  • Marinara Engine version: 2.5.1 (staging 87d1ccadc)
  • Package version: long-term-memory 1.4.80 (upstream/staging 2a473d3eb)
  • Install type: source (code reading, regression tests and a measurement harness)
  • OS + version: any
  • Browser or app shell: any

Logs, screenshots, or video

None. The measurement replayed cached answers from three models cut at 4,096 and 8,192 tokens and compared the stored memories by meaning:

  • cut only, 4,096: about a third of the memories gone (around 100 facts over 12 or 13 cut sources per model); with the continuation, 8 to 13, the same as two runs on the same text, and the memory count matches the full answer's.
  • cut only, 8,192: 15 to 21 facts lost over 2 or 3 cut sources per model; with the continuation, 1 or 2.
  • cost: each continuation answer is 2,000 to 3,000 tokens (median), never above 2,900 at 8,192, plus the prompt sent again. At 4,096, 2 or 3 continuations in 13 needed a second round.
  • side effect: about 1.5 extra near-duplicate memories per cut source at 4,096 (0.3 at 8,192), handled by the existing deduplication and reconciliation.

Additional context

Tracker item EX-I13. Follows the extraction prompt clean-ups in #1512 and #1513, which made cut answers rarer but didn't remove them.

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 21, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1555 Originally assigned to: @Promansis on GitHub. ## Summary When the extraction model's answer reaches the output token limit (default 8,192), Long-Term Memory keeps the complete memories written before the cut, marks the source incomplete and offers a retry. The retry sends the same request with the same limit, so it stops at the same place every time. The memories the model writes last are lost for good, usually recurring motifs, open threads and the tone note. Add an opt-in setting, "Finish cut-off answers", that asks the model for the rest of a cut-off answer, and tell users with the setting off why Retry won't help. ## Affected package - Package: `long-term-memory` 1.4.80 - Package type: Agent package (server extraction, Memory Settings) - Area: extraction truncation recovery (`evidence-unit-extraction.ts`), extraction settings, Memory Settings form ## Expected behavior - With "Finish cut-off answers" on: a source whose answer is longer than the output limit is still extracted completely, within the user's "Maximum output tokens" setting, at the cost of one to three extra requests for that source only. Sources that aren't cut off make no extra request. - With it off (the default): nothing extra is spent, and a cut-off source says why Retry won't help and names the setting. ## Actual behavior The answer is cut, the salvaged memories are saved, the source is marked incomplete and retryable, and each retry is cut at the same place. The only message is "Extraction output was cut off by the model limit; the source remains retryable." ## Steps to reproduce 1. Choose an extraction model and a "Maximum output tokens" value small enough that a long chat summary doesn't fit (for example 4,096 with a long headed summary). 2. Import or re-extract that summary. 3. The source ends incomplete; Extraction details in Review show the cut-off warning. 4. Retry: the answer stops at the same place and the same memories are missing. Measured on 15 real chat summaries with Opus, Sonnet and Haiku as the extraction model at the default 8,192: 1 to 4 answers in 15 per model still pass the limit (worst about 11,200 tokens), losing 3 to 6% of the memories, always the ones written last. ## Minimal fix One PR, patch bump (1.5.0 is reserved for the planned migration release). S = `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory`, H = `packages/long-term-memory/src/engine/packages/shared/src/features/agents/long-term-memory`, C = `packages/long-term-memory/src/engine/packages/client/src/features/long-term-memory`. - **Setting.** A boolean extraction setting, default `false`, added the way `aiKeywordExtraction` is: `H/schema/settings.ts` (settings and resolved settings), the default in `S/extraction/extraction-config.ts`, passed through both extraction calls in `S/extraction/source-extraction.ts`. - **Continuation** in `S/extraction/evidence-unit-extraction.ts`, only when the setting is on. When the first answer is cut (finish reason `length`, `max_tokens` or `token_limit`) and at least one memory was salvaged, call the model again with the same messages, the same `maxTokens` and the same response format, plus a `continuation` object in the user JSON: an instruction to return only the memories not yet listed, starting with the interrupted stream, and `alreadyExtracted: [{ bucket, subjectId, sectionKey, text }]` with text cut to 100 characters. Append the new units and drop exact repeats. Repeat while the latest answer is still cut and added at least one unit, at most 3 continuation rounds. If a round adds nothing or the provider rejects the call, keep what is held and finish as today (`incomplete`, retryable). Record each round in the debug log (rounds, units added). An answer with nothing salvaged is unchanged: no extra call, `ltm_model_output_truncated`. - **Hint.** When the setting is off and the answer was cut after at least one memory was salvaged, the `ltm_model_output_incomplete` warning says: "The answer stopped at the output limit, so Retry will stop at the same place. Turn on 'Finish cut-off answers' in Memory Settings to fetch the rest." With the setting on and the last round still cut, the warning keeps today's text. - **Memory Settings.** A `Toggle` beside "Maximum output tokens" in `C/settings/MemorySettings.tsx` (form state as for `aiKeywordExtraction`), with two strings in `C/locales/en.json`: - label: "Finish cut-off answers" - help: "When the model's answer stops at the output limit, ask it for the rest. Up to 3 extra requests for that source, each sending the source again." - **CHANGELOG under `## Unreleased`**: a new setting in Memory Settings, "Finish cut-off answers", off by default; with it on, an extraction cut off at the output limit asks the model for the rest (up to 3 extra requests for that source); with it off, a cut-off source now says Retry will stop at the same place and names the setting. **Not included** - Raising the 8,192 default. Saved settings already store 8,192, and about 110 models in the Engine's model table can't produce more than 4,096 or 8,192 output tokens, so a larger request would be refused there. - Retrying with a doubled budget. It helps only models with room above the limit and overrides the user's setting. - A new draft diagnostic for the continuation. Draft diagnostics allow only `warning` and `error`; the debug log records the rounds. - Engine changes: clamping package requests to the model's known output limit, and passing that limit to packages. ## Regression proof - `tests/long-term-memory-extraction-reliability.regression.ts`, next to the existing recovered-truncation case: - setting off: a cut answer with one salvaged unit makes exactly 1 call, stays `incomplete`, and the warning names the setting. - setting on: a cut answer, then a complete continuation. Expect 2 calls; the second request's user JSON carries `continuation.alreadyExtracted` with the salvaged unit; units are merged with exact repeats dropped; `incomplete` is false. - setting on, the continuation is cut again every time and keeps adding units: expect 1 + 3 calls and the final state incomplete, with today's warning text. - setting on, a continuation that adds nothing, and one where the provider throws: the run keeps the salvaged units and ends incomplete without failing. - setting on, nothing salvaged: still 1 call and `ltm_model_output_truncated` (the existing cases). - The off, on and round-limit cases fail today and pass with the fix. - `tests/long-term-memory-storage.regression.ts`: the new setting saves, reads back and defaults to `false` when absent. ## Environment - Marinara Engine version: 2.5.1 (`staging` 87d1ccadc) - Package version: long-term-memory 1.4.80 (`upstream/staging` 2a473d3eb) - Install type: source (code reading, regression tests and a measurement harness) - OS + version: any - Browser or app shell: any ## Logs, screenshots, or video None. The measurement replayed cached answers from three models cut at 4,096 and 8,192 tokens and compared the stored memories by meaning: - cut only, 4,096: about a third of the memories gone (around 100 facts over 12 or 13 cut sources per model); with the continuation, 8 to 13, the same as two runs on the same text, and the memory count matches the full answer's. - cut only, 8,192: 15 to 21 facts lost over 2 or 3 cut sources per model; with the continuation, 1 or 2. - cost: each continuation answer is 2,000 to 3,000 tokens (median), never above 2,900 at 8,192, plus the prompt sent again. At 4,096, 2 or 3 continuations in 13 needed a second round. - side effect: about 1.5 extra near-duplicate memories per cut source at 4,096 (0.3 at 8,192), handled by the existing deduplication and reconciliation. ## Additional context Tracker item EX-I13. Follows the extraction prompt clean-ups in #1512 and #1513, which made cut answers rarer but didn't remove them. ## 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-23 04:02:50 +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-Agents#1544
No description provided.