Medium: Settings navigation guard ignores unsaved Permanent Memory edits and removals
Severity
Medium — unsaved edits/removals in the Permanent Memory editor are silently discarded when navigating away from Settings, even though the Settings page has a “Save your changes?” navigation guard. The guard only knows about the parent settings form, not the memory editor's separate draft.
Evidence
MemoryPanel.tsx:34–73: memories are edited in localdraftstate.MemoryPanel.tsx:108–121computesdirtyfor pending removals/edits and only persists when Save changes is clicked.MemoryPanel.tsx:190–197displays its own “Unsaved changes” state but does not notify SettingsPanel of the dirty draft; its Props at lines 13–21 have no dirty-change callback.SettingsPanel.tsx:150–208: the navigation and beforeunload guards usedirty = !valuesEqual(draft, settings), which only compares the parent's CortexSettings, not the independently edited memory rows.SettingsPanel.tsx:433–439: the MemoryPanel is embedded under the Memory tab, without wiring its edit state to the guard.
Deterministic reproduction
- In Settings → Memory, ensure one saved fact exists.
- Edit that fact or mark it for removal, without clicking Save changes. The local editor correctly displays “Unsaved changes.”
- Click Close settings, New thread, or a chat in the sidebar.
- Actual: if no separate settings field was changed,
SettingsPanel.dirtyremains false, so navigation proceeds without the save/discard/keep-editing dialog. MemoryPanel unmounts and the unsaved memory edit is lost. - Expected: any unsaved memory draft should block/confirm route navigation and window reload just like unsaved settings fields, or preserve drafts across the route transition.
Fix/tests
Lift memory dirty state into SettingsPanel (e.g. onDirtyChange and a scoped draft manager) and include it in both the navigation and beforeunload guards. A Save and close must persist the changed memories, not only settings, and handle 409 conflicts correctly; Discard must explicitly discard both drafts. Add tests for edited and removed memory rows, each navigation entry point and reload, plus a failed/409 memory save.
Reviewed revision: e824fe2dcba0d1be127c9fff165f776186dc37e9. Deterministic state ownership and navigation-guard mismatch; UI test not executed. Distinct from #424, which covers native history bypassing a guard even when the parent settings state is dirty.
Additional immediate reproduction: changing Settings tabs also discards the unsaved memory draft, without navigating away from Settings. SettingsPanel.tsx:433–439 renders MemoryPanel only when section === "memory"; clicking “General,” “AI Model,” etc. unmounts it. MemoryPanel.tsx:34–38 initializes local draft state from the saved memos prop on remount. Repro: edit an existing memory without Save changes → click AI Model → click Memory again → the edit is gone. This is stronger than the route-guard scenario because it occurs within a single Settings session; it should be covered by the same lifted/persisted draft state solution and regression tests.