Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: guard backup delete with a ref and assert retry after failure (#8922)
[._.]/ Adam Eivy060f56720335
diff --git a/client/src/pages/DataManager.jsx b/client/src/pages/DataManager.jsxindex 127f970a07..29160393b4 100644--- a/client/src/pages/DataManager.jsx+++ b/client/src/pages/DataManager.jsx@@ -394,7 +394,8 @@ export default function DataManager() {const [purging, setPurging] = useState(null);const [confirmPurge, setConfirmPurge] = useState(null);const [deletingItem, setDeletingItem] = useState(null);- const [deletingBackup, setDeletingBackup] = useState(null);+ // Ref, not state: two clicks in one render would both read a stale state value.+ const deletingBackupsRef = useRef(new Set());const overviewRequestRef = useRef(0);const overviewReadRef = useRef(null);@@ -520,20 +521,13 @@ export default function DataManager() {};const handleDeleteBackup = async (filename) => {- // Guard duplicate submissions: if a deletion is already in progress for this- // filename, return early without making another request.- if (deletingBackup === filename) return;-- setDeletingBackup(filename);- const result = await api.deleteDataBackup(filename).catch(() => null);- setDeletingBackup(null);-- // Only remove the row from the list if the deletion succeeded. On failure,- // the API layer's error toast stays visible, and the row remains so the user- // can retry.- if (result) {- setBackups(prev => prev.filter(b => b.name !== filename));- }+ if (deletingBackupsRef.current.has(filename)) return;+ deletingBackupsRef.current.add(filename);+ // The API layer toasts the failure; keep the row on a rejected delete so+ // the archive still on disk stays visible and the user can retry (#8922).+ const deleted = await api.deleteDataBackup(filename).then(() => true, () => false);+ deletingBackupsRef.current.delete(filename);+ if (deleted) setBackups(prev => prev.filter(b => b.name !== filename));};// `fullHeight` + `padded` + the `p-4` bar/body mirror the loaded shell below,diff --git a/client/src/pages/DataManager.test.jsx b/client/src/pages/DataManager.test.jsxindex b2875afd29..e4679ddd67 100644--- a/client/src/pages/DataManager.test.jsx+++ b/client/src/pages/DataManager.test.jsx@@ -500,8 +500,8 @@ describe('DataManager backup deletion (#8922)', () => {deleteDataBackup.mockReset();});- it('keeps a backup row visible when deleteDataBackup is rejected', async () => {- deleteDataBackup.mockRejectedValue(new Error('Network error'));+ it('keeps a backup row visible when deleteDataBackup is rejected, then allows a retry', async () => {+ deleteDataBackup.mockRejectedValueOnce(new Error('Network error')).mockResolvedValueOnce({ deleted: 'backup-2025-01-01.tar.gz' });getDataBackups.mockResolvedValue(mockBackups);render(<DataManager />);@@ -519,6 +519,15 @@ describe('DataManager backup deletion (#8922)', () => {await waitFor(() => expect(screen.getByText('backup-2025-01-01.tar.gz')).toBeInTheDocument());// The second backup should also remainexpect(screen.getByText('backup-2025-01-02.tar.gz')).toBeInTheDocument();++ // Retrying the same row succeeds and removes it.+ fireEvent.click(screen.getAllByRole('button', { name: 'Delete backup' })[0]);+ const retryConfirm = await screen.findByRole('button', { name: 'Delete' });+ await act(async () => {+ fireEvent.click(retryConfirm);+ });+ await waitFor(() => expect(screen.queryByText('backup-2025-01-01.tar.gz')).not.toBeInTheDocument());+ expect(deleteDataBackup).toHaveBeenCalledTimes(2);});it('removes a backup row only after deleteDataBackup succeeds', async () => {@@ -542,33 +551,4 @@ describe('DataManager backup deletion (#8922)', () => {// The other backup should still be visibleexpect(screen.getByText('backup-2025-01-02.tar.gz')).toBeInTheDocument();});-- it('guards duplicate submissions while a deletion is in progress', async () => {- let resolveDelete;- deleteDataBackup.mockImplementation(() => new Promise(resolve => { resolveDelete = resolve; }));- getDataBackups.mockResolvedValue(mockBackups);-- render(<DataManager />);- await waitFor(() => expect(screen.getByText('backup-2025-01-01.tar.gz')).toBeInTheDocument());-- const deleteButton = screen.getAllByRole('button', { name: 'Delete backup' })[0];- fireEvent.click(deleteButton);-- const confirmButton = await screen.findByRole('button', { name: 'Delete' });- await act(async () => {- fireEvent.click(confirmButton);- });-- // The deletion is now in progress. If the user tries to delete again, the- // guard should prevent a second submission.- expect(deleteDataBackup).toHaveBeenCalledTimes(1);- expect(deleteDataBackup).toHaveBeenCalledWith('backup-2025-01-01.tar.gz');-- // Resolve the first deletion- await act(async () => {- resolveDelete({ success: true });- });-- await waitFor(() => expect(screen.queryByText('backup-2025-01-01.tar.gz')).not.toBeInTheDocument());- });});