mirror of
https://github.com/purrgrammer/grimoire.git
synced 2026-04-10 23:47:12 +02:00
fix: use majority EOSE heuristic for faster LOADING → LIVE transition
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
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user