perf(gateway): gate sessions.list on state=running instead of gatewayReady

The maybeLoadSessions() guard previously waited for status.gatewayReady
to become true, which is driven by the server-side gateway.ready event
and backed by a 30s fallback timer in GatewayManager. In practice,
OpenClaw's plugin bootstrap often exceeds that window, so the fallback
fired and users stared at the loading state for ~30s after the WS
handshake had already completed.

sessions.list is a plain RPC — it needs the handshake to be done, not
plugins to be up. Gate it on state === 'running' so the session list is
fetched immediately after handshake completion. Existing throttling via
LOAD_SESSIONS_MIN_INTERVAL_MS still prevents spam on state flaps.
This commit is contained in:
Haze
2026-04-24 17:03:05 +08:00
parent 4271419abb
commit a3d5b0555f

View File

@@ -98,7 +98,11 @@ function maybeLoadSessions(
force = false,
): void {
const { status } = useGatewayStore.getState();
if (status.gatewayReady === false) return;
// Gate on the RPC channel being live (handshake complete), not the later
// gateway.ready event. The ready event can lag up to GATEWAY_READY_FALLBACK_MS
// behind handshake completion while plugins finish booting, and sessions.list
// does not require plugins to be up.
if (status.state !== 'running') return;
const now = Date.now();
if (!force && now - lastLoadSessionsAt < LOAD_SESSIONS_MIN_INTERVAL_MS) return;