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([importer-progress-reconnect]): make snapshot replay hook-driven, not connection-time
[._.]/ Adam Eivy6f4922fb11dd
diff --git a/client/src/hooks/useImporterProgress.js b/client/src/hooks/useImporterProgress.jsindex 10194a438f..5a88fc298f 100644--- a/client/src/hooks/useImporterProgress.js+++ b/client/src/hooks/useImporterProgress.js@@ -56,7 +56,21 @@ export function useImporterProgress() {}};socket.on('importer:progress', onProgress);- return () => socket.off('importer:progress', onProgress);++ // Ask the server to replay the in-flight analyze snapshot. The socket+ // auto-connects at app load — before this lazily-mounted hook registers+ // its listener — so a server-side connection-time replay would arrive+ // before anyone was listening. Requesting it HERE (after `on()`) and again+ // on every `connect` (reconnect) guarantees a listener is in place when the+ // replayed frames land, so a tab that opens or reconnects mid-analyze+ // rebuilds its checklist instead of staying on "Starting…".+ const requestReplay = () => socket.emit('importer:progress:replay');+ requestReplay();+ socket.on('connect', requestReplay);+ return () => {+ socket.off('importer:progress', onProgress);+ socket.off('connect', requestReplay);+ };}, []);return { stages, reset };diff --git a/client/src/hooks/useImporterProgress.test.jsx b/client/src/hooks/useImporterProgress.test.jsxindex c27bec60c6..454c268eb4 100644--- a/client/src/hooks/useImporterProgress.test.jsx+++ b/client/src/hooks/useImporterProgress.test.jsx@@ -3,21 +3,25 @@ import { renderHook, act, cleanup } from '@testing-library/react';import { CheckCircle2, AlertTriangle, Loader2, Circle } from 'lucide-react';// Mock the socket module so the test can drive the `importer:progress` handler-// the hook registers with `on()`.+// the hook registers with `on()` and observe the `emit()` replay requests.const handlers = new Map();+const emitted = [];vi.mock('../services/socket', () => ({default: {on: (event, fn) => { handlers.set(event, fn); },off: (event, fn) => { if (handlers.get(event) === fn) handlers.delete(event); },+ emit: (event, ...args) => { emitted.push([event, ...args]); },},}));import { useImporterProgress, stageStatusIcon } from './useImporterProgress.js';const fire = (payload) => act(() => { handlers.get('importer:progress')?.(payload); });+// Simulate a socket (re)connect — the hook re-requests a snapshot replay.+const fireConnect = () => act(() => { handlers.get('connect')?.(); });describe('useImporterProgress', () => {- beforeEach(() => handlers.clear());+ beforeEach(() => { handlers.clear(); emitted.length = 0; });afterEach(cleanup);it('starts with null stages', () => {@@ -84,6 +88,17 @@ describe('useImporterProgress', () => {]);});+ it('requests a snapshot replay on mount and on every reconnect', () => {+ // The replay must be hook-driven: the socket auto-connects at app load,+ // before this lazily-mounted hook registers its listener, so the hook asks+ // the server to replay AFTER `on()` — and again on each `connect` so a+ // reconnect mid-analyze re-fetches the snapshot.+ renderHook(() => useImporterProgress());+ expect(emitted).toEqual([['importer:progress:replay']]);+ fireConnect();+ expect(emitted).toEqual([['importer:progress:replay'], ['importer:progress:replay']]);+ });+it('ignores malformed frames', () => {const { result } = renderHook(() => useImporterProgress());fire(null);diff --git a/server/services/socket.js b/server/services/socket.jsindex 494dab7e0b..0a5da6c140 100644--- a/server/services/socket.js+++ b/server/services/socket.js@@ -93,15 +93,23 @@ export function initSocket(io) {// and the user is offered a reload.socket.emit('build:id', { buildId: getBuildId() });- // Replay the in-flight importer analyze snapshot to this socket so a tab- // that (re)connects mid-analyze rebuilds its stage checklist instead of- // staying stuck on "Starting…" — the original gate dropped every `stage`- // frame whose run the client never saw a `start` for. No-op when no- // analyze is running (empty frame list). `setupImporterEventForwarding`- // (below) is what keeps the snapshot fed; it's armed at server start.- for (const frame of getImporterProgressFrames()) {- socket.emit('importer:progress', frame);- }+ // Replay the in-flight importer analyze snapshot ON DEMAND so a tab that+ // (re)connects mid-analyze rebuilds its stage checklist instead of staying+ // stuck on "Starting…" — the original gate dropped every `stage` frame+ // whose run the client never saw a `start` for. Replay is request-driven+ // (not fired at `connection` time) because the socket auto-connects at app+ // load, before the lazily-mounted Importer page registers its+ // `importer:progress` listener — a connection-time replay would land+ // before any listener exists and be lost. The client requests this right+ // after registering its listener and again on every reconnect (see+ // useImporterProgress). No-op when no analyze is running (empty list).+ // `setupImporterEventForwarding` (below) keeps the snapshot fed; it's armed+ // at server start.+ socket.on('importer:progress:replay', () => {+ for (const frame of getImporterProgressFrames()) {+ socket.emit('importer:progress', frame);+ }+ });// Handle streaming app detectionsocket.on('detect:start', async (rawData) => {