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-1087]): drop superseded stream's buffered lines; note useSseProgress divergence
Adam Eivy9fe6f1771218
diff --git a/client/src/hooks/useInstallStream.js b/client/src/hooks/useInstallStream.jsindex 95f7267108..b7cd4993b4 100644--- a/client/src/hooks/useInstallStream.js+++ b/client/src/hooks/useInstallStream.js@@ -19,6 +19,12 @@ import { safeParseJSON } from '../lib/genUtils';* Closing the EventSource (via `close()` on cancel, or unmount/disable) is what* the server interprets as a cancel — it SIGTERMs the underlying pip/bash child.*+ * Deliberately NOT built on `useSseProgress`: this needs kind-tagged log+ * accumulation with a cap + optional debounced flush, stage tracking, a+ * `streamStarted` signal, `doneRef`-gated connection-lost suppression, an+ * `onComplete` callback, and auto-scroll — all beyond what `useSseProgress`+ * exposes. Wrapping it would add indirection without removing code.+ ** `flushMs` controls log batching: 0 flushes each line synchronously (fine for* the structured, bounded FLUX.2 stream); >0 buffers and flushes on a debounce* so a chatty pip/git stream re-renders the log list at ~1/flushMs Hz instead@@ -86,6 +92,10 @@ export function useInstallStream(url, {useEffect(() => {const clearFlush = () => {if (flushTimerRef.current != null) { clearTimeout(flushTimerRef.current); flushTimerRef.current = null; }+ // Drop any un-flushed lines too: with flushMs > 0 a superseded stream can+ // leave buffered lines behind, and the next stream's flush would render+ // them into its own log.+ pendingRef.current = [];};const closeStream = () => {if (esRef.current) { esRef.current.close(); esRef.current = null; }@@ -98,7 +108,6 @@ export function useInstallStream(url, {doneRef.current = false;setError(null);setStreamStarted(false);- pendingRef.current = [];clearFlush();closeStream();return undefined;diff --git a/client/src/hooks/useInstallStream.test.jsx b/client/src/hooks/useInstallStream.test.jsxindex 451701cee6..ce1820efcc 100644--- a/client/src/hooks/useInstallStream.test.jsx+++ b/client/src/hooks/useInstallStream.test.jsx@@ -178,6 +178,11 @@ describe('useInstallStream', () => {expect(result.current.error).toBeNull();expect(second.closed).toBe(false);+ // A stale onerror on the superseded stream is likewise ignored.+ act(() => { first.fail(); });+ expect(result.current.error).toBeNull();+ expect(second.closed).toBe(false);+// The live stream still works.act(() => { second.emit({ type: 'log', message: 'live' }); });expect(result.current.logs.map((e) => e.text)).toEqual(['live']);@@ -203,6 +208,26 @@ describe('useInstallStream', () => {expect(result.current.logs.map((e) => e.text)).toEqual(['a', 'b']);});+ it('drops a superseded stream\'s un-flushed buffer on url change (flushMs > 0)', () => {+ vi.useFakeTimers();+ const { result, rerender } = renderHook(+ ({ url }) => useInstallStream(url, { enabled: true, flushMs: 100 }),+ { initialProps: { url: '/a' } },+ );+ const first = MockEventSource.instances[0];+ // Buffer a line on stream A but DON'T let the debounce fire.+ act(() => { first.emit({ type: 'log', message: 'stale-A' }); });+ expect(result.current.logs).toEqual([]);++ // url change re-runs the effect: cleanup cancels A's timer + drops its buffer.+ rerender({ url: '/b' });+ const second = MockEventSource.instances[1];+ act(() => { second.emit({ type: 'log', message: 'live-B' }); });+ act(() => { vi.advanceTimersByTime(100); });+ // Only B's line lands — A's buffered 'stale-A' must not leak in.+ expect(result.current.logs.map((e) => e.text)).toEqual(['live-B']);+ });+it('flushes buffered lines immediately on a terminal frame even with flushMs > 0', () => {vi.useFakeTimers();const { result } = renderHook(() => useInstallStream('/x', { enabled: true, flushMs: 100 }));