From 1bfdede83714dd6af591723235ccd2ee91116c6d Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 2 Feb 2026 12:48:08 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20use=20majority=20EOSE=20heuristic=20for?= =?UTF-8?q?=20faster=20LOADING=20=E2=86=92=20LIVE=20transition?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of waiting for ALL relays to send EOSE before transitioning from LOADING to LIVE state, use a majority heuristic where >50% of relays having sent EOSE is sufficient. This prevents slow or unresponsive relays from blocking the UI. The fallback "all terminal states" check is preserved for error scenarios where relays fail without sending EOSE. https://claude.ai/code/session_01P8oPqRLSCRkAdT1sBbaAiL --- src/hooks/useReqTimelineEnhanced.ts | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/hooks/useReqTimelineEnhanced.ts b/src/hooks/useReqTimelineEnhanced.ts index cda3c4e..0e546f4 100644 --- a/src/hooks/useReqTimelineEnhanced.ts +++ b/src/hooks/useReqTimelineEnhanced.ts @@ -216,16 +216,33 @@ export function useReqTimelineEnhanced( eoseAt: Date.now(), }); - // Check if ALL relays have reached EOSE - const allEose = Array.from(next.values()).every( + // Count states for majority heuristic + const states = Array.from(next.values()); + const eoseCount = states.filter( + (s) => s.subscriptionState === "eose", + ).length; + const totalRelays = states.length; + + // Majority heuristic: consider stream ready when >50% of relays have EOSE + // This prevents slow/unresponsive relays from blocking the UI + const majorityEose = eoseCount > totalRelays / 2; + + // Fallback: also ready if all relays are in terminal states + // (handles error scenarios where relays fail without EOSE) + const allTerminal = states.every( (s) => s.subscriptionState === "eose" || s.connectionState === "error" || s.connectionState === "disconnected", ); - if (allEose && !eoseReceivedRef.current) { - console.log("REQ Enhanced: All relays finished"); + if ((majorityEose || allTerminal) && !eoseReceivedRef.current) { + console.log("REQ Enhanced: Stream ready", { + eoseCount, + totalRelays, + majorityEose, + allTerminal, + }); setEoseReceived(true); if (!stream) { setLoading(false);