Skip to content

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

address review (claude): confirm actual unreachability before treating disconnect as a restart

Adam Eivy7a9f77af2577
diff --git a/client/src/components/apps/tabs/UpdateTab.jsx b/client/src/components/apps/tabs/UpdateTab.jsx
index 267bec7583..c31644d23f 100644
--- a/client/src/components/apps/tabs/UpdateTab.jsx
+++ b/client/src/components/apps/tabs/UpdateTab.jsx
@@ -131,14 +131,22 @@ export default function UpdateTab() {
// this server process — and its socket — well before update.sh reaches its
// 'restart' step. That step event, and 'portos:update:complete', are then
// never emitted, and the UI hangs on "Reconciling..."/"Stopping apps"
- // forever even though update.sh finishes fine in the background. The
- // socket disconnecting IS the server dying, so treat it as the same
- // signal 'restart' would have been — it's a strictly more reliable proxy
- // for "the update just tore down this process" than waiting on a step
- // event from the process being torn down.
+ // forever even though update.sh finishes fine in the background. A raw
+ // 'disconnect' isn't proof of that by itself, though — PortOS is commonly
+ // used remotely over Tailscale, and a transient network blip during the
+ // pre-pm2-stop steps (git-pull/submodules, while the server is still very
+ // much alive) would fire 'disconnect' too. Confirm the server is actually
+ // unreachable before treating this as "the update just tore the process
+ // down" — otherwise a blip prematurely arms polling, which can time out
+ // with a false "Restart timed out" error while the real update finishes
+ // fine in the background with nothing left watching it.
const handleDisconnect = () => {
if (!updatingRef.current) return;
- armRestartPolling();
+ setTimeout(async () => {
+ if (!updatingRef.current) return;
+ const ok = await api.checkHealth().catch(() => null);
+ if (!ok && updatingRef.current) armRestartPolling();
+ }, 1500);
};
socket.on('portos:update:step', handleStep);
diff --git a/client/src/components/apps/tabs/UpdateTab.test.jsx b/client/src/components/apps/tabs/UpdateTab.test.jsx
index e00c91b91a..f6d12e2cb9 100644
--- a/client/src/components/apps/tabs/UpdateTab.test.jsx
+++ b/client/src/components/apps/tabs/UpdateTab.test.jsx
@@ -1,5 +1,5 @@
-import { describe, it, expect, vi, beforeEach } from 'vitest';
-import { render, screen, fireEvent, waitFor } from '@testing-library/react';
+import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
+import { act, render, screen, fireEvent, waitFor } from '@testing-library/react';
// ── Mock socket — capture registered handlers so the test can fire 'disconnect' ──
const handlers = new Map();
@@ -35,6 +35,15 @@ const OUT_OF_SYNC_STATUS = {
installState: { outOfSync: true, runningStaleCode: true },
};
+// Fires 'disconnect' and advances past the 1.5s unreachability-confirmation
+// delay in handleDisconnect, flushing the checkHealth() microtask through it.
+const fireDisconnectAndConfirm = async () => {
+ vi.useFakeTimers();
+ handlers.get('disconnect')();
+ await act(async () => { await vi.advanceTimersByTimeAsync(1500); });
+ vi.useRealTimers();
+};
+
describe('UpdateTab reconcile flow', () => {
beforeEach(() => {
handlers.clear();
@@ -45,7 +54,11 @@ describe('UpdateTab reconcile flow', () => {
mockToast.loading.mockClear();
});
- it('arms the restart-polling fallback on socket disconnect, not just on the "restart" step', async () => {
+ afterEach(() => {
+ vi.useRealTimers();
+ });
+
+ it('arms the restart-polling fallback once a disconnect is confirmed by an unreachable health check', async () => {
render(<UpdateTab />);
const button = await screen.findByRole('button', { name: 'Reconcile Now' });
@@ -57,23 +70,43 @@ describe('UpdateTab reconcile flow', () => {
// The server process dies mid-update (pm2-stop kills it) before it ever
// emits a 'restart' step or 'portos:update:complete' — only the socket
- // disconnecting tells the client the process is gone.
+ // disconnecting tells the client the process is gone. Simulate the real
+ // death: the health check that follows the disconnect also fails.
expect(handlers.has('disconnect')).toBe(true);
- fireEvent.click(button); // no-op safety: button should already reflect updating state
- handlers.get('disconnect')();
+ mockCheckHealth.mockResolvedValue(null);
+ await fireDisconnectAndConfirm();
- // The fallback must arm from 'disconnect' alone — the UI should not stay
- // stuck showing "Reconciling..." forever waiting for a step event that
- // will never arrive from the now-dead process.
+ // The fallback must arm from a confirmed 'disconnect' — the UI should not
+ // 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());
});
+ it('ignores a disconnect caused by a transient network blip (server still reachable)', async () => {
+ render(<UpdateTab />);
+
+ const button = await screen.findByRole('button', { name: 'Reconcile Now' });
+ fireEvent.click(button);
+ await waitFor(() => expect(screen.getByRole('button', { name: 'Reconciling...' })).toBeTruthy());
+
+ // PortOS is commonly used remotely over Tailscale — a socket 'disconnect'
+ // can fire from a mobile network blip during the pre-pm2-stop steps, well
+ // before the server actually dies. The health check right after the
+ // disconnect still succeeds (server alive, same pre-update version), so
+ // this must NOT be treated as proof of a restart.
+ expect(handlers.has('disconnect')).toBe(true);
+ await fireDisconnectAndConfirm();
+
+ expect(screen.getByRole('button', { name: 'Reconciling...' })).toBeTruthy();
+ expect(mockToast.loading).not.toHaveBeenCalled();
+ });
+
it('ignores a disconnect that happens while no update is in progress', async () => {
render(<UpdateTab />);
await screen.findByRole('button', { name: 'Reconcile Now' });
expect(handlers.has('disconnect')).toBe(true);
- handlers.get('disconnect')();
+ await fireDisconnectAndConfirm();
// No update was running, so disconnect must not fake-arm the restart flow.
expect(screen.getByRole('button', { name: 'Reconcile Now' })).toBeTruthy();