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: fail closed on a failed maintenance-status re-read and reconcile on every connect (#8811)
[._.]/ Adam Eivy508bf3a839a1
diff --git a/client/src/components/settings/DatabaseTab.jsx b/client/src/components/settings/DatabaseTab.jsxindex 71afa032ca..aae54c84ed 100644--- a/client/src/components/settings/DatabaseTab.jsx+++ b/client/src/components/settings/DatabaseTab.jsx@@ -269,7 +269,6 @@ export function DatabaseTab() {// the same tab must still recognize its own cutover once it reconciles.const ownOperationRef = useRef(safeReadJsonSession(OWN_OPERATION_KEY));const wentDownAtRef = useRef(null);- const hasConnectedOnceRef = useRef(socket.connected);const loadStatus = useCallback(() => {setDbLoading(true);@@ -312,7 +311,12 @@ export function DatabaseTab() {toast.error('Database cutover was interrupted and needs recovery.', { id: CUTOVER_TOAST_ID });}})- .catch(() => setMaintenance(null))+ // A failed read (e.g. the server is mid-restart) tells us nothing new —+ // keep whatever fence state we last confirmed rather than dropping to+ // null, which would read as idle and re-enable competing actions while+ // a cutover may still be in flight. Only a first-ever failed read has+ // nothing to preserve, which correctly renders "unable to check".+ .catch(() => setMaintenance((prev) => prev)).finally(() => setMaintenanceLoading(false));}, []);@@ -335,15 +339,12 @@ export function DatabaseTab() {// Push, don't poll: the cutover restarts this server, so there is no// event stream during that gap. Socket.IO's own reconnect (not a// client-driven interval) is the signal that it's safe to re-read the- // durable maintenance journal.+ // durable maintenance journal. Reconcile on EVERY connect, including the+ // first — a page reloaded while the server was still down gets its+ // mount-time HTTP reads refused, and this is the only later signal that+ // it's back. A duplicate read right after a successful mount fetch is+ // harmless.const handleConnect = () => {- if (!hasConnectedOnceRef.current) {- hasConnectedOnceRef.current = true;- return;- }- // A real reconnect (not the initial connect) — the durable journal may- // have moved on while this tab had no socket. Downtime (if any) was- // already captured by handleDisconnect below.loadStatus();reconcileMaintenance();};diff --git a/client/src/components/settings/DatabaseTab.test.jsx b/client/src/components/settings/DatabaseTab.test.jsxindex bcad0cb6c4..b682178f2a 100644--- a/client/src/components/settings/DatabaseTab.test.jsx+++ b/client/src/components/settings/DatabaseTab.test.jsx@@ -94,19 +94,36 @@ describe('DatabaseTab migration', () => {await waitFor(() => expect(screen.getAllByRole('button', { name: /^Backup$/i })[0]).toBeDisabled());});- it('reconciles the durable journal on socket reconnect, not on a timer', async () => {- // Not yet connected at mount, so the socket's own first `connect` is the- // initial handshake, not a reconnect worth re-reading the journal for.- socket.connected = false;+ it('reconciles the durable journal on every socket connect, not on a timer', async () => {await renderTab();expect(getDatabaseMaintenanceStatus).toHaveBeenCalledTimes(1);- await act(async () => { fireSocketEvent('connect'); }); // the initial connect — ignored (not a reconnect)- expect(getDatabaseMaintenanceStatus).toHaveBeenCalledTimes(1);+ // Reconciling on every connect (not just a later reconnect) matters when a+ // page reloads while the server is still down: the mount-time HTTP read+ // fails, and the socket's first successful connect is the only signal+ // that it's safe to re-read the journal.+ await act(async () => { fireSocketEvent('connect'); });+ await waitFor(() => expect(getDatabaseMaintenanceStatus).toHaveBeenCalledTimes(2));await act(async () => { fireSocketEvent('disconnect'); });- await act(async () => { fireSocketEvent('connect'); }); // a real reconnect after a real disconnect- await waitFor(() => expect(getDatabaseMaintenanceStatus).toHaveBeenCalledTimes(2));+ await act(async () => { fireSocketEvent('connect'); });+ await waitFor(() => expect(getDatabaseMaintenanceStatus).toHaveBeenCalledTimes(3));+ });++ it('keeps the last known fenced state (fails closed) when a status re-read errors mid-cutover', async () => {+ getDatabaseMaintenanceStatus.mockResolvedValueOnce({+ id: 'op-5', stage: 'exporting', coordinator: 'awaiting-exit', source: 'docker', target: 'native', fenced: true,+ });+ render(<DatabaseTab />);+ await waitFor(() => expect(screen.getByText(/Draining writers|Exporting source database/i)).toBeTruthy());++ getDatabaseMaintenanceStatus.mockRejectedValueOnce(new Error('server unreachable'));+ await act(async () => { fireSocketEvent('disconnect'); });+ await act(async () => { fireSocketEvent('connect'); });++ // Still shows the fenced state — never silently drops to idle/unknown,+ // which would re-enable competing backend actions mid-cutover.+ expect(screen.getByText(/Exporting source database/i)).toBeTruthy();});it('shows an actionable recovery control for an interrupted cutover, and resumes the same operation id', async () => {