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([issue-1144]): address claude review — stale terminal frame replay and retry-path state reset
[._.]/ Adam Eivy14a4c30494af
diff --git a/client/src/hooks/useInstallStream.js b/client/src/hooks/useInstallStream.jsindex b7cd4993b4..596902d73e 100644--- a/client/src/hooks/useInstallStream.js+++ b/client/src/hooks/useInstallStream.js@@ -113,6 +113,15 @@ export function useInstallStream(url, {return undefined;}+ // Reset state on every (re)subscribe, not just on disable — a url change+ // while enabled (e.g. a retry that bumps an attempt counter) must start+ // the new stream clean, or a prior run's `error`/`done`/log lines leak+ // into it (wedging consumers that derive "installing" from those flags).+ setLogs([]);+ setCurrentStage(null);+ setDone(false);+ doneRef.current = false;+ setError(null);setStreamStarted(true);const es = new EventSource(url);esRef.current = es;diff --git a/client/src/hooks/useInstallStream.test.jsx b/client/src/hooks/useInstallStream.test.jsxindex 4348d19546..92435b3c32 100644--- a/client/src/hooks/useInstallStream.test.jsx+++ b/client/src/hooks/useInstallStream.test.jsx@@ -213,4 +213,27 @@ describe('useInstallStream', () => {expect(result.current.logs.map((e) => e.text)).toEqual(['a', 'done']);expect(result.current.done).toBe(true);});++ it('resets error/done/log state when the url changes while enabled (retry path)', () => {+ const { result, rerender } = renderHook(+ ({ url }) => useInstallStream(url, { enabled: true }),+ { initialProps: { url: '/install?attempt=1' } },+ );+ act(() => { last().emit({ type: 'error', message: 'pip exited with code 1' }); });+ expect(result.current.error).toBe('pip exited with code 1');+ expect(result.current.logs).toHaveLength(1);++ // A retry bumps the url (attempt counter) without toggling enabled — the+ // new stream must start clean or `error` wedges the consumer's+ // "installing" derivation and the old log lines leak into the new run.+ rerender({ url: '/install?attempt=2' });+ expect(result.current.error).toBeNull();+ expect(result.current.done).toBe(false);+ expect(result.current.logs).toEqual([]);+ expect(result.current.streamStarted).toBe(true);++ act(() => { last().emit({ type: 'complete', message: 'ok' }); });+ expect(result.current.done).toBe(true);+ expect(result.current.error).toBeNull();+ });});diff --git a/client/src/hooks/useSseProgress.js b/client/src/hooks/useSseProgress.jsindex d65f58ce8e..33e42411e7 100644--- a/client/src/hooks/useSseProgress.js+++ b/client/src/hooks/useSseProgress.js@@ -5,6 +5,9 @@ import { useEffect, useRef, useState } from 'react';// emitter that drifts back to the double-l spelling still terminates.const TERMINAL_TYPES = new Set(['complete', 'canceled', 'cancelled', 'error']);+/** True when a frame is one of the stream-ending types this hook closes on. */+export const isTerminalSseFrame = (frame) => TERMINAL_TYPES.has(frame?.type);+/*** Subscribe to a server-side EventSource stream of JSON-payload progress* frames. Used by both the per-issue auto-runner and the per-volumediff --git a/client/src/hooks/useSseProgress.test.jsx b/client/src/hooks/useSseProgress.test.jsxindex baeb207800..9a611676de 100644--- a/client/src/hooks/useSseProgress.test.jsx+++ b/client/src/hooks/useSseProgress.test.jsx@@ -1,6 +1,6 @@import { describe, it, expect, beforeEach, afterEach } from 'vitest';import { renderHook, act } from '@testing-library/react';-import { useSseProgress } from './useSseProgress';+import { useSseProgress, isTerminalSseFrame } from './useSseProgress';import { MockEventSource, lastEventSource as last } from '../test/mockEventSource';beforeEach(() => {@@ -59,4 +59,28 @@ describe('useSseProgress', () => {expect(result.current.frames).toHaveLength(0);expect(last().url).toBe('/b');});++ it('retains latest across a disable gap but resets closed — consumers must gate terminal handling on closed', () => {+ const { result, rerender } = renderHook(+ ({ url }) => useSseProgress(url, { enabled: !!url }),+ { initialProps: { url: '/a' } },+ );+ act(() => { last().emit({ type: 'error', error: 'boom' }); });+ expect(result.current.closed).toBe(true);+ // Stream disabled (consumer cleared its job id): closed resets, but the+ // terminal frame stays in `latest` — a consumer that re-enables and acts+ // on `latest` without checking `closed` would replay the stale terminal.+ rerender({ url: null });+ expect(result.current.closed).toBe(false);+ expect(result.current.latest).toEqual({ type: 'error', error: 'boom' });+ });++ it('isTerminalSseFrame matches the terminal set and rejects others', () => {+ expect(isTerminalSseFrame({ type: 'complete' })).toBe(true);+ expect(isTerminalSseFrame({ type: 'canceled' })).toBe(true);+ expect(isTerminalSseFrame({ type: 'cancelled' })).toBe(true);+ expect(isTerminalSseFrame({ type: 'error' })).toBe(true);+ expect(isTerminalSseFrame({ type: 'progress' })).toBe(false);+ expect(isTerminalSseFrame(null)).toBe(false);+ });});diff --git a/client/src/hooks/useValidTab.test.jsx b/client/src/hooks/useValidTab.test.jsxindex 6d62aa74cd..a6c8ccc1b0 100644--- a/client/src/hooks/useValidTab.test.jsx+++ b/client/src/hooks/useValidTab.test.jsx@@ -8,13 +8,18 @@ const TABS = [{ id: 'runs', label: 'Runs' },];-const wrapperAt = (path) => ({ children }) => (- <MemoryRouter initialEntries={[path]}>- <Routes>- <Route path="/page/:tab?" element={children} />- </Routes>- </MemoryRouter>-);+const wrapperAt = (path) => {+ function RouteWrapper({ children }) {+ return (+ <MemoryRouter initialEntries={[path]}>+ <Routes>+ <Route path="/page/:tab?" element={children} />+ </Routes>+ </MemoryRouter>+ );+ }+ return RouteWrapper;+};describe('useValidTab', () => {it('returns the tab param when it names a real tab', () => {diff --git a/client/src/pages/VideoTimelineEditor.jsx b/client/src/pages/VideoTimelineEditor.jsxindex 1fbae04c60..f9b5e606a8 100644--- a/client/src/pages/VideoTimelineEditor.jsx+++ b/client/src/pages/VideoTimelineEditor.jsx@@ -20,7 +20,7 @@ import {import toast from '../components/ui/Toast';import * as api from '../services/api';import { formatTimecode } from '../utils/formatters';-import { useSseProgress } from '../hooks/useSseProgress';+import { useSseProgress, isTerminalSseFrame } from '../hooks/useSseProgress';// Map project-time t (every clip contributes its trimmed duration) to the// (clipIndex, withinClipSec) pair the preview <video> element needs. The@@ -417,25 +417,36 @@ export default function VideoTimelineEditor() {);useEffect(() => {if (!renderJobId || !renderFrame) return;- if (renderFrame.type === 'progress') setRenderProgress(renderFrame.progress);- else if (renderFrame.type === 'complete') {+ if (renderFrame.type === 'progress') {+ setRenderProgress(renderFrame.progress);+ return;+ }+ // A genuine terminal frame sets `latest` and `closed` in the same commit,+ // so they're visible together here. A STALE terminal frame — the hook+ // keeps `latest` across the disabled gap, so starting a second render+ // briefly re-exposes the previous job's final frame — arrives with+ // `closed === false`; without this gate it would duplicate the toast and+ // tear down the new render's UI while ffmpeg keeps running.+ if (!renderStreamClosed || !isTerminalSseFrame(renderFrame)) return;+ if (renderFrame.type === 'complete') {toast.success('Timeline rendered');setRenderJobId(null);navigate(`/media/history?focus=${renderFrame.result.id}`);} else if (renderFrame.type === 'error') {toast.error(renderFrame.error || 'Render failed');setRenderJobId(null);- } else if (renderFrame.type === 'canceled') {+ } else {+ // canceled (either spelling — the hook treats both as terminal)toast('Render cancelled');setRenderJobId(null);setRenderProgress(0);}- }, [renderJobId, renderFrame, navigate]);+ }, [renderJobId, renderFrame, renderStreamClosed, navigate]);useEffect(() => {// Stream ended without a terminal frame — connection lost. Terminal frames// are handled (and clear renderJobId) in the frame effect above.if (!renderJobId || !renderStreamClosed) return;- if (['complete', 'error', 'canceled'].includes(renderFrame?.type)) return;+ if (isTerminalSseFrame(renderFrame)) return;toast.error('Lost connection to render — check Media History');setRenderJobId(null);setRenderProgress(0);