[GH-ISSUE #1556] [Issue]: Long-Term Memory: a full debug log is rewritten in full for every new line #1543

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

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

Originally assigned to: @Promansis on GitHub.

Summary

Long-Term Memory keeps its debug log at most 2 MB. Once the log is full, every new debug line reads the whole file, keeps the newest lines up to just under 2 MB and writes it back, all while holding the vault lock. Every recall and extraction writes debug lines, so a long-running install pays a full 2 MB rewrite for each one, and saves and recalls wait behind it. Trimming well below the cap would make the next lines plain appends again.

Affected package

  • Package: long-term-memory 1.4.80
  • Area: server debug log (maintenance/debug-log.ts)

Expected behavior

  • When a new line would push the debug log past 2 MB, the log keeps its newest complete lines up to about 1.5 MB, then adds the line.
  • The lines after that are plain appends until the log reaches 2 MB again.
  • The log never passes 2 MB, every line stays complete JSON, and the newest lines are kept, as today.

Actual behavior

  • appendBounded (S/maintenance/debug-log.ts:143-165) trims to LTM_DEBUG_MAX_LOG_BYTES - lineBytes, so the file stays within one line of the cap.
  • The next line overflows again, so from then on every append reads, trims and rewrites the whole 2 MB file through a temporary file and a rename.
  • recordLtmDebugEvent (:182-200) runs that append under withLtmVaultLock. The debug setting in Memory Settings doesn't gate these writes: recall (recall/generation-injection.ts:247), extraction and draft apply all record events.

S = packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory

Steps to reproduce

  1. Use Long-Term Memory long enough for the debug log to reach 2 MB, or fill it with large debug events as tests/long-term-memory-debug-log.regression.ts does.
  2. Record one more event: the log is rewritten and ends within one line of 2 MB.
  3. Record another event: the log is rewritten again instead of appended.

Minimal fix

  • S/maintenance/debug-log.ts: in appendBounded, keep the newest complete lines within a trim target of three quarters of LTM_DEBUG_MAX_LOG_BYTES (1.5 MB) instead of the cap minus the new line. Nothing else changes.
  • Regression: extend tests/long-term-memory-debug-log.regression.ts: after the log overflows, its size is at most the trim target, and the next event grows it by exactly that event's line.
  • CHANGELOG entry; patch release.

Environment

  • Marinara Engine version: 2.5.1
  • Package version: long-term-memory 1.4.80
  • Install type: any
  • OS + version: any
  • Browser or app shell: n/a (server)

Logs, screenshots, or video

Found by reading the code while reviewing the runtime architecture audit. The trade-off is that the log keeps about 1.5 to 2 MB of history instead of always 2 MB.

Additional context

An earlier plan moved the debug log onto its own lock. That was dropped: it could make a backup restore fail halfway through swapping the vault folder. This issue keeps the debug log on the vault lock and only removes the repeated rewrite.

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 22, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1556 Originally assigned to: @Promansis on GitHub. ## Summary Long-Term Memory keeps its debug log at most 2 MB. Once the log is full, every new debug line reads the whole file, keeps the newest lines up to just under 2 MB and writes it back, all while holding the vault lock. Every recall and extraction writes debug lines, so a long-running install pays a full 2 MB rewrite for each one, and saves and recalls wait behind it. Trimming well below the cap would make the next lines plain appends again. ## Affected package - Package: `long-term-memory` 1.4.80 - Area: server debug log (`maintenance/debug-log.ts`) ## Expected behavior - When a new line would push the debug log past 2 MB, the log keeps its newest complete lines up to about 1.5 MB, then adds the line. - The lines after that are plain appends until the log reaches 2 MB again. - The log never passes 2 MB, every line stays complete JSON, and the newest lines are kept, as today. ## Actual behavior - `appendBounded` (`S/maintenance/debug-log.ts:143-165`) trims to `LTM_DEBUG_MAX_LOG_BYTES - lineBytes`, so the file stays within one line of the cap. - The next line overflows again, so from then on every append reads, trims and rewrites the whole 2 MB file through a temporary file and a rename. - `recordLtmDebugEvent` (`:182-200`) runs that append under `withLtmVaultLock`. The debug setting in Memory Settings doesn't gate these writes: recall (`recall/generation-injection.ts:247`), extraction and draft apply all record events. `S` = `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory` ## Steps to reproduce 1. Use Long-Term Memory long enough for the debug log to reach 2 MB, or fill it with large debug events as `tests/long-term-memory-debug-log.regression.ts` does. 2. Record one more event: the log is rewritten and ends within one line of 2 MB. 3. Record another event: the log is rewritten again instead of appended. ## Minimal fix - `S/maintenance/debug-log.ts`: in `appendBounded`, keep the newest complete lines within a trim target of three quarters of `LTM_DEBUG_MAX_LOG_BYTES` (1.5 MB) instead of the cap minus the new line. Nothing else changes. - Regression: extend `tests/long-term-memory-debug-log.regression.ts`: after the log overflows, its size is at most the trim target, and the next event grows it by exactly that event's line. - CHANGELOG entry; patch release. ## Environment - Marinara Engine version: 2.5.1 - Package version: long-term-memory 1.4.80 - Install type: any - OS + version: any - Browser or app shell: n/a (server) ## Logs, screenshots, or video Found by reading the code while reviewing the runtime architecture audit. The trade-off is that the log keeps about 1.5 to 2 MB of history instead of always 2 MB. ## Additional context An earlier plan moved the debug log onto its own lock. That was dropped: it could make a backup restore fail halfway through swapping the vault folder. This issue keeps the debug log on the vault lock and only removes the repeated rewrite. ## 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
Author
Owner

@Promansis commented on GitHub (Oct 22, 2026):

Fixed in staging by #1557 (a6e2b20ce), released as Long-Term Memory 1.4.82.

<!-- gh-comment-id:6330229768 --> @Promansis commented on GitHub (Oct 22, 2026): Fixed in staging by #1557 (a6e2b20ce), released as Long-Term Memory 1.4.82.
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#1543
No description provided.