[GH-ISSUE #1415] [Issue]: Long-Term Memory won't start when a settings file has a field from a newer version #719

Closed
opened 2026-10-20 17:30:03 +07:00 by bsakaguchi · 0 comments
Owner

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

Originally assigned to: @Promansis on GitHub.

Summary

Long-Term Memory's activation check parses its settings files strictly. A settings field written by a newer version therefore stops an older version from starting, which leaves no recall and no extraction in any chat until someone edits the file by hand. This bites hardest after a failed update: the Engine rolls back to the previous version, and that version then can't read the settings the newer one saved.

Each settings schema already drops fields that older versions used and later removed. This issue covers the other direction: fields added by a newer version. #1328 left this out of scope on purpose ("changing it needs its own decision"); this issue is that decision.

Affected package

long-term-memory 1.4.38 (upstream/staging 97c0486f8), under packages/long-term-memory/src/engine/packages/:

  • Activation check: server/.../long-term-memory/runtime.ts:16-24 parses the global settings, the extraction settings and agent-settings.json.
  • Readers:
    • getLtmGlobalSettings (settings.ts:13-16, config/settings.json);
    • getLtmExtractionConfig (extraction-config.ts:39-45, config/extraction.json);
    • the agent-settings read in runtime.ts:21-23;
    • backup export (backup-restore.ts:47-53), which also reads the retention config.
  • Writers: updateLtmGlobalSettings (settings.ts:24-35) and updateLtmExtractionConfig (extraction-config.ts:69-95).
  • Schemas: ltmGlobalSettingsShape (shared/.../schema.ts:75), ltmExtractionSettingsShape (:354), ltmAgentSettingsShape (:3222) and ltmRetentionConfigSchema (:1356) are all .strict(). Their preprocessors (:99-115, :377, :3234-3243) delete known removed keys only.
  • Test that pins the current behaviour: tests/long-term-memory-storage.regression.ts:287-293 ("self-check must reject malformed settings", using {"version":1,"unknown":true}).

Expected behavior

  • A settings file with a field this version doesn't know still loads: the unknown field is ignored and logged by name.
  • Saving settings keeps that field in the file, so upgrading again restores it.
  • Request bodies stay strict (PUT /settings parses its body with the same schema, routes.ts:679), so a typo from the client is still rejected.

Actual behavior

  • At startup: the activation check throws a Zod "unrecognized key" error. The Engine logs "Failed to activate capability package", records the error in its runtime diagnostics, and the package doesn't run.
  • During an update: a failed activation rolls the package back to the previous version (see the 1.3.34 changelog entry). If the newer version had already saved a new settings field, the rolled-back version then fails its own activation for the same reason.
  • Backups: export parses the same files strictly, so it fails as well.
  • Saving: settings can't be saved either, because updateLtmGlobalSettings merges the existing file into the request and parses the result strictly.

Steps to reproduce

  1. Stop the server and add "someNewSetting": true to <dataDir>/long-term-memory/config/settings.json.
  2. Start the server. Long-Term Memory fails to activate: the server log shows "Failed to activate capability package", and the error appears in the Engine's runtime diagnostics.
  3. Alternatively, run tests/long-term-memory-storage.regression.ts: lines 287-293 assert exactly this failure.

Environment

  • Marinara Engine version: 2.5.0 line (package range >=2.4.1 <4.0.0)
  • Package version: long-term-memory 1.4.38 (upstream/staging 97c0486f8)
  • Install type: source (code audit)
  • OS + version: not platform-specific
  • Browser or app shell: any

Logs, screenshots, or video

Not applicable; the failure is a Zod "unrecognized key" error during activation.

Minimal fix

  1. Read leniently, for settings files only.
    • Before the schema parse, split the stored object into known and unknown top-level keys, using the object shape's keys.
    • Parse the known part and log one warning that names the unknown keys, without values.
    • Apply this in four places:
      • getLtmGlobalSettings;
      • getLtmExtractionConfig;
      • the agent-settings read in the activation check;
      • backup export's settings reads, including the retention config.
    • Leave the schemas themselves strict, because they also validate request bodies.
  2. Keep unknown keys when saving.
    • In updateLtmGlobalSettings and updateLtmExtractionConfig, merge the request into the known part only, so the request is still validated strictly.
    • Then write { ...unknownFromExistingFile, ...parsed }.
    • POST /settings/reset still writes defaults only, because the user asked for a reset.
  3. Unchanged:
    • request bodies stay strict;
    • restoring a backup made by a newer version still fails at restore time, with an error;
    • a known field with an invalid value still fails;
    • memory files already skip invalid entries (since 1.4.29).
  4. Regression: replace the assertion at tests/long-term-memory-storage.regression.ts:287-293 with these checks:
    • activation succeeds with an unknown key in settings.json, extraction.json and agent-settings.json;
    • the resolved settings ignore the unknown key;
    • after updateLtmGlobalSettings({ longTermMemoryStopWords: [...] }), the file still contains the unknown key;
    • a PUT /settings body with an unknown key is still rejected;
    • backup export succeeds and leaves the unknown key out of the backup.

Validation:

  • npm run check
  • node scripts/typecheck-packages.mjs long-term-memory
  • rebuild LTM
  • node scripts/validate-catalog.mjs
  • the storage, runtime and routes regressions (MARINARA_ENGINE_ROOT set for the last two)

Additional context

  • Trade-offs:
    • A misspelled key in a hand-edited settings file is now ignored, with a warning, instead of failing. Settings are normally changed in the UI, so this is rare.
    • Keeping unknown keys on save is what stops a downgrade followed by an upgrade from quietly resetting the newer setting.
  • Downgrade safety: older versions are unaffected. The change only makes this version tolerant of what newer versions write, so it pays off from the release after it ships.
  • Precedent: the recall style already falls back to its default when a restored value is unknown (tests/long-term-memory-storage.regression.ts:703-706).
  • Out of scope: the other .strict() schemas, about 160 calls for notes, drafts, indexes and backups.

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 15, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1415 Originally assigned to: @Promansis on GitHub. ## Summary Long-Term Memory's activation check parses its settings files strictly. A settings field written by a newer version therefore stops an older version from starting, which leaves no recall and no extraction in any chat until someone edits the file by hand. This bites hardest after a failed update: the Engine rolls back to the previous version, and that version then can't read the settings the newer one saved. Each settings schema already drops fields that older versions used and later removed. This issue covers the other direction: fields added by a newer version. #1328 left this out of scope on purpose ("changing it needs its own decision"); this issue is that decision. ## Affected package `long-term-memory` 1.4.38 (`upstream/staging` 97c0486f8), under `packages/long-term-memory/src/engine/packages/`: - **Activation check:** `server/.../long-term-memory/runtime.ts:16-24` parses the global settings, the extraction settings and `agent-settings.json`. - **Readers:** - `getLtmGlobalSettings` (`settings.ts:13-16`, `config/settings.json`); - `getLtmExtractionConfig` (`extraction-config.ts:39-45`, `config/extraction.json`); - the agent-settings read in `runtime.ts:21-23`; - backup export (`backup-restore.ts:47-53`), which also reads the retention config. - **Writers:** `updateLtmGlobalSettings` (`settings.ts:24-35`) and `updateLtmExtractionConfig` (`extraction-config.ts:69-95`). - **Schemas:** `ltmGlobalSettingsShape` (`shared/.../schema.ts:75`), `ltmExtractionSettingsShape` (`:354`), `ltmAgentSettingsShape` (`:3222`) and `ltmRetentionConfigSchema` (`:1356`) are all `.strict()`. Their preprocessors (`:99-115`, `:377`, `:3234-3243`) delete known removed keys only. - **Test that pins the current behaviour:** `tests/long-term-memory-storage.regression.ts:287-293` ("self-check must reject malformed settings", using `{"version":1,"unknown":true}`). ## Expected behavior - A settings file with a field this version doesn't know still loads: the unknown field is ignored and logged by name. - Saving settings keeps that field in the file, so upgrading again restores it. - Request bodies stay strict (`PUT /settings` parses its body with the same schema, `routes.ts:679`), so a typo from the client is still rejected. ## Actual behavior - **At startup:** the activation check throws a Zod "unrecognized key" error. The Engine logs "Failed to activate capability package", records the error in its runtime diagnostics, and the package doesn't run. - **During an update:** a failed activation rolls the package back to the previous version (see the 1.3.34 changelog entry). If the newer version had already saved a new settings field, the rolled-back version then fails its own activation for the same reason. - **Backups:** export parses the same files strictly, so it fails as well. - **Saving:** settings can't be saved either, because `updateLtmGlobalSettings` merges the existing file into the request and parses the result strictly. ## Steps to reproduce 1. Stop the server and add `"someNewSetting": true` to `<dataDir>/long-term-memory/config/settings.json`. 2. Start the server. Long-Term Memory fails to activate: the server log shows "Failed to activate capability package", and the error appears in the Engine's runtime diagnostics. 3. Alternatively, run `tests/long-term-memory-storage.regression.ts`: lines 287-293 assert exactly this failure. ## Environment - Marinara Engine version: 2.5.0 line (package range `>=2.4.1 <4.0.0`) - Package version: long-term-memory 1.4.38 (`upstream/staging` 97c0486f8) - Install type: source (code audit) - OS + version: not platform-specific - Browser or app shell: any ## Logs, screenshots, or video Not applicable; the failure is a Zod "unrecognized key" error during activation. ## Minimal fix 1. **Read leniently, for settings files only.** - Before the schema parse, split the stored object into known and unknown top-level keys, using the object shape's keys. - Parse the known part and log one warning that names the unknown keys, without values. - Apply this in four places: - `getLtmGlobalSettings`; - `getLtmExtractionConfig`; - the agent-settings read in the activation check; - backup export's settings reads, including the retention config. - Leave the schemas themselves strict, because they also validate request bodies. 2. **Keep unknown keys when saving.** - In `updateLtmGlobalSettings` and `updateLtmExtractionConfig`, merge the request into the known part only, so the request is still validated strictly. - Then write `{ ...unknownFromExistingFile, ...parsed }`. - `POST /settings/reset` still writes defaults only, because the user asked for a reset. 3. **Unchanged:** - request bodies stay strict; - restoring a backup made by a newer version still fails at restore time, with an error; - a known field with an invalid value still fails; - memory files already skip invalid entries (since 1.4.29). 4. **Regression:** replace the assertion at `tests/long-term-memory-storage.regression.ts:287-293` with these checks: - activation succeeds with an unknown key in `settings.json`, `extraction.json` and `agent-settings.json`; - the resolved settings ignore the unknown key; - after `updateLtmGlobalSettings({ longTermMemoryStopWords: [...] })`, the file still contains the unknown key; - a `PUT /settings` body with an unknown key is still rejected; - backup export succeeds and leaves the unknown key out of the backup. Validation: - `npm run check` - `node scripts/typecheck-packages.mjs long-term-memory` - rebuild LTM - `node scripts/validate-catalog.mjs` - the storage, runtime and routes regressions (`MARINARA_ENGINE_ROOT` set for the last two) ## Additional context - **Trade-offs:** - A misspelled key in a hand-edited settings file is now ignored, with a warning, instead of failing. Settings are normally changed in the UI, so this is rare. - Keeping unknown keys on save is what stops a downgrade followed by an upgrade from quietly resetting the newer setting. - **Downgrade safety:** older versions are unaffected. The change only makes this version tolerant of what newer versions write, so it pays off from the release after it ships. - **Precedent:** the recall style already falls back to its default when a restored value is unknown (`tests/long-term-memory-storage.regression.ts:703-706`). - **Out of scope:** the other `.strict()` schemas, about 160 calls for notes, drafts, indexes and backups. ## 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-20 17:30:03 +07:00
  • closed this issue
  • added the
    bug
    label
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#719
No description provided.