Skip to content

The agent that grows with you

fix(desktop): explain the stale-open gateway reconnect guard (#121680, salvage #121771)

teknium1df05d0a8e226
diff --git a/apps/desktop/src/app/gateway/hooks/use-gateway-request.ts b/apps/desktop/src/app/gateway/hooks/use-gateway-request.ts
index 18706e8c7f8..54fdc79dbe6 100644
--- a/apps/desktop/src/app/gateway/hooks/use-gateway-request.ts
+++ b/apps/desktop/src/app/gateway/hooks/use-gateway-request.ts
@@ -47,12 +47,19 @@ export function useGatewayRequest() {
)
const ensureGatewayOpen = useCallback(async () => {
+ // The ref is populated by the subscription effect after first render; the
+ // registry is the source of truth when it has not caught up yet.
const existing = gatewayRef.current ?? activeGateway()
if (!existing) {
return null
}
+ // gatewayStateRef mirrors $gatewayState through a render + effect, so it
+ // still reads 'open' for a beat after a socket drop rejected the caller's
+ // in-flight request. Trusting it alone skipped the reconnect and re-sent
+ // on the dead socket ("Hermes gateway is not connected", #121680). Ask the
+ // socket itself.
if (gatewayStateRef.current === 'open' && existing.connectionState === 'open') {
return existing
}