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
address review (claude): guard disconnect confirmation against unmount + silence its health checks
Adam Eivye779211e644f
diff --git a/client/src/components/apps/tabs/UpdateTab.jsx b/client/src/components/apps/tabs/UpdateTab.jsxindex c31644d23f..6e134ce40d 100644--- a/client/src/components/apps/tabs/UpdateTab.jsx+++ b/client/src/components/apps/tabs/UpdateTab.jsx@@ -46,6 +46,14 @@ export default function UpdateTab() {// Mirrors `updating` for the socket 'disconnect' listener below, which is// registered once on mount and would otherwise close over a stale `false`.const updatingRef = useRef(false);+ // Guards the disconnect-confirmation setTimeout below: without this, an+ // unmount (e.g. the user navigates away) while the timer is pending lets+ // the deferred callback still fire, pop an undismissable "PortOS is+ // restarting..." toast (duration: Infinity), and set state on an unmounted+ // component — nothing is left running to ever dismiss it. Never reset to+ // `true`; this only ever needs to flip once, on unmount.+ const mountedRef = useRef(true);+ useEffect(() => () => { mountedRef.current = false; }, []);// Tracks whether the health endpoint went down during a restart poll. A// reconcile (issue #1779) often lands the SAME version (new commits, no// release bump), so version-change detection alone can't confirm completion —@@ -143,9 +151,13 @@ export default function UpdateTab() {const handleDisconnect = () => {if (!updatingRef.current) return;setTimeout(async () => {- if (!updatingRef.current) return;- const ok = await api.checkHealth().catch(() => null);- if (!ok && updatingRef.current) armRestartPolling();+ if (!updatingRef.current || !mountedRef.current) return;+ // silent: true — a failed check here just means "confirmed, arm+ // polling"; the generic "Server unreachable" toast would otherwise+ // fire right alongside (and ahead of) the intended "restarting" toast+ // on the exact real-disconnect case this confirmation exists for.+ const ok = await api.checkHealth({ silent: true }).catch(() => null);+ if (!ok && updatingRef.current && mountedRef.current) armRestartPolling();}, 1500);};@@ -174,7 +186,12 @@ export default function UpdateTab() {const pollHealth = useCallback(async () => {attemptsRef.current += 1;- const ok = await api.checkHealth().catch(() => null);+ // silent: true — the server being unreachable is the EXPECTED state for+ // most of this restart poll (that's the down→up transition it's+ // watching for), not an error; the generic toast would spam "Server+ // unreachable" on every 2s tick throughout the "PortOS is restarting..."+ // loading toast's own lifetime.+ const ok = await api.checkHealth({ silent: true }).catch(() => null);const preUpdateVersion = preUpdateVersionRef.current;if (!ok) {// Server is mid-restart (PM2 stopped it) — record the dip so a same-versiondiff --git a/client/src/components/apps/tabs/UpdateTab.test.jsx b/client/src/components/apps/tabs/UpdateTab.test.jsxindex f6d12e2cb9..a420f9ea7d 100644--- a/client/src/components/apps/tabs/UpdateTab.test.jsx+++ b/client/src/components/apps/tabs/UpdateTab.test.jsx@@ -80,6 +80,31 @@ describe('UpdateTab reconcile flow', () => {// stay stuck showing "Reconciling..." forever waiting for a step event// that will never arrive from the now-dead process.await waitFor(() => expect(screen.getByRole('button', { name: 'Restarting...' })).toBeTruthy());+ // The confirmation check must be silent — a real disconnect is the+ // primary case this fallback exists for, and a generic "Server+ // unreachable" toast firing right alongside the intended "restarting"+ // toast would be a confusing double-toast on the common path.+ expect(mockCheckHealth).toHaveBeenLastCalledWith({ silent: true });+ });++ it('does not pop an undismissable "restarting" toast if the component unmounts before the disconnect confirmation resolves', async () => {+ const { unmount } = render(<UpdateTab />);++ const button = await screen.findByRole('button', { name: 'Reconcile Now' });+ fireEvent.click(button);+ await waitFor(() => expect(screen.getByRole('button', { name: 'Reconciling...' })).toBeTruthy());++ // The server really did go down (confirms), but the user navigated away+ // before the 1.5s confirmation delay elapsed. Nothing is left mounted to+ // ever dismiss a toast.loading({ duration: Infinity }) popped after this.+ mockCheckHealth.mockResolvedValue(null);+ vi.useFakeTimers();+ handlers.get('disconnect')();+ unmount();+ await act(async () => { await vi.advanceTimersByTimeAsync(1500); });+ vi.useRealTimers();++ expect(mockToast.loading).not.toHaveBeenCalled();});it('ignores a disconnect caused by a transient network blip (server still reachable)', async () => {diff --git a/client/src/services/apiSystem.js b/client/src/services/apiSystem.jsindex 482168b1bb..b8c4f5e48e 100644--- a/client/src/services/apiSystem.js+++ b/client/src/services/apiSystem.js@@ -7,7 +7,7 @@ export const getAlertsSummary = (options) => request('/alerts/summary', options)export const getCharacter = (options) => request('/character', options);// Health-export const checkHealth = () => request('/system/health');+export const checkHealth = (options) => request('/system/health', options);export const getSystemHealth = (options) => request('/system/health/details', options);export const getNetworkExposure = (options) => request('/network-exposure/status', options);export const getCapabilities = (options) => request('/capabilities', options);