[GH-ISSUE #1508] [Issue]: Long-Term Memory: warnings in the server log lose the error that caused them #1497

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

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

Originally assigned to: @Promansis on GitHub.

Summary

Long-Term Memory writes most of its warnings pino style, with the error first: logger.warn(error, "[ltm] Deferred index rebuild after maintenance mutation"). On the real Engine those warnings reach the server log without the error. The line says that something failed but never why.

The package runtime turns the error-first form into the host's message-first form, host.logger.warn(message, error). The Engine passes that to pino as it is, and pino only uses arguments after the message to fill printf placeholders such as %s; an argument with no placeholder is dropped. So the error is lost. When the message does have a placeholder ("… for chat %s", chat.id), pino fills it with the error instead of the id, and the id is lost.

27 warnings in the package are written error first, among them a failed recall index rebuild after an edit, a settings save or a maintenance action (rebuildAfterMutation), the scope-link rebuild, retention, recall's shared-history lookup and the legacy settings adoption. logger.error(error, message) is not affected: the host's error takes the error first and the Engine passes it to pino that way.

Affected package

Re-checked 2026-10-21 at upstream/staging edb9c4928 (long-term-memory 1.4.57, built on the Engine's host, capability API 1.341): the fix applies unchanged there; line numbers are at the commit named below.

long-term-memory 1.4.55 (upstream/staging 8b72729f1).

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

Expected behavior

A warning logged with its error first shows the error in the server log: its message, and its stack like the package's logger.error lines. A warning whose message has an id placeholder shows the id.

Actual behavior

  • logger.warn in S/package-runtime.ts:177-185 accepts a string first (passed on unchanged) or anything else first. For the second form it calls host.logger.warn(typeof second === "string" ? second : "Long-Term Memory warning", first, ...args): the message, then the error, then any printf arguments.
  • The Engine's host logger (packages/server/src/services/capability-packages/capability-module-runtime.service.ts:126-127 in Marinara-Engine) is warn: (message, ...args) => Reflect.apply(logger.warn, logger, [message, ...args]), where logger is the Engine's pino instance.
  • pino formats the message with the arguments after it (%s, %d, %o, …) and ignores the rest. Its err serializer only applies to an error passed first.

Result through the Engine's pino 10.3.1 with the host's mapping (probe messages):

Package call Server log msg today
warn(error, "Long-Term Memory background rebuild failed") Long-Term Memory background rebuild failed (no error)
warn(error, "[ltm] Failed to delete draft %s", "draft-a") [ltm] Failed to delete draft Error: EISDIR: illegal operation on a directory, read (no id)
warn(error) Long-Term Memory warning
error(error, "…") message plus an err object with type, message and stack

Callers on 8b72729f1: 18 pass an error and a plain message, 8 pass an error and a message with a %s id (S/drafts/draft-store.ts:343, S/maintenance/legacy-adoption.ts:38, S/maintenance/maintenance.ts:237, S/persistence/index-state.ts:87, S/persistence/retention.ts:97, S/recall/generation-injection.ts:90, :135, :318), and one passes an array of note ids (S/maintenance/note-transfer.ts:303). Four pass a string first and are fine.

Steps to reproduce

  1. With pino from the Engine's server package: const log = pino(); const error = new Error("disk full");
  2. log.warn("Long-Term Memory background rebuild failed", error) (what the package runtime sends): the line has "msg":"Long-Term Memory background rebuild failed" and no err.
  3. log.warn(error, "object-first form"): the line has "err":{"type":"Error","message":"disk full","stack":…}.

In the package: configure the runtime with a host logger that, like pino, keeps only a warning's message, and call logger.warn(new Error("cause text"), "message"). The host receives "message".

Minimal fix

One PR, patch bump. Only S/package-runtime.ts, in logger.warn.

  • For a warning logged error first, put the cause into the message: `${message}: ${cause}`, where the cause is the error's stack (or its message if it has none), or String(value) for anything that is not an error. Pass the printf arguments on unchanged, so %s gets the id again.
  • Keep the string-first form and the "Long-Term Memory warning" fallback as they are. The host contract (warn(message, ...args)) and the Engine stay unchanged, and the result works with any host, not only pino.
  • Update the one test that asserted the old call shape (the retention warning in the storage regression).
  • CHANGELOG under ## Unreleased: "Long-Term Memory warnings in the server log now include the error that caused them. Before, the Engine's log dropped that error, so a warning such as a failed index rebuild gave no cause, and a warning that names a chat, draft or file showed the error's message in place of that name."

Not included

  • An Engine change to give warn an error-first form: the package must work with the Engines in its range, and the host contract is message first.
  • util.inspect of the error: it would also print the error's own fields, which for some provider errors include the request body.

Regression proof

  • tests/long-term-memory-runtime.regression.ts, after the existing host-swap checks: configure a host whose warn records only its first argument, as pino does, call logger.warn(new Error("cause text"), "message"), and expect the recorded message to start with message: and contain cause text. Fails today: the recorded message is message.
  • tests/long-term-memory-storage.regression.ts: the retention check asserted the old shape (the error as the second argument). It now expects [ltm] Deferred activity index pruning during retention: followed by the cause, and also fails today.

Environment

  • Marinara Engine version: 2.5.0 line (staging 2039583ca), pino 10.3.1
  • Package version: long-term-memory 1.4.55 (upstream/staging 8b72729f1)
  • Install type: source (code reading, a pino probe and the regression suite)
  • OS + version: not platform-specific
  • Browser or app shell: any

Logs, screenshots, or video

From the Engine's pino with the host's mapping (stack frames cut):

before: {"level":40,"msg":"Long-Term Memory background rebuild failed"}
after:  {"level":40,"msg":"Long-Term Memory background rebuild failed: Error: EISDIR: illegal operation on a directory, read\n    at …"}
before: {"level":40,"msg":"[ltm] Failed to delete draft Error: EISDIR: illegal operation on a directory, read"}
after:  {"level":40,"msg":"[ltm] Failed to delete draft draft-a: Error: EISDIR: illegal operation on a directory, read\n    at …"}

Additional context

Tracker item OT-10. Found while checking where a failed recall index rebuild is logged. The hygiene add-on (raw rebuild errors in the index state) points users to the server log and depends on this fix.

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 20, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1508 Originally assigned to: @Promansis on GitHub. ## Summary Long-Term Memory writes most of its warnings pino style, with the error first: `logger.warn(error, "[ltm] Deferred index rebuild after maintenance mutation")`. On the real Engine those warnings reach the server log without the error. The line says that something failed but never why. The package runtime turns the error-first form into the host's message-first form, `host.logger.warn(message, error)`. The Engine passes that to pino as it is, and pino only uses arguments after the message to fill printf placeholders such as `%s`; an argument with no placeholder is dropped. So the error is lost. When the message does have a placeholder (`"… for chat %s", chat.id`), pino fills it with the error instead of the id, and the id is lost. 27 warnings in the package are written error first, among them a failed recall index rebuild after an edit, a settings save or a maintenance action (`rebuildAfterMutation`), the scope-link rebuild, retention, recall's shared-history lookup and the legacy settings adoption. `logger.error(error, message)` is not affected: the host's `error` takes the error first and the Engine passes it to pino that way. ## Affected package Re-checked 2026-10-21 at `upstream/staging` edb9c4928 (long-term-memory 1.4.57, built on the Engine's host, capability API 1.341): the fix applies unchanged there; line numbers are at the commit named below. `long-term-memory` 1.4.55 (`upstream/staging` 8b72729f1). `S` = `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory` ## Expected behavior A warning logged with its error first shows the error in the server log: its message, and its stack like the package's `logger.error` lines. A warning whose message has an id placeholder shows the id. ## Actual behavior - `logger.warn` in `S/package-runtime.ts:177-185` accepts a string first (passed on unchanged) or anything else first. For the second form it calls `host.logger.warn(typeof second === "string" ? second : "Long-Term Memory warning", first, ...args)`: the message, then the error, then any printf arguments. - The Engine's host logger (`packages/server/src/services/capability-packages/capability-module-runtime.service.ts:126-127` in Marinara-Engine) is `warn: (message, ...args) => Reflect.apply(logger.warn, logger, [message, ...args])`, where `logger` is the Engine's pino instance. - pino formats the message with the arguments after it (`%s`, `%d`, `%o`, …) and ignores the rest. Its `err` serializer only applies to an error passed first. Result through the Engine's pino 10.3.1 with the host's mapping (probe messages): | Package call | Server log `msg` today | |---|---| | `warn(error, "Long-Term Memory background rebuild failed")` | `Long-Term Memory background rebuild failed` (no error) | | `warn(error, "[ltm] Failed to delete draft %s", "draft-a")` | `[ltm] Failed to delete draft Error: EISDIR: illegal operation on a directory, read` (no id) | | `warn(error)` | `Long-Term Memory warning` | | `error(error, "…")` | message plus an `err` object with type, message and stack | Callers on 8b72729f1: 18 pass an error and a plain message, 8 pass an error and a message with a `%s` id (`S/drafts/draft-store.ts:343`, `S/maintenance/legacy-adoption.ts:38`, `S/maintenance/maintenance.ts:237`, `S/persistence/index-state.ts:87`, `S/persistence/retention.ts:97`, `S/recall/generation-injection.ts:90`, `:135`, `:318`), and one passes an array of note ids (`S/maintenance/note-transfer.ts:303`). Four pass a string first and are fine. ## Steps to reproduce 1. With pino from the Engine's server package: `const log = pino(); const error = new Error("disk full");` 2. `log.warn("Long-Term Memory background rebuild failed", error)` (what the package runtime sends): the line has `"msg":"Long-Term Memory background rebuild failed"` and no `err`. 3. `log.warn(error, "object-first form")`: the line has `"err":{"type":"Error","message":"disk full","stack":…}`. In the package: configure the runtime with a host logger that, like pino, keeps only a warning's message, and call `logger.warn(new Error("cause text"), "message")`. The host receives `"message"`. ## Minimal fix One PR, patch bump. Only `S/package-runtime.ts`, in `logger.warn`. - For a warning logged error first, put the cause into the message: `` `${message}: ${cause}` ``, where the cause is the error's stack (or its message if it has none), or `String(value)` for anything that is not an error. Pass the printf arguments on unchanged, so `%s` gets the id again. - Keep the string-first form and the `"Long-Term Memory warning"` fallback as they are. The host contract (`warn(message, ...args)`) and the Engine stay unchanged, and the result works with any host, not only pino. - Update the one test that asserted the old call shape (the retention warning in the storage regression). - **CHANGELOG under `## Unreleased`:** "Long-Term Memory warnings in the server log now include the error that caused them. Before, the Engine's log dropped that error, so a warning such as a failed index rebuild gave no cause, and a warning that names a chat, draft or file showed the error's message in place of that name." **Not included** - An Engine change to give `warn` an error-first form: the package must work with the Engines in its range, and the host contract is message first. - `util.inspect` of the error: it would also print the error's own fields, which for some provider errors include the request body. ## Regression proof - `tests/long-term-memory-runtime.regression.ts`, after the existing host-swap checks: configure a host whose `warn` records only its first argument, as pino does, call `logger.warn(new Error("cause text"), "message")`, and expect the recorded message to start with `message: ` and contain `cause text`. Fails today: the recorded message is `message`. - `tests/long-term-memory-storage.regression.ts`: the retention check asserted the old shape (the error as the second argument). It now expects `[ltm] Deferred activity index pruning during retention: ` followed by the cause, and also fails today. ## Environment - Marinara Engine version: 2.5.0 line (`staging` 2039583ca), pino 10.3.1 - Package version: long-term-memory 1.4.55 (`upstream/staging` 8b72729f1) - Install type: source (code reading, a pino probe and the regression suite) - OS + version: not platform-specific - Browser or app shell: any ## Logs, screenshots, or video From the Engine's pino with the host's mapping (stack frames cut): ``` before: {"level":40,"msg":"Long-Term Memory background rebuild failed"} after: {"level":40,"msg":"Long-Term Memory background rebuild failed: Error: EISDIR: illegal operation on a directory, read\n at …"} before: {"level":40,"msg":"[ltm] Failed to delete draft Error: EISDIR: illegal operation on a directory, read"} after: {"level":40,"msg":"[ltm] Failed to delete draft draft-a: Error: EISDIR: illegal operation on a directory, read\n at …"} ``` ## Additional context Tracker item OT-10. Found while checking where a failed recall index rebuild is logged. The hygiene add-on (raw rebuild errors in the index state) points users to the server log and depends on this fix. ## 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-22 04:02:42 +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#1497
No description provided.