[GH-ISSUE #1507] [Issue]: Long-Term Memory: a stale settings form can undo Reset or Import, an integrity-only failure shows the wrong message, and Reset loses focus #1498

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/1507

Originally assigned to: @Promansis on GitHub.

Summary

Three follow-ups to #1452 (Reset and Import reload the settings forms), all confirmed in the browser at 1.4.54:

  1. A stale form can undo a Reset or Import. After a failed reload, leaving Settings and coming back fills the forms with the settings from before the Reset or Import. The next Save sends the whole form, so it silently writes those old values back.
  2. An Import whose integrity read alone failed shows a wrong message and an old report.
    • It says "settings could not be refreshed", although the forms show the refreshed settings.
    • The panel still shows the integrity report from before the import.
  3. Focus is lost after Reset. Focus drops to the page body when the Maintenance panel hides for the reload, and it doesn't come back afterwards. Keyboard and screen-reader users lose their place.

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.54 (upstream/staging b1873710f). PR #1473 (head c4b1c0192) doesn't touch these files.

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

Expected behavior

  1. After a failed reload, Settings shows the load error until a reload succeeds, on this visit or the next. The forms only ever fill from settings read after the Reset or Import.
  2. When an Import refreshed the settings but not the integrity report, the message says the backup was imported. The integrity area shows only its own "could not load" error with Retry, not the report from before the import.
  3. When the reload finishes, focus returns to the control that started the action. For Import, whose Replace button is gone by then, focus goes to "Choose backup".

Actual behavior

1. Remount after a failed reload

  • refillSince (C/settings/MemorySettings.tsx:214) is component state, so it starts at 0 again when Settings remounts.
  • react-query v5 keeps a query's old data and dataUpdatedAt after a failed refetch. On remount, the fill effects (:243-248 global, :249-254 extraction) therefore see data, no form, and dataUpdatedAt >= 0, and fill the forms from the settings cached before the action.
  • The refetch on mount succeeds later, but the forms are already set, so they are never refilled.
  • If the user then edits any field and saves, globalPayload (:108-111) and extractionPayload (:170-176) send every field of the stale form, and that writes the pre-Reset or pre-Import values back.

Browser probe:

  1. "Maximum recalled memories" shows 20.
  2. Reset runs with the settings read failing, and the page shows "Could not load memory settings.".
  3. The user goes to Vault. The server now answers 37.
  4. Back in Settings, after 1 s the field shows 20.
UI7-PROBE remount: cached=20 server=37 shown=20 -> STALE (bug)

2. Import with only the integrity read failed

  • importBackup (C/settings/MaintenancePanel.tsx:401-407) treats a failed integrity refetch like a failed settings refetch. It calls settings.clear(startedAt) and sets backupImportedSettingsNotRefreshed.
  • The fill effects then refill the forms from the refreshed settings, because their dataUpdatedAt is at or after startedAt.
  • The integrity area renders both integrity.isError (:583-590) and the cached integrity.data (:591-600).
  • The existing #1452 row import-integrity (tests/long-term-memory-browser.regression.ts:3780-3849) asserts both the wrong message and the refreshed value.

Browser probe (all status surfaces in the panel after that row's import):

["Memory backup imported, but settings could not be refreshed.","Integrity check could not load. Retry","Integrity check passed for 3 notes."]

3. Focus after Reset

  • The Reset button (C/settings/MaintenancePanel.tsx:553) is disabled while the action runs.
  • The panel is rendered with hidden (:515) while the forms reload (C/settings/MemorySettings.tsx:363-381).
  • Either one drops focus to body, and nothing restores it.

Browser probe (the settings read is delayed 800 ms, then succeeds):

UI7-PROBE focus: during reload=body; after reload=body

Import goes through the same hidden panel. Its focus was not probed separately.

Steps to reproduce

  1. Open Long-Term Memory, then Settings and Maintenance.
  2. Make the settings read fail, for example with a network block on GET /api/long-term-memory/settings, then click Reset settings. "Could not load memory settings." appears.
  3. Go to Vault, restore the network, and return to Settings. The forms show the values from before the Reset. Change any field and save: the old values are written back.
  4. Import a backup while only GET /api/long-term-memory/integrity fails. The message says settings could not be refreshed, the forms show the imported settings, and the old integrity report is still shown.
  5. Reset settings with the keyboard (Tab to the button, Enter). After the reload, focus is on the page body.

Minimal fix

One PR, patch bump. Client only; no new locale keys.

  1. C/settings/MemorySettings.tsx:244 and :250: add global.isError || and extraction.isError || to the fill gates. While a query is in error, Settings shows the error surface (:383-398). The successful refetch, on mount or through Retry, clears isError with a newer dataUpdatedAt, and the forms then fill from it. The #1452 Retry path and the import-integrity path are unaffected, because their settings queries are not in error.
  2. C/settings/MaintenancePanel.tsx:401-407:
    • Only a settings refresh failure clears the forms and shows backupImportedSettingsNotRefreshed. Otherwise apply the refreshed settings and keep "Memory backup imported." (memoryBackupImported, set at :400).
    • At :591, render the cached report only when !integrity.isError, so a failed integrity read shows just its error with Retry.
  3. C/settings/MaintenancePanel.tsx focus:
    • Keep a focusAfterReload ref.
    • Reset's onClick stores event.currentTarget. Import stores the "Choose backup" Button, which forwards refs (C/shared-controls.tsx:21).
    • An effect on [hidden, pending] focuses the stored element, then clears the ref. It runs only once the panel is visible and idle, only if the element is still connected, and only if focus is on body.
  • CHANGELOG under ## Unreleased: one bullet, for example: "Settings no longer refill from values cached before a Reset or Import when the reload failed. A backup import whose integrity check failed reports it correctly. Focus returns to the Reset or Import control after the settings reload."

Not included

  • Declined: waiting for fresh data whenever the cached settings were marked out of date, for example when another view invalidated queryKeys.settings while Settings was closed. That gate (queryClient.getQueryState(key)?.isInvalidated) would change every Settings visit. The maintainer chose to fix only the failed-reload case, which the isError gate covers.
  • Moving focus to the error surface's Retry button when the reload fails. Focus stays on body until the panel is visible again.
  • Changing the prescribed loading screen that hides the panel (#1452).

Regression proof

Write first, in tests/long-term-memory-browser.regression.ts, beside the #1452 loop (:3777-3851). The private probe scenario can be turned into assertions:

  1. Remount. Reset fails its settings read, the user goes to Vault, the server answers again, and the user returns to Settings. "Maximum recalled memories" equals the new server value, not the cached one. The probe shows 20 instead of 37 today.
  2. Import with only integrity failing. Change the import-integrity row to expect "Memory backup imported.". The panel shows "Integrity check could not load." and no "Integrity check passed" report.
  3. Focus. With the settings read delayed, Reset settings ends with document.activeElement being the Reset button (read it as the activity-log focus check at :3291 does). Import ends on "Choose backup".

Every existing #1452 and #1376 row must still pass.

Environment

  • Marinara Engine version: 2.5.0 line (local staging checkout, unchanged; Playwright Chromium from its node_modules)
  • Package version: long-term-memory 1.4.54 (upstream/staging b1873710f, artifacts/long-term-memory-1.4.54.zip)
  • Install type: source (browser regression harness, throwaway copy)
  • OS + version: Linux, Node 24.15.0
  • Browser or app shell: Chromium (Playwright, headless)

Logs, screenshots, or video

The probe output is quoted under Actual behavior. It came from a throwaway copy of the browser regression with the probe snippet inserted. The whole suite still exits 0, because the probe prints its results rather than asserting them.

Additional context

Tracker item UI-7 (#1452 review follow-ups). The tracker listed three things:

  • Remount: found to be worse than listed, because Save can write the stale values back.
  • The integrity message: confirmed, plus the stale report.
  • Focus: previously unverified; now confirmed lost.

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/1507 Originally assigned to: @Promansis on GitHub. ## Summary Three follow-ups to #1452 (Reset and Import reload the settings forms), all confirmed in the browser at 1.4.54: 1. **A stale form can undo a Reset or Import.** After a failed reload, leaving Settings and coming back fills the forms with the settings from before the Reset or Import. The next Save sends the whole form, so it silently writes those old values back. 2. **An Import whose integrity read alone failed shows a wrong message and an old report.** - It says "settings could not be refreshed", although the forms show the refreshed settings. - The panel still shows the integrity report from before the import. 3. **Focus is lost after Reset.** Focus drops to the page body when the Maintenance panel hides for the reload, and it doesn't come back afterwards. Keyboard and screen-reader users lose their place. ## 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.54 (`upstream/staging` b1873710f). PR #1473 (head c4b1c0192) doesn't touch these files. `C` = `packages/long-term-memory/src/engine/packages/client/src/features/long-term-memory` ## Expected behavior 1. After a failed reload, Settings shows the load error until a reload succeeds, on this visit or the next. The forms only ever fill from settings read after the Reset or Import. 2. When an Import refreshed the settings but not the integrity report, the message says the backup was imported. The integrity area shows only its own "could not load" error with Retry, not the report from before the import. 3. When the reload finishes, focus returns to the control that started the action. For Import, whose Replace button is gone by then, focus goes to "Choose backup". ## Actual behavior ### 1. Remount after a failed reload - `refillSince` (`C/settings/MemorySettings.tsx:214`) is component state, so it starts at 0 again when Settings remounts. - react-query v5 keeps a query's old `data` and `dataUpdatedAt` after a failed refetch. On remount, the fill effects (`:243-248` global, `:249-254` extraction) therefore see data, no form, and `dataUpdatedAt >= 0`, and fill the forms from the settings cached before the action. - The refetch on mount succeeds later, but the forms are already set, so they are never refilled. - If the user then edits any field and saves, `globalPayload` (`:108-111`) and `extractionPayload` (`:170-176`) send every field of the stale form, and that writes the pre-Reset or pre-Import values back. **Browser probe:** 1. "Maximum recalled memories" shows 20. 2. Reset runs with the settings read failing, and the page shows "Could not load memory settings.". 3. The user goes to Vault. The server now answers 37. 4. Back in Settings, after 1 s the field shows **20**. ``` UI7-PROBE remount: cached=20 server=37 shown=20 -> STALE (bug) ``` ### 2. Import with only the integrity read failed - `importBackup` (`C/settings/MaintenancePanel.tsx:401-407`) treats a failed integrity refetch like a failed settings refetch. It calls `settings.clear(startedAt)` and sets `backupImportedSettingsNotRefreshed`. - The fill effects then refill the forms from the refreshed settings, because their `dataUpdatedAt` is at or after `startedAt`. - The integrity area renders both `integrity.isError` (`:583-590`) and the cached `integrity.data` (`:591-600`). - The existing #1452 row `import-integrity` (`tests/long-term-memory-browser.regression.ts:3780-3849`) asserts both the wrong message and the refreshed value. **Browser probe** (all status surfaces in the panel after that row's import): ``` ["Memory backup imported, but settings could not be refreshed.","Integrity check could not load. Retry","Integrity check passed for 3 notes."] ``` ### 3. Focus after Reset - The Reset button (`C/settings/MaintenancePanel.tsx:553`) is disabled while the action runs. - The panel is rendered with `hidden` (`:515`) while the forms reload (`C/settings/MemorySettings.tsx:363-381`). - Either one drops focus to `body`, and nothing restores it. **Browser probe** (the settings read is delayed 800 ms, then succeeds): ``` UI7-PROBE focus: during reload=body; after reload=body ``` Import goes through the same hidden panel. Its focus was not probed separately. ## Steps to reproduce 1. Open Long-Term Memory, then Settings and Maintenance. 2. Make the settings read fail, for example with a network block on `GET /api/long-term-memory/settings`, then click Reset settings. "Could not load memory settings." appears. 3. Go to Vault, restore the network, and return to Settings. The forms show the values from before the Reset. Change any field and save: the old values are written back. 4. Import a backup while only `GET /api/long-term-memory/integrity` fails. The message says settings could not be refreshed, the forms show the imported settings, and the old integrity report is still shown. 5. Reset settings with the keyboard (Tab to the button, Enter). After the reload, focus is on the page body. ## Minimal fix One PR, patch bump. Client only; no new locale keys. 1. **`C/settings/MemorySettings.tsx:244` and `:250`**: add `global.isError ||` and `extraction.isError ||` to the fill gates. While a query is in error, Settings shows the error surface (`:383-398`). The successful refetch, on mount or through Retry, clears `isError` with a newer `dataUpdatedAt`, and the forms then fill from it. The #1452 Retry path and the import-integrity path are unaffected, because their settings queries are not in error. 2. **`C/settings/MaintenancePanel.tsx:401-407`**: - Only a settings refresh failure clears the forms and shows `backupImportedSettingsNotRefreshed`. Otherwise apply the refreshed settings and keep "Memory backup imported." (`memoryBackupImported`, set at `:400`). - At `:591`, render the cached report only when `!integrity.isError`, so a failed integrity read shows just its error with Retry. 3. **`C/settings/MaintenancePanel.tsx`** focus: - Keep a `focusAfterReload` ref. - Reset's `onClick` stores `event.currentTarget`. Import stores the "Choose backup" `Button`, which forwards refs (`C/shared-controls.tsx:21`). - An effect on `[hidden, pending]` focuses the stored element, then clears the ref. It runs only once the panel is visible and idle, only if the element is still connected, and only if focus is on `body`. - **CHANGELOG under `## Unreleased`:** one bullet, for example: "Settings no longer refill from values cached before a Reset or Import when the reload failed. A backup import whose integrity check failed reports it correctly. Focus returns to the Reset or Import control after the settings reload." **Not included** - **Declined:** waiting for fresh data whenever the cached settings were marked out of date, for example when another view invalidated `queryKeys.settings` while Settings was closed. That gate (`queryClient.getQueryState(key)?.isInvalidated`) would change every Settings visit. The maintainer chose to fix only the failed-reload case, which the `isError` gate covers. - Moving focus to the error surface's Retry button when the reload fails. Focus stays on `body` until the panel is visible again. - Changing the prescribed loading screen that hides the panel (#1452). ## Regression proof Write first, in `tests/long-term-memory-browser.regression.ts`, beside the #1452 loop (`:3777-3851`). The private probe scenario can be turned into assertions: 1. **Remount.** Reset fails its settings read, the user goes to Vault, the server answers again, and the user returns to Settings. "Maximum recalled memories" equals the new server value, not the cached one. The probe shows 20 instead of 37 today. 2. **Import with only integrity failing.** Change the `import-integrity` row to expect "Memory backup imported.". The panel shows "Integrity check could not load." and no "Integrity check passed" report. 3. **Focus.** With the settings read delayed, Reset settings ends with `document.activeElement` being the Reset button (read it as the activity-log focus check at `:3291` does). Import ends on "Choose backup". Every existing #1452 and #1376 row must still pass. ## Environment - Marinara Engine version: 2.5.0 line (local `staging` checkout, unchanged; Playwright Chromium from its `node_modules`) - Package version: long-term-memory 1.4.54 (`upstream/staging` b1873710f, `artifacts/long-term-memory-1.4.54.zip`) - Install type: source (browser regression harness, throwaway copy) - OS + version: Linux, Node 24.15.0 - Browser or app shell: Chromium (Playwright, headless) ## Logs, screenshots, or video The probe output is quoted under Actual behavior. It came from a throwaway copy of the browser regression with the probe snippet inserted. The whole suite still exits 0, because the probe prints its results rather than asserting them. ## Additional context Tracker item UI-7 (#1452 review follow-ups). The tracker listed three things: - **Remount:** found to be worse than listed, because Save can write the stale values back. - **The integrity message:** confirmed, plus the stale report. - **Focus:** previously unverified; now confirmed lost. ## 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#1498
No description provided.