[GH-ISSUE #1377] [Issue]: Long-Term Memory UI: remove duplicated code, repeated fetches and unused locale keys #705

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

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

Originally assigned to: @Promansis on GitHub.

Summary

The Long-Term Memory client carries several byte-identical copies of the same code, three definitions of the same queries, a lazy() import that splits nothing, Settings actions that fetch the same data two or three times, and about 155 locale keys that nothing references. Removing them changes nothing users see, except that one loading flash goes away.

Affected package

long-term-memory 1.4.31 client, under packages/long-term-memory/src/engine/packages/client/src/features/long-term-memory/. Line numbers are at cdb583a95, before the folder moves in #1376.

Expected behavior

One copy of each shared piece of code, one definition per query, each Settings action fetches each resource once, and every locale key is used.

Actual behavior

  • sectionCopy (46 lines) is defined twice, identically: MemoryVault.tsx:1054-1099 and :1350-1395.
  • The all/chat/branch/character/persona label list appears three times: MemoryVault.tsx:236-242, SourcesWorkspace.tsx:143-149, :474-480.
  • chatModeLabel (SourcesWorkspace.tsx:436) and modeName (:940) are byte-identical.
  • 9 hand-written arrow-key handlers for tab rails: MemorySettings.tsx:953, LtmWorkspace.tsx:215, SourcesWorkspace.tsx:212/818/2827/3073/3548, TargetPicker.tsx:180, MemoryVault.tsx:432.
  • confirm() wrappers at ActivityView.tsx:593 and MemorySettings.tsx:102, plus an inline window.confirm at LongTermMemoryDetail.tsx:239.
  • /settings is queried at MemoryVault.tsx:1708, SourcesWorkspace.tsx:1687 and MemorySettings.tsx:268. /scope-targets is queried at MemoryVault.tsx:1591, SourcesWorkspace.tsx:1679 and ActivityView.tsx:703; all three share one cache key, but the Vault parses it as its own VaultScopeTargets type (:164), so one cache entry has two declared shapes. /notes/:id/derived is cached under two keys (MemoryVault.tsx:1787, SourcesWorkspace.tsx:1086).
  • React.lazy at LongTermMemoryDetail.tsx:94-99 splits nothing, because esbuild builds one output file without --splitting. It only adds a loading flash.
  • Backup import (MemorySettings.tsx:719-736), reset (:781-787) and delete-all (:824-835) call invalidateQueries, which already waits for active queries to refetch, then call .refetch() again. Passing queryKeys.root together with child keys restarts overlapping fetches, and most query functions ignore the abort signal, so the cancelled requests still go out. This contradicts the rule at api.ts:226.
  • 155 of the 1,476 ui.* keys in locales/en.json have no literal or template-prefix reference.

Steps to reproduce

  1. Diff the two sectionCopy blocks: they are identical.
  2. Count ArrowRight handlers across the feature's .tsx files: 9 sites.
  3. In Settings → Maintenance, import a backup with the browser's network panel open: the same requests go out more than once.

Environment

  • Marinara Engine version: 2.5.0 line (staging)
  • Package version: long-term-memory 1.4.31 (upstream/staging 39a5c5cfb; LTM files unchanged since cdb583a95)
  • Install type: source (code audit; the double fetch was confirmed against @tanstack/query-core 5.100.9 source)
  • OS + version: not platform-specific
  • Browser or app shell: any

Logs, screenshots, or video

Not applicable.

Minimal fix

Deletions only:

  1. Delete the second sectionCopy; both places use one const.
  2. One label-list helper in display-labels.ts; the three copies call it.
  3. Delete chatModeLabel and modeName; call localizedLabel(mode, t, labelKeys.mode) (display-labels.ts:39,129).
  4. Add nextTabIndex(key, index, length) to shared-controls.tsx; the 9 handlers call it.
  5. Move the Settings confirm() (the one with destructive) to shared-controls.tsx; delete the Activity copy and use it for the inline window.confirm.
  6. Export settingsQuery, scopeTargetsQuery(chatId) (one response type; the Vault reads the fields it needs from it) and derivedNotesQuery(id) from api.ts; the screens use them.
  7. Delete lazy/Suspense in LongTermMemoryDetail.tsx and import MemoryVault directly. Keep zod: it validates review state read from localStorage.
  8. In the three Settings handlers, delete the .refetch() calls, read errors with queryClient.getQueryState(key), and drop either queryKeys.root or the child keys it already covers.
  9. Delete the unreferenced locale keys, after checking each one for a dynamically built reference.

Proof: a small Engine-free test for nextTabIndex; the browser test stays green; the duplicate counts above each drop to one.

Additional context

After #1376, so these deletions land in the moved files. The shared errorMessage helper is part of #1375.

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @Promansis on GitHub (Oct 14, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1377 Originally assigned to: @Promansis on GitHub. ## Summary The Long-Term Memory client carries several byte-identical copies of the same code, three definitions of the same queries, a `lazy()` import that splits nothing, Settings actions that fetch the same data two or three times, and about 155 locale keys that nothing references. Removing them changes nothing users see, except that one loading flash goes away. ## Affected package `long-term-memory` 1.4.31 client, under `packages/long-term-memory/src/engine/packages/client/src/features/long-term-memory/`. Line numbers are at cdb583a95, before the folder moves in #1376. ## Expected behavior One copy of each shared piece of code, one definition per query, each Settings action fetches each resource once, and every locale key is used. ## Actual behavior - `sectionCopy` (46 lines) is defined twice, identically: `MemoryVault.tsx:1054-1099` and `:1350-1395`. - The all/chat/branch/character/persona label list appears three times: `MemoryVault.tsx:236-242`, `SourcesWorkspace.tsx:143-149`, `:474-480`. - `chatModeLabel` (`SourcesWorkspace.tsx:436`) and `modeName` (`:940`) are byte-identical. - 9 hand-written arrow-key handlers for tab rails: `MemorySettings.tsx:953`, `LtmWorkspace.tsx:215`, `SourcesWorkspace.tsx:212/818/2827/3073/3548`, `TargetPicker.tsx:180`, `MemoryVault.tsx:432`. - `confirm()` wrappers at `ActivityView.tsx:593` and `MemorySettings.tsx:102`, plus an inline `window.confirm` at `LongTermMemoryDetail.tsx:239`. - `/settings` is queried at `MemoryVault.tsx:1708`, `SourcesWorkspace.tsx:1687` and `MemorySettings.tsx:268`. `/scope-targets` is queried at `MemoryVault.tsx:1591`, `SourcesWorkspace.tsx:1679` and `ActivityView.tsx:703`; all three share one cache key, but the Vault parses it as its own `VaultScopeTargets` type (`:164`), so one cache entry has two declared shapes. `/notes/:id/derived` is cached under two keys (`MemoryVault.tsx:1787`, `SourcesWorkspace.tsx:1086`). - `React.lazy` at `LongTermMemoryDetail.tsx:94-99` splits nothing, because esbuild builds one output file without `--splitting`. It only adds a loading flash. - Backup import (`MemorySettings.tsx:719-736`), reset (`:781-787`) and delete-all (`:824-835`) call `invalidateQueries`, which already waits for active queries to refetch, then call `.refetch()` again. Passing `queryKeys.root` together with child keys restarts overlapping fetches, and most query functions ignore the abort signal, so the cancelled requests still go out. This contradicts the rule at `api.ts:226`. - 155 of the 1,476 `ui.*` keys in `locales/en.json` have no literal or template-prefix reference. ## Steps to reproduce 1. Diff the two `sectionCopy` blocks: they are identical. 2. Count `ArrowRight` handlers across the feature's `.tsx` files: 9 sites. 3. In Settings → Maintenance, import a backup with the browser's network panel open: the same requests go out more than once. ## Environment - Marinara Engine version: 2.5.0 line (`staging`) - Package version: long-term-memory 1.4.31 (`upstream/staging` 39a5c5cfb; LTM files unchanged since cdb583a95) - Install type: source (code audit; the double fetch was confirmed against `@tanstack/query-core` 5.100.9 source) - OS + version: not platform-specific - Browser or app shell: any ## Logs, screenshots, or video Not applicable. ## Minimal fix Deletions only: 1. Delete the second `sectionCopy`; both places use one `const`. 2. One label-list helper in `display-labels.ts`; the three copies call it. 3. Delete `chatModeLabel` and `modeName`; call `localizedLabel(mode, t, labelKeys.mode)` (`display-labels.ts:39,129`). 4. Add `nextTabIndex(key, index, length)` to `shared-controls.tsx`; the 9 handlers call it. 5. Move the Settings `confirm()` (the one with `destructive`) to `shared-controls.tsx`; delete the Activity copy and use it for the inline `window.confirm`. 6. Export `settingsQuery`, `scopeTargetsQuery(chatId)` (one response type; the Vault reads the fields it needs from it) and `derivedNotesQuery(id)` from `api.ts`; the screens use them. 7. Delete `lazy`/`Suspense` in `LongTermMemoryDetail.tsx` and import `MemoryVault` directly. Keep zod: it validates review state read from localStorage. 8. In the three Settings handlers, delete the `.refetch()` calls, read errors with `queryClient.getQueryState(key)`, and drop either `queryKeys.root` or the child keys it already covers. 9. Delete the unreferenced locale keys, after checking each one for a dynamically built reference. Proof: a small Engine-free test for `nextTabIndex`; the browser test stays green; the duplicate counts above each drop to one. ## Additional context After #1376, so these deletions land in the moved files. The shared `errorMessage` helper is part of #1375. ## Template check - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-20 17:29:54 +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#705
No description provided.