[PR #1558] [MERGED] fix(long-term-memory): add "Finish cut-off answers" to ask for the rest of a cut extraction answer (#1555) #1563

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Agents/pull/1558
Author: @Promansis
Created: 10/22/2026
Status: ✅ Merged
Merged: 10/22/2026
Merged by: @Promansis

Base: staging ← Head: fix(long-term-memory)/extraction-output-continuation


📝 Commits (3)

  • 7322e4e fix(long-term-memory): add "Finish cut-off answers" to ask for the rest of a cut extraction answer (#1555)
  • c029e38 chore(long-term-memory): release 1.4.81 (#1555)
  • bc81473 fix(long-term-memory): fit each continuation request to the model's context (#1555)

📊 Changes

20 files changed (+471 additions, -116 deletions)

View changed files

➕ artifacts/long-term-memory-1.4.81.zip (+0 -0)
📝 catalog/catalog.json (+8 -8)
📝 catalog/notes.json (+6 -6)
📝 catalog/v2/catalog.json (+8 -8)
📝 catalog/v2/notes.json (+6 -6)
📝 catalog/v3/catalog.json (+8 -8)
📝 catalog/v3/notes.json (+6 -6)
📝 packages/long-term-memory/CHANGELOG.md (+4 -0)
📝 packages/long-term-memory/client.js (+16 -16)
📝 packages/long-term-memory/manifest.json (+5 -5)
📝 packages/long-term-memory/server.mjs (+38 -38)
📝 packages/long-term-memory/src/engine/packages/client/src/features/long-term-memory/locales/en.json (+2 -0)
📝 packages/long-term-memory/src/engine/packages/client/src/features/long-term-memory/settings/MemorySettings.tsx (+12 -0)
📝 packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/extraction/evidence-unit-extraction.ts (+154 -4)
📝 packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/extraction/extraction-config.ts (+1 -0)
📝 packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/extraction/source-extraction.ts (+3 -0)
📝 packages/long-term-memory/src/engine/packages/shared/src/features/agents/long-term-memory/schema/settings.ts (+2 -0)
📝 scripts/build-feature-packages.mjs (+1 -1)
📝 tests/long-term-memory-extraction-reliability.regression.ts (+188 -9)
📝 tests/long-term-memory-storage.regression.ts (+3 -1)

📄 Description

Pull request

Linked issue

Closes #1555

Why this change

  • When the extraction model's answer reaches the output token limit, Long-Term Memory keeps the complete memories written before the cut and marks the source incomplete and retryable. Retry sends the same request with the same limit, so it stops at the same place every time, and the memories the model writes last (usually recurring motifs, open threads and the tone note) are lost for good. Measured on 15 real chat summaries at the default 8,192: 1 to 4 answers in 15 per model (Opus, Sonnet, Haiku) still pass the limit, losing 3 to 6% of the memories.
  • Raising the default doesn't work: 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. Asking the model for the rest stays within the user's own "Maximum output tokens".

What changed

  • long-term-memory 1.4.81: a new extraction setting, "Finish cut-off answers" (finishCutOffAnswers), off by default, added the way aiKeywordExtraction is (shared settings schema, extraction defaults, passed through both extraction calls and the source_note_loaded debug details).
  • With it on, a cut-off answer with at least one memory saved from it gets up to 3 continuation requests:
first answer cut (length / max_tokens / token_limit) and ≥1 memory salvaged
  repeat, at most 3 rounds:
    same messages, same maxTokens (fitted again when a known model context needs it), same response format
      + user JSON continuation: { instruction, alreadyExtracted: [{bucket, subjectId, sectionKey, text ≤100 chars}] }
    append new memories, drop exact repeats
    debug log: evidence_unit_continuation (round, addedUnits, units, responseChars, finishReason)
    stop when the answer is not cut (complete) or the round added nothing / the call failed (incomplete, retryable)
  • Repeats are not counted as candidates; memories past the 999-candidate cap count as parser rejections, so the extraction counts still balance.
  • Each continuation runs the same context preflight as the first request, because the list of memories already written makes its prompt longer: on a model with a known context, maxTokens is lowered only when the longer prompt would not fit with it (added after CodeRabbit review).
  • A cancel during a continuation still cancels the extraction; any other failure, including a preflight that finds no viable budget, keeps the memories already held.
  • An answer with nothing salvaged is unchanged: no extra call, ltm_model_output_truncated.
  • With it off, the ltm_model_output_incomplete warning now reads: "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 it on and the last round still cut, the warning keeps today's text.
  • Memory Settings: a toggle right after "Maximum output tokens", with the label "Finish cut-off answers" and the 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."
  • Regressions in tests/long-term-memory-extraction-reliability.regression.ts and tests/long-term-memory-storage.regression.ts. Rebuilt packages/long-term-memory bundles, manifest, artifact and catalog entries.

Package and security impact

  • Affected package IDs: long-term-memory
  • Engine compatibility impact: none
  • New or changed permissions/entrypoints: none
  • Restart, storage, update, or uninstall impact: one new optional boolean in the saved extraction settings; absent reads as off, so existing vaults behave as before. With the setting on, a cut-off source costs up to 3 extra model requests, each sending the source again. A continuation that ends without the cut but adds nothing leaves the source incomplete, so each Retry of that source costs 2 requests.

Validation

  • node scripts/validate-catalog.mjs passes locally
  • git diff --check passes locally
  • Rebuilt every affected manifest, payload, artifact, and catalog entry
  • Installed or updated the affected package through Marinara Engine
  • Checked supported modes, restart behavior, and uninstall cleanup
  • Read and followed CONTRIBUTING.md

Manual verification notes

  • New regression steps: setting off, 1 call, incomplete, the warning names the setting (also checked through processLongTermMemorySource); setting on, a complete continuation makes 2 calls, the second request carries the salvaged memory in continuation.alreadyExtracted with the same source text, maxTokens and response format, the repeat is dropped, the source is complete and the counts balance; with a known context whose fit lowers the continuation budget, the second request is sent with the lower maxTokens and the source completes; a continuation cut every time makes 1 + 3 calls and ends incomplete with today's warning; a round that adds nothing and a provider failure keep the salvaged memory and end incomplete; a cancel during a continuation rejects with the original error; nothing salvaged stays 1 call with the setting off and on; the setting defaults to off and saves and reads back on.
  • Against staging (2a473d3eb) the off, on and storage-default steps fail (old warning text, 1 call where 2 are expected, setting undefined); the cancel step fails with its abort check removed. All pass with the fix.
  • On the fix commit: npm run check, the package typecheck and build, the catalog, locale and release-notes checks, and the extraction-reliability, storage, routes, browser, loading, extraction-graph, local-characters and candidate-reconciliation suites pass.
  • After CodeRabbit review (bc8147301): the new fitted-budget step fails on the previous head (8,192 sent where 2,000 was fitted) and passes with the fix.
  • On the release head (bc8147301): the package rebuild leaves the tree clean, npm run check, the typecheck and the catalog, locale and release-notes checks pass, and the extraction-reliability and storage suites (the two regression files this PR changes) pass. Hosted CI runs the full suite list on this head.

Documentation impact

  • No documentation changes needed
  • Updated this README catalog and package guidance
  • Updated linked Marinara Engine documentation

UI evidence (if applicable)

No screenshot: the change adds one toggle with help text to the existing Memory Settings form, next to "Maximum output tokens".

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Agents/pull/1558 **Author:** [@Promansis](https://github.com/Promansis) **Created:** 10/22/2026 **Status:** ✅ Merged **Merged:** 10/22/2026 **Merged by:** [@Promansis](https://github.com/Promansis) **Base:** `staging` ← **Head:** `fix(long-term-memory)/extraction-output-continuation` --- ### 📝 Commits (3) - [`7322e4e`](https://github.com/Pasta-Devs/Marinara-Agents/commit/7322e4e8e2883b6155fa277cc7b1f8322f29c5a9) fix(long-term-memory): add "Finish cut-off answers" to ask for the rest of a cut extraction answer (#1555) - [`c029e38`](https://github.com/Pasta-Devs/Marinara-Agents/commit/c029e38e17136e85f474518eba06d3e51710e0f2) chore(long-term-memory): release 1.4.81 (#1555) - [`bc81473`](https://github.com/Pasta-Devs/Marinara-Agents/commit/bc8147301422b37f54eb8b1a117b0449b2f6d8c4) fix(long-term-memory): fit each continuation request to the model's context (#1555) ### 📊 Changes **20 files changed** (+471 additions, -116 deletions) <details> <summary>View changed files</summary> ➕ `artifacts/long-term-memory-1.4.81.zip` (+0 -0) 📝 `catalog/catalog.json` (+8 -8) 📝 `catalog/notes.json` (+6 -6) 📝 `catalog/v2/catalog.json` (+8 -8) 📝 `catalog/v2/notes.json` (+6 -6) 📝 `catalog/v3/catalog.json` (+8 -8) 📝 `catalog/v3/notes.json` (+6 -6) 📝 `packages/long-term-memory/CHANGELOG.md` (+4 -0) 📝 `packages/long-term-memory/client.js` (+16 -16) 📝 `packages/long-term-memory/manifest.json` (+5 -5) 📝 `packages/long-term-memory/server.mjs` (+38 -38) 📝 `packages/long-term-memory/src/engine/packages/client/src/features/long-term-memory/locales/en.json` (+2 -0) 📝 `packages/long-term-memory/src/engine/packages/client/src/features/long-term-memory/settings/MemorySettings.tsx` (+12 -0) 📝 `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/extraction/evidence-unit-extraction.ts` (+154 -4) 📝 `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/extraction/extraction-config.ts` (+1 -0) 📝 `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/extraction/source-extraction.ts` (+3 -0) 📝 `packages/long-term-memory/src/engine/packages/shared/src/features/agents/long-term-memory/schema/settings.ts` (+2 -0) 📝 `scripts/build-feature-packages.mjs` (+1 -1) 📝 `tests/long-term-memory-extraction-reliability.regression.ts` (+188 -9) 📝 `tests/long-term-memory-storage.regression.ts` (+3 -1) </details> ### 📄 Description # Pull request ## Linked issue Closes #1555 ## Why this change - When the extraction model's answer reaches the output token limit, Long-Term Memory keeps the complete memories written before the cut and marks the source incomplete and retryable. Retry sends the same request with the same limit, so it stops at the same place every time, and the memories the model writes last (usually recurring motifs, open threads and the tone note) are lost for good. Measured on 15 real chat summaries at the default 8,192: 1 to 4 answers in 15 per model (Opus, Sonnet, Haiku) still pass the limit, losing 3 to 6% of the memories. - Raising the default doesn't work: 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. Asking the model for the rest stays within the user's own "Maximum output tokens". ## What changed - `long-term-memory` 1.4.81: a new extraction setting, "Finish cut-off answers" (`finishCutOffAnswers`), off by default, added the way `aiKeywordExtraction` is (shared settings schema, extraction defaults, passed through both extraction calls and the `source_note_loaded` debug details). - With it on, a cut-off answer with at least one memory saved from it gets up to 3 continuation requests: ```text first answer cut (length / max_tokens / token_limit) and ≥1 memory salvaged repeat, at most 3 rounds: same messages, same maxTokens (fitted again when a known model context needs it), same response format + user JSON continuation: { instruction, alreadyExtracted: [{bucket, subjectId, sectionKey, text ≤100 chars}] } append new memories, drop exact repeats debug log: evidence_unit_continuation (round, addedUnits, units, responseChars, finishReason) stop when the answer is not cut (complete) or the round added nothing / the call failed (incomplete, retryable) ``` - Repeats are not counted as candidates; memories past the 999-candidate cap count as parser rejections, so the extraction counts still balance. - Each continuation runs the same context preflight as the first request, because the list of memories already written makes its prompt longer: on a model with a known context, `maxTokens` is lowered only when the longer prompt would not fit with it (added after CodeRabbit review). - A cancel during a continuation still cancels the extraction; any other failure, including a preflight that finds no viable budget, keeps the memories already held. - An answer with nothing salvaged is unchanged: no extra call, `ltm_model_output_truncated`. - With it off, the `ltm_model_output_incomplete` warning now reads: "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 it on and the last round still cut, the warning keeps today's text. - Memory Settings: a toggle right after "Maximum output tokens", with the label "Finish cut-off answers" and the 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." - Regressions in `tests/long-term-memory-extraction-reliability.regression.ts` and `tests/long-term-memory-storage.regression.ts`. Rebuilt `packages/long-term-memory` bundles, manifest, artifact and catalog entries. ## Package and security impact - Affected package IDs: `long-term-memory` - Engine compatibility impact: none - New or changed permissions/entrypoints: none - Restart, storage, update, or uninstall impact: one new optional boolean in the saved extraction settings; absent reads as off, so existing vaults behave as before. With the setting on, a cut-off source costs up to 3 extra model requests, each sending the source again. A continuation that ends without the cut but adds nothing leaves the source incomplete, so each Retry of that source costs 2 requests. ## Validation - [ ] `node scripts/validate-catalog.mjs` passes locally - [ ] `git diff --check` passes locally - [ ] Rebuilt every affected manifest, payload, artifact, and catalog entry - [ ] Installed or updated the affected package through Marinara Engine - [ ] Checked supported modes, restart behavior, and uninstall cleanup - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes - New regression steps: setting off, 1 call, incomplete, the warning names the setting (also checked through `processLongTermMemorySource`); setting on, a complete continuation makes 2 calls, the second request carries the salvaged memory in `continuation.alreadyExtracted` with the same source text, `maxTokens` and response format, the repeat is dropped, the source is complete and the counts balance; with a known context whose fit lowers the continuation budget, the second request is sent with the lower `maxTokens` and the source completes; a continuation cut every time makes 1 + 3 calls and ends incomplete with today's warning; a round that adds nothing and a provider failure keep the salvaged memory and end incomplete; a cancel during a continuation rejects with the original error; nothing salvaged stays 1 call with the setting off and on; the setting defaults to off and saves and reads back on. - Against `staging` (2a473d3eb) the off, on and storage-default steps fail (old warning text, 1 call where 2 are expected, setting undefined); the cancel step fails with its abort check removed. All pass with the fix. - On the fix commit: `npm run check`, the package typecheck and build, the catalog, locale and release-notes checks, and the extraction-reliability, storage, routes, browser, loading, extraction-graph, local-characters and candidate-reconciliation suites pass. - After CodeRabbit review (bc8147301): the new fitted-budget step fails on the previous head (8,192 sent where 2,000 was fitted) and passes with the fix. - On the release head (bc8147301): the package rebuild leaves the tree clean, `npm run check`, the typecheck and the catalog, locale and release-notes checks pass, and the extraction-reliability and storage suites (the two regression files this PR changes) pass. Hosted CI runs the full suite list on this head. ## Documentation impact - [ ] No documentation changes needed - [ ] Updated this README catalog and package guidance - [ ] Updated linked Marinara Engine documentation ## UI evidence (if applicable) No screenshot: the change adds one toggle with help text to the existing Memory Settings form, next to "Maximum output tokens". 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:03:10 +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#1563
No description provided.