[GH-ISSUE #1419] [Issue]: Long-Term Memory server: split the 1,635-line routes.ts by area #723

Closed
opened 2026-10-20 17:30:05 +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/1419

Originally assigned to: @Promansis on GitHub.

Summary

All 56 Long-Term Memory HTTP endpoints are registered in one 1,635-line routes.ts, inside a single function. Their request schemas and helpers are about 470 lines at the top of the same file. Every server change to notes, drafts, imports, maintenance or settings therefore touches this one file, which makes reviews larger and parallel work conflict. This issue splits it into one file per area, as pure moves with no behaviour change.

Affected package

long-term-memory 1.4.38 (upstream/staging 97c0486f8), packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/routes.ts:

  • Lines 1-468: imports (33 sibling modules), request schemas, routeError and vaultNoteValidationError.
  • Lines 469-1635: createLongTermMemoryRoutes, which registers all 56 endpoints. GET /scope-targets alone is about 120 lines inline (:746-868).
  • Test: tests/long-term-memory-routes.regression.ts (6,325 lines; needs MARINARA_ENGINE_ROOT).

Expected behavior

  • Each area's endpoints live in their own file.
  • routes.ts only composes them.
  • Every endpoint keeps its method, path, body limit, error handling and response.

Actual behavior

The 56 endpoints by area:

Area Endpoints Paths
Notes 19 16 under /notes, plus /search, /scope-targets and /local-characters
Drafts 11 7 under /drafts, 4 under /rejected-suggestions
Imports 4 /import/preview, /import/source-details, /import/lorebooks/preview, /import/source-notes
Maintenance 17 /status, /rebuild, /integrity, /repair, /identity-repair/*, /fork-repair/*, /backup/*, /data, /debug-log*, /events, /last-injection/:chatId
Settings 5 /settings, /settings/reset, /extraction-settings

Steps to reproduce

  1. Open routes.ts.
  2. Count the app.get, app.post, app.put, app.patch and app.delete calls inside createLongTermMemoryRoutes: there are 56.

Environment

  • Marinara Engine version: 2.5.0 line (staging)
  • 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.

Minimal fix

  1. Pin the route list first, in its own commit.
    • In tests/long-term-memory-routes.regression.ts, collect the registered routes with an onRoute hook before the LTM routes are registered.
    • Assert that the sorted method and path list equals the 56 routes above.
    • This must pass on the unsplit file.
  2. Move, without changing logic. Keep routes.ts as the composer, so server-entry.ts is unchanged, and add a routes/ folder:
    • routes/notes.ts, routes/drafts.ts, routes/imports.ts, routes/maintenance.ts and routes/settings.ts. Each exports register…Routes(app, runtime) and holds that area's handlers and request schemas.
    • routes/shared.ts holds routeError, vaultNoteValidationError, rebuildAfterMutation (turned into a function that takes root) and the schemas used by more than one area.
    • Register the areas in the current order.
  3. Proof:
    • the route-list assertion from step 1;
    • the full routes regression (all scenarios; it passes at 1.4.38, in 9 s locally).

Validation:

  • npm run check
  • node scripts/typecheck-packages.mjs long-term-memory
  • rebuild LTM (server.mjs changes; patch bump)
  • node scripts/validate-catalog.mjs
  • the routes, runtime and storage regressions (MARINARA_ENGINE_ROOT set)

Additional context

  • Out of scope:
    • Raw error text in responses (routeError, :425 and :439; rebuild results, :489). The client shows these messages in toasts ("Saved, but recall is stale: …"). On a self-hosted install, they are the most useful detail for the person fixing the problem.
    • Moving /scope-targets business logic into a service. That is a separate change.
    • Splitting into server subfolders beyond routes/.
  • Timing: this conflicts with any open LTM server PR, so land it between batches.
  • CI: the routes regression doesn't run in CI yet; see #1414.

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/1419 Originally assigned to: @Promansis on GitHub. ## Summary All 56 Long-Term Memory HTTP endpoints are registered in one 1,635-line `routes.ts`, inside a single function. Their request schemas and helpers are about 470 lines at the top of the same file. Every server change to notes, drafts, imports, maintenance or settings therefore touches this one file, which makes reviews larger and parallel work conflict. This issue splits it into one file per area, as pure moves with no behaviour change. ## Affected package `long-term-memory` 1.4.38 (`upstream/staging` 97c0486f8), `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/routes.ts`: - **Lines 1-468:** imports (33 sibling modules), request schemas, `routeError` and `vaultNoteValidationError`. - **Lines 469-1635:** `createLongTermMemoryRoutes`, which registers all 56 endpoints. `GET /scope-targets` alone is about 120 lines inline (`:746-868`). - **Test:** `tests/long-term-memory-routes.regression.ts` (6,325 lines; needs `MARINARA_ENGINE_ROOT`). ## Expected behavior - Each area's endpoints live in their own file. - `routes.ts` only composes them. - Every endpoint keeps its method, path, body limit, error handling and response. ## Actual behavior The 56 endpoints by area: | Area | Endpoints | Paths | |---|---|---| | Notes | 19 | 16 under `/notes`, plus `/search`, `/scope-targets` and `/local-characters` | | Drafts | 11 | 7 under `/drafts`, 4 under `/rejected-suggestions` | | Imports | 4 | `/import/preview`, `/import/source-details`, `/import/lorebooks/preview`, `/import/source-notes` | | Maintenance | 17 | `/status`, `/rebuild`, `/integrity`, `/repair`, `/identity-repair/*`, `/fork-repair/*`, `/backup/*`, `/data`, `/debug-log*`, `/events`, `/last-injection/:chatId` | | Settings | 5 | `/settings`, `/settings/reset`, `/extraction-settings` | ## Steps to reproduce 1. Open `routes.ts`. 2. Count the `app.get`, `app.post`, `app.put`, `app.patch` and `app.delete` calls inside `createLongTermMemoryRoutes`: there are 56. ## Environment - Marinara Engine version: 2.5.0 line (`staging`) - 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. ## Minimal fix 1. **Pin the route list first, in its own commit.** - In `tests/long-term-memory-routes.regression.ts`, collect the registered routes with an `onRoute` hook before the LTM routes are registered. - Assert that the sorted method and path list equals the 56 routes above. - This must pass on the unsplit file. 2. **Move, without changing logic.** Keep `routes.ts` as the composer, so `server-entry.ts` is unchanged, and add a `routes/` folder: - `routes/notes.ts`, `routes/drafts.ts`, `routes/imports.ts`, `routes/maintenance.ts` and `routes/settings.ts`. Each exports `register…Routes(app, runtime)` and holds that area's handlers and request schemas. - `routes/shared.ts` holds `routeError`, `vaultNoteValidationError`, `rebuildAfterMutation` (turned into a function that takes `root`) and the schemas used by more than one area. - Register the areas in the current order. 3. **Proof:** - the route-list assertion from step 1; - the full routes regression (all scenarios; it passes at 1.4.38, in 9 s locally). Validation: - `npm run check` - `node scripts/typecheck-packages.mjs long-term-memory` - rebuild LTM (`server.mjs` changes; patch bump) - `node scripts/validate-catalog.mjs` - the routes, runtime and storage regressions (`MARINARA_ENGINE_ROOT` set) ## Additional context - **Out of scope:** - **Raw error text in responses** (`routeError`, `:425` and `:439`; rebuild results, `:489`). The client shows these messages in toasts ("Saved, but recall is stale: …"). On a self-hosted install, they are the most useful detail for the person fixing the problem. - **Moving `/scope-targets` business logic** into a service. That is a separate change. - **Splitting into server subfolders beyond `routes/`.** - **Timing:** this conflicts with any open LTM server PR, so land it between batches. - **CI:** the routes regression doesn't run in CI yet; see #1414. ## 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:05 +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#723
No description provided.