[PR #1256] [MERGED] fix(long-term-memory): 1.4.11 — reserve prompt overhead and refill dropped memories #1369

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

📋 Pull Request Information

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

Base: staging ← Head: fix(long-term-memory)/1252-prompt-budget-refill


📝 Commits (1)

  • 8383abe fix(long-term-memory): 1.4.11 — reserve prompt overhead and refill dropped memories (#1252)

📊 Changes

16 files changed (+267 additions, -133 deletions)

View changed files

➕ artifacts/long-term-memory-1.4.11.zip (+0 -0)
📝 catalog/catalog.json (+6 -6)
📝 catalog/notes.json (+6 -6)
📝 catalog/v2/catalog.json (+6 -6)
📝 catalog/v2/notes.json (+6 -6)
📝 catalog/v3/catalog.json (+6 -6)
📝 catalog/v3/notes.json (+6 -6)
📝 packages/long-term-memory/CHANGELOG.md (+4 -0)
📝 packages/long-term-memory/manifest.json (+3 -3)
📝 packages/long-term-memory/server.mjs (+44 -42)
📝 packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/budget.ts (+19 -7)
📝 packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/generation-injection.ts (+19 -2)
📝 packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/prompt.ts (+57 -41)
📝 packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/retrieval.ts (+3 -0)
📝 scripts/build-feature-packages.mjs (+1 -1)
📝 tests/long-term-memory-runtime.regression.ts (+81 -1)

📄 Description

Linked issue

Closes #1252

Why this change

  • Long-Term Memory measured only raw chunk text against the recall budget, then assembled the prompt with framing, preamble, labels and escaping on top. The assembled prompt therefore exceeded the limit, and the serializer dropped its tail without reconsidering the smaller chunks it had skipped earlier, so a high-scoring memory could be dropped while a chunk that fit was left out.
  • Review of the fix (repaired before publication) added two cases: retrieval estimated cost from raw legacy chunk text while the serializer renders the label-stripped bullet form, so the reserved overhead could reject a chunk the serializer would have fit; and an empty recall caused by the reserved budget was recorded as no_matches, writing a zero-match injection receipt instead of a prompt-budget skip.

What changed

  • prompt.ts: extracted renderLongTermMemoryPrompt, added estimateLongTermMemoryPromptOverhead and formatLongTermMemoryPromptBullet, and rewrote serializeLongTermMemoryPrompt to re-fit each candidate against the rendered prompt and skip an overflowing chunk instead of popping the tail.
  • generation-injection.ts: reserves the fixed prompt overhead in the retrieval budget (guarding the case where the overhead alone fills it), requests the prompt-normalized token estimate, and records skipped/prompt_budget when the reserved budget rejected every candidate rather than writing a zero-match receipt.
  • budget.ts / retrieval.ts: optional prompt-normalized estimate plus a debug-independent budgetExhausted signal; defaults preserve search and reconciliation callers.
  • tests/long-term-memory-runtime.regression.ts: a/b/c refill case, legacy summary: chunk case, and a budget-exhausted receipt-preservation case.
  • Rebuilt long-term-memory 1.4.11: manifest, server.mjs, artifact ZIP and catalog lane entries; changelog entry added.

Package and security impact

  • Affected package IDs: long-term-memory
  • Engine compatibility impact: none (min 2.4.1 / maxExclusive 4.0.0 unchanged; no capability API change)
  • New or changed permissions/entrypoints: none
  • Restart, storage, update, or uninstall impact: none (recall selection and prompt assembly only; no storage or lifecycle change)

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

On 8383abe57f70eca2a0da875bbffb5ba16f2282d5 (pushed SHA), with MARINARA_AGENTS_ROOT and MARINARA_ENGINE_ROOT set:

  • test-fast.sh (Prettier, ESLint, git diff --check): exit 0.
  • npm run typecheck:packages: pass ("long-term-memory: no syntax errors, undefined names or unresolved modules").
  • test-ltm.sh runtime, test-ltm.sh routes, test-ltm.sh debug-log: pass; runtime includes the new refill, legacy summary: and budget-exhausted cases.
  • test-ltm.sh installation: pass ("Long-Term Memory 1.4.11 installation: install, offline restart, backup inclusion, uninstall, reinstall, and durable-byte preservation ok") against the exact committed ZIP.
  • node scripts/test-catalog-lanes.mjs, node scripts/validate-package-locales.mjs, node scripts/validate-catalog.mjs, node scripts/tests/catalog-release-notes.regression.mjs: pass.
  • Publish proof: repository and independent Engine checkout inputs captured before and after the checks; assertPublishProof verified unchanged on final HEAD immediately before push.
  • Not performed: manual install/update through the Engine UI, and manual mode/restart/uninstall click-through beyond the installation regression.

Documentation impact

  • No documentation changes needed — package README, architecture and UI docs describe the recall flow generically and remain accurate; no catalog membership, compatibility, setup or user-visible workflow changed.
  • Updated this README catalog and package guidance
  • Updated linked Marinara Engine documentation

UI evidence (if applicable)

None — server-side recall selection and prompt assembly change; no client UI surface.

Summary by CodeRabbit

  • Bug Fixes
    • Long-Term Memory now accounts for fixed prompt overhead when selecting recalled information. If a chunk exceeds the available token budget, it is skipped so later, smaller chunks can still be included.
    • When no chunks fit, the system records a prompt-budget skip rather than treating the result as a zero-match recall. Existing injection information is preserved.

🔄 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/1256 **Author:** [@Promansis](https://github.com/Promansis) **Created:** 10/7/2026 **Status:** ✅ Merged **Merged:** 10/7/2026 **Merged by:** [@Promansis](https://github.com/Promansis) **Base:** `staging` ← **Head:** `fix(long-term-memory)/1252-prompt-budget-refill` --- ### 📝 Commits (1) - [`8383abe`](https://github.com/Pasta-Devs/Marinara-Agents/commit/8383abe57f70eca2a0da875bbffb5ba16f2282d5) fix(long-term-memory): 1.4.11 — reserve prompt overhead and refill dropped memories (#1252) ### 📊 Changes **16 files changed** (+267 additions, -133 deletions) <details> <summary>View changed files</summary> ➕ `artifacts/long-term-memory-1.4.11.zip` (+0 -0) 📝 `catalog/catalog.json` (+6 -6) 📝 `catalog/notes.json` (+6 -6) 📝 `catalog/v2/catalog.json` (+6 -6) 📝 `catalog/v2/notes.json` (+6 -6) 📝 `catalog/v3/catalog.json` (+6 -6) 📝 `catalog/v3/notes.json` (+6 -6) 📝 `packages/long-term-memory/CHANGELOG.md` (+4 -0) 📝 `packages/long-term-memory/manifest.json` (+3 -3) 📝 `packages/long-term-memory/server.mjs` (+44 -42) 📝 `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/budget.ts` (+19 -7) 📝 `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/generation-injection.ts` (+19 -2) 📝 `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/prompt.ts` (+57 -41) 📝 `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/retrieval.ts` (+3 -0) 📝 `scripts/build-feature-packages.mjs` (+1 -1) 📝 `tests/long-term-memory-runtime.regression.ts` (+81 -1) </details> ### 📄 Description ## Linked issue Closes #1252 ## Why this change - Long-Term Memory measured only raw chunk text against the recall budget, then assembled the prompt with framing, preamble, labels and escaping on top. The assembled prompt therefore exceeded the limit, and the serializer dropped its tail without reconsidering the smaller chunks it had skipped earlier, so a high-scoring memory could be dropped while a chunk that fit was left out. - Review of the fix (repaired before publication) added two cases: retrieval estimated cost from raw legacy chunk text while the serializer renders the label-stripped bullet form, so the reserved overhead could reject a chunk the serializer would have fit; and an empty recall caused by the reserved budget was recorded as `no_matches`, writing a zero-match injection receipt instead of a prompt-budget skip. ## What changed - `prompt.ts`: extracted `renderLongTermMemoryPrompt`, added `estimateLongTermMemoryPromptOverhead` and `formatLongTermMemoryPromptBullet`, and rewrote `serializeLongTermMemoryPrompt` to re-fit each candidate against the rendered prompt and skip an overflowing chunk instead of popping the tail. - `generation-injection.ts`: reserves the fixed prompt overhead in the retrieval budget (guarding the case where the overhead alone fills it), requests the prompt-normalized token estimate, and records `skipped/prompt_budget` when the reserved budget rejected every candidate rather than writing a zero-match receipt. - `budget.ts` / `retrieval.ts`: optional prompt-normalized estimate plus a debug-independent `budgetExhausted` signal; defaults preserve search and reconciliation callers. - `tests/long-term-memory-runtime.regression.ts`: a/b/c refill case, legacy `summary:` chunk case, and a budget-exhausted receipt-preservation case. - Rebuilt `long-term-memory` 1.4.11: manifest, `server.mjs`, artifact ZIP and catalog lane entries; changelog entry added. ## Package and security impact - Affected package IDs: `long-term-memory` - Engine compatibility impact: none (min 2.4.1 / maxExclusive 4.0.0 unchanged; no capability API change) - New or changed permissions/entrypoints: none - Restart, storage, update, or uninstall impact: none (recall selection and prompt assembly only; no storage or lifecycle change) ## 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 On `8383abe57f70eca2a0da875bbffb5ba16f2282d5` (pushed SHA), with `MARINARA_AGENTS_ROOT` and `MARINARA_ENGINE_ROOT` set: - `test-fast.sh` (Prettier, ESLint, `git diff --check`): exit 0. - `npm run typecheck:packages`: pass ("long-term-memory: no syntax errors, undefined names or unresolved modules"). - `test-ltm.sh runtime`, `test-ltm.sh routes`, `test-ltm.sh debug-log`: pass; runtime includes the new refill, legacy `summary:` and budget-exhausted cases. - `test-ltm.sh installation`: pass ("Long-Term Memory 1.4.11 installation: install, offline restart, backup inclusion, uninstall, reinstall, and durable-byte preservation ok") against the exact committed ZIP. - `node scripts/test-catalog-lanes.mjs`, `node scripts/validate-package-locales.mjs`, `node scripts/validate-catalog.mjs`, `node scripts/tests/catalog-release-notes.regression.mjs`: pass. - Publish proof: repository and independent Engine checkout inputs captured before and after the checks; `assertPublishProof` verified unchanged on final HEAD immediately before push. - Not performed: manual install/update through the Engine UI, and manual mode/restart/uninstall click-through beyond the installation regression. ## Documentation impact - [x] No documentation changes needed — package README, architecture and UI docs describe the recall flow generically and remain accurate; no catalog membership, compatibility, setup or user-visible workflow changed. - [ ] Updated this README catalog and package guidance - [ ] Updated linked Marinara Engine documentation ## UI evidence (if applicable) None — server-side recall selection and prompt assembly change; no client UI surface. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Long-Term Memory now accounts for fixed prompt overhead when selecting recalled information. If a chunk exceeds the available token budget, it is skipped so later, smaller chunks can still be included. * When no chunks fit, the system records a prompt-budget skip rather than treating the result as a zero-match recall. Existing injection information is preserved. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-21 05:09: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-Agents#1369
No description provided.