[GH-ISSUE #1542] [Issue]: Long-Term Memory: identity repair, batch imports and preflight still send raw server errors to the client #1512

Closed
opened 2026-10-22 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/1542

Originally assigned to: @Promansis on GitHub.

Summary

After the error-message hygiene fix, a route that hits an unexpected error logs it and sends a fallback message instead of the error's own text. Three other paths still send that text to the client, which shows it as is, and a fourth would. The text can hold file paths and library internals:

  1. An identity repair that fails and whose backup also cannot be restored. The message ends in the repair error's text, and that error is not logged.
  2. A source that fails to save or to extract during a batch import. Sources lists the error's text under the source.
  3. A change that Review's preflight cannot check. The blocker shows the error's text.
  4. A library error that has a numeric statusCode and a string code, such as Fastify's FST_ERR_* errors. isLtmServiceError checks only that shape, so such an error would be treated as one of LTM's own and sent with its message and status. Nothing raises one in a route today, so this one is hardening.

Affected package

long-term-memory 1.4.72 (upstream/staging bcaebd07d).

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

Expected behavior

An error LTM did not write for users is logged on the server, and the client gets a message that says what failed and that the details are in the server log. LTM's own service errors, such as a model reply that was cut off, and a cancelled import keep their messages. Error codes, statuses of LTM's own errors and retry flags stay as they are.

Actual behavior

Line numbers are on upstream/staging bcaebd07d (refreshed 2026-10-21; first checked on 8b72729f1).

  • Identity repair. When the repair fails, applyLtmIdentityRepairs restores the backup (S/identity/identity-repair.ts:150-161). If the restore also fails, it logs only the restore error (:154) and throws identity_repair_restore_failed with the message "Identity repair failed and its backup could not be restored: ${message(error)}" (:155-159). The repair error's text goes to the client and is never logged. The Maintenance settings show it.
  • Source write failure. importPackageInterop lists a source it could not save with code: "source_write_failed" and message: error.message (S/sources/interop.ts:1009-1021). Nothing logs it.
  • Extract or finalize failure. failed() (S/extraction/source-processing.ts:453-510) uses error.message (:461) for both the result's error (:504) and its diagnostic (:507). This covers file and snapshot errors as well as provider errors from the Engine. It does not log.
  • Sources shows these messages as is: C/sources/SourcesWorkspace.tsx:1380, :2639 (result rows) and :1392, :2696 ("{title}: {message}" for write failures).
  • Preflight blockers. addBlocker (S/drafts/reconciliation.ts:485-490) uses error.message for any error, so a storage failure during the check becomes the blocker text (code preflight_blocked). Review shows it (C/review/ReviewQueue.tsx:1834). Not logged.
  • Errors shaped like service errors. isLtmServiceError (S/service-error.ts:12-20) accepts any object with a string message, an integer statusCode and a string code. After the hygiene fix, routeError relies on it, so a library error of that shape would be sent with its own message and status, without being logged. No known path does this today: Fastify's body-limit and content-type errors are raised before the route handler runs, and the Engine's error handler already replaces a 413's message; the Engine's provider errors carry status, not statusCode; Node, SQLite and fetch errors have no statusCode. Every LTM service error is an instance of LtmServiceError or one of its subclasses.

Steps to reproduce

  1. In the routes regression, make the storage's updateNote throw new Error("EACCES: open '/private/marinara/source_chat_a.json'").
  2. Re-import a chat summary through POST /api/long-term-memory/import/source-notes with extract: false.
  3. writeFailures[0].error.message is "EACCES: open '/private/marinara/source_chat_a.json'", and Sources would show that path.

The same kind of stub shows the other paths: getNotesByIds throwing during POST /drafts/:id/preflight (blocker text), updateNote throwing after the repair's backup is removed during POST /identity-repair/apply (500 with the error appended), and a direct routeError call with Object.assign(new Error("Request body is too large: /private/upload"), { statusCode: 413, code: "FST_ERR_CTP_BODY_TOO_LARGE" }) (413 with that message).

In normal use: with an invalid API key on the memory model, a batch import with extraction on shows the provider's error text under each source that failed.

Minimal fix

One PR, patch bump. Server only; the client already shows whatever message comes back.

  • S/identity/identity-repair.ts: in the restore-failure branch, log the repair error too, and say "Identity repair failed and its backup could not be restored. Details are in the server log." Same code and status. Remove the now unused message() helper (:606).
  • S/sources/interop.ts: for an error that is not an LtmServiceError, log it with the source id and say "Failed to write imported source note. Details are in the server log."
  • S/extraction/source-processing.ts failed(): for an error that is neither an LtmServiceError nor a cancellation, log it with the stage and source id and say "Failed to extract imported source. Details are in the server log." (or "finalize"). failureCode and retryableFailure are unchanged, so a provider's safe error code and status still decide the code and the retry flag.
  • S/drafts/reconciliation.ts addBlocker: for an error that is not an LtmServiceError, log it with the draft id and say "Long-term memory preflight failed. Details are in the server log." Link-choice and projection errors keep their messages.
  • S/service-error.ts: isLtmServiceError becomes error instanceof LtmServiceError. Its other callers already send "Index rebuild failed" for anything else.
  • CHANGELOG under ## Unreleased: "A few more unexpected failures no longer show their raw error text, which could include file paths. In Sources, a source that could not be saved or extracted now says "Failed to write imported source note." or "Failed to extract imported source.", followed by "Details are in the server log."; this includes the model provider rejecting the request during an import. In Review, a change that could not be checked says "Long-term memory preflight failed. Details are in the server log." An identity repair in settings whose backup could not be restored says so without the cause. The full error is written to the server log. Messages written for you, such as a model reply that was cut off, show as before."

Not included

  • Localized text for these messages. They are English server text today and stay so; localizing them needs a client mapping from code to text.
  • The provider's own reason on import failures (bad key, quota, rate limit, timeout). It now goes to the server log, as it already does for re-extracting one source, and Settings → Debug → Activity still records it. Showing it again would mean wrapping provider HTTP errors in a service error that keeps only the status, for both paths.
  • The raw rebuild error after accepting a draft, which has its own issue after the debounced background rebuild.
  • Integrity report entries and model-output parse messages inside service errors, which describe the stored data or the model's answer.

Regression proof

  • tests/long-term-memory-routes.regression.ts:
    • scope-identity scenario, before the backup-retention case: a persona identity repair whose updateNote stub deletes the new backup and throws a private-path Error. Expect 500, the new message, identity_repair_restore_failed, and the error in the logger stub. After the routeError cases: a Fastify-shaped error gives the 500 fallback with ltm_unexpected_failure and is logged.
    • imports scenario: the write failure from Steps; expect source_write_failed with the new message, logged. The existing import whose model throws now expects extract_failed with the new message.
    • drafts scenario, after the blocked-preflight case: getNotesByIds throws on the check's own reads; expect one preflight_blocked blocker with the new message, logged.
  • tests/long-term-memory-extraction-reliability.regression.ts: the existing snapshot-failure batch expects extract_failed with the new message, and snapshot unavailable in the logger stub.
  • Each fails today (the response carries the error's text) and passes with the fix. Each message and each log call was also reverted on its own to check that a case fails.

Environment

  • Marinara Engine version: 2.5.1 (staging 87d1ccadc)
  • Package version: long-term-memory 1.4.72 (upstream/staging bcaebd07d)
  • Install type: source (code reading and regression tests)
  • OS + version: not platform-specific
  • Browser or app shell: any

Logs, screenshots, or video

None. The regression cases above show the leaked text with made-up paths.

Additional context

Tracker item OT-6. Follows the raw-error clean-up in #1506.

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/1542 Originally assigned to: @Promansis on GitHub. ## Summary After the error-message hygiene fix, a route that hits an unexpected error logs it and sends a fallback message instead of the error's own text. Three other paths still send that text to the client, which shows it as is, and a fourth would. The text can hold file paths and library internals: 1. An identity repair that fails and whose backup also cannot be restored. The message ends in the repair error's text, and that error is not logged. 2. A source that fails to save or to extract during a batch import. Sources lists the error's text under the source. 3. A change that Review's preflight cannot check. The blocker shows the error's text. 4. A library error that has a numeric `statusCode` and a string `code`, such as Fastify's `FST_ERR_*` errors. `isLtmServiceError` checks only that shape, so such an error would be treated as one of LTM's own and sent with its message and status. Nothing raises one in a route today, so this one is hardening. ## Affected package `long-term-memory` 1.4.72 (`upstream/staging` bcaebd07d). `S` = `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory` `C` = `packages/long-term-memory/src/engine/packages/client/src/features/long-term-memory` ## Expected behavior An error LTM did not write for users is logged on the server, and the client gets a message that says what failed and that the details are in the server log. LTM's own service errors, such as a model reply that was cut off, and a cancelled import keep their messages. Error codes, statuses of LTM's own errors and retry flags stay as they are. ## Actual behavior Line numbers are on `upstream/staging` bcaebd07d (refreshed 2026-10-21; first checked on 8b72729f1). - **Identity repair.** When the repair fails, `applyLtmIdentityRepairs` restores the backup (`S/identity/identity-repair.ts:150-161`). If the restore also fails, it logs only the restore error (`:154`) and throws `identity_repair_restore_failed` with the message "Identity repair failed and its backup could not be restored: ${message(error)}" (`:155-159`). The repair error's text goes to the client and is never logged. The Maintenance settings show it. - **Source write failure.** `importPackageInterop` lists a source it could not save with `code: "source_write_failed"` and `message: error.message` (`S/sources/interop.ts:1009-1021`). Nothing logs it. - **Extract or finalize failure.** `failed()` (`S/extraction/source-processing.ts:453-510`) uses `error.message` (`:461`) for both the result's `error` (`:504`) and its diagnostic (`:507`). This covers file and snapshot errors as well as provider errors from the Engine. It does not log. - Sources shows these messages as is: `C/sources/SourcesWorkspace.tsx:1380`, `:2639` (result rows) and `:1392`, `:2696` ("{title}: {message}" for write failures). - **Preflight blockers.** `addBlocker` (`S/drafts/reconciliation.ts:485-490`) uses `error.message` for any error, so a storage failure during the check becomes the blocker text (code `preflight_blocked`). Review shows it (`C/review/ReviewQueue.tsx:1834`). Not logged. - **Errors shaped like service errors.** `isLtmServiceError` (`S/service-error.ts:12-20`) accepts any object with a string `message`, an integer `statusCode` and a string `code`. After the hygiene fix, `routeError` relies on it, so a library error of that shape would be sent with its own message and status, without being logged. No known path does this today: Fastify's body-limit and content-type errors are raised before the route handler runs, and the Engine's error handler already replaces a 413's message; the Engine's provider errors carry `status`, not `statusCode`; Node, SQLite and fetch errors have no `statusCode`. Every LTM service error is an instance of `LtmServiceError` or one of its subclasses. ## Steps to reproduce 1. In the routes regression, make the storage's `updateNote` throw `new Error("EACCES: open '/private/marinara/source_chat_a.json'")`. 2. Re-import a chat summary through `POST /api/long-term-memory/import/source-notes` with `extract: false`. 3. `writeFailures[0].error.message` is `"EACCES: open '/private/marinara/source_chat_a.json'"`, and Sources would show that path. The same kind of stub shows the other paths: `getNotesByIds` throwing during `POST /drafts/:id/preflight` (blocker text), `updateNote` throwing after the repair's backup is removed during `POST /identity-repair/apply` (500 with the error appended), and a direct `routeError` call with `Object.assign(new Error("Request body is too large: /private/upload"), { statusCode: 413, code: "FST_ERR_CTP_BODY_TOO_LARGE" })` (413 with that message). In normal use: with an invalid API key on the memory model, a batch import with extraction on shows the provider's error text under each source that failed. ## Minimal fix One PR, patch bump. Server only; the client already shows whatever message comes back. - `S/identity/identity-repair.ts`: in the restore-failure branch, log the repair error too, and say "Identity repair failed and its backup could not be restored. Details are in the server log." Same code and status. Remove the now unused `message()` helper (`:606`). - `S/sources/interop.ts`: for an error that is not an `LtmServiceError`, log it with the source id and say "Failed to write imported source note. Details are in the server log." - `S/extraction/source-processing.ts` `failed()`: for an error that is neither an `LtmServiceError` nor a cancellation, log it with the stage and source id and say "Failed to extract imported source. Details are in the server log." (or "finalize"). `failureCode` and `retryableFailure` are unchanged, so a provider's safe error code and status still decide the code and the retry flag. - `S/drafts/reconciliation.ts` `addBlocker`: for an error that is not an `LtmServiceError`, log it with the draft id and say "Long-term memory preflight failed. Details are in the server log." Link-choice and projection errors keep their messages. - `S/service-error.ts`: `isLtmServiceError` becomes `error instanceof LtmServiceError`. Its other callers already send "Index rebuild failed" for anything else. - **CHANGELOG under `## Unreleased`**: "A few more unexpected failures no longer show their raw error text, which could include file paths. In Sources, a source that could not be saved or extracted now says "Failed to write imported source note." or "Failed to extract imported source.", followed by "Details are in the server log."; this includes the model provider rejecting the request during an import. In Review, a change that could not be checked says "Long-term memory preflight failed. Details are in the server log." An identity repair in settings whose backup could not be restored says so without the cause. The full error is written to the server log. Messages written for you, such as a model reply that was cut off, show as before." **Not included** - Localized text for these messages. They are English server text today and stay so; localizing them needs a client mapping from code to text. - The provider's own reason on import failures (bad key, quota, rate limit, timeout). It now goes to the server log, as it already does for re-extracting one source, and Settings → Debug → Activity still records it. Showing it again would mean wrapping provider HTTP errors in a service error that keeps only the status, for both paths. - The raw rebuild error after accepting a draft, which has its own issue after the debounced background rebuild. - Integrity report entries and model-output parse messages inside service errors, which describe the stored data or the model's answer. ## Regression proof - `tests/long-term-memory-routes.regression.ts`: - scope-identity scenario, before the backup-retention case: a persona identity repair whose `updateNote` stub deletes the new backup and throws a private-path `Error`. Expect 500, the new message, `identity_repair_restore_failed`, and the error in the logger stub. After the `routeError` cases: a Fastify-shaped error gives the 500 fallback with `ltm_unexpected_failure` and is logged. - imports scenario: the write failure from Steps; expect `source_write_failed` with the new message, logged. The existing import whose model throws now expects `extract_failed` with the new message. - drafts scenario, after the blocked-preflight case: `getNotesByIds` throws on the check's own reads; expect one `preflight_blocked` blocker with the new message, logged. - `tests/long-term-memory-extraction-reliability.regression.ts`: the existing snapshot-failure batch expects `extract_failed` with the new message, and `snapshot unavailable` in the logger stub. - Each fails today (the response carries the error's text) and passes with the fix. Each message and each log call was also reverted on its own to check that a case fails. ## Environment - Marinara Engine version: 2.5.1 (`staging` 87d1ccadc) - Package version: long-term-memory 1.4.72 (`upstream/staging` bcaebd07d) - Install type: source (code reading and regression tests) - OS + version: not platform-specific - Browser or app shell: any ## Logs, screenshots, or video None. The regression cases above show the leaked text with made-up paths. ## Additional context Tracker item OT-6. Follows the raw-error clean-up in #1506. ## 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: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#1512
No description provided.