Skip to content

Self-improving AI Employees for everyone

Fix docker scripts.

trohitg238bb28db639
diff --git a/client/src/contexts/WebSocketContext.tsx b/client/src/contexts/WebSocketContext.tsx
index a1bf8f61..482bbc2b 100644
--- a/client/src/contexts/WebSocketContext.tsx
+++ b/client/src/contexts/WebSocketContext.tsx
@@ -1512,45 +1512,46 @@ export const WebSocketProvider: React.FC<{ children: React.ReactNode }> = ({ chi
// Don't connect if still loading auth or not authenticated
if (authLoading || !isAuthenticated) {
- // If we were connected and user logs out, disconnect
- if (wsRef.current) {
- if (wsRef.current.readyState === WebSocket.OPEN ||
- wsRef.current.readyState === WebSocket.CONNECTING) {
- wsRef.current.close(1000, 'User logged out');
- }
- wsRef.current = null;
- setIsConnected(false);
- }
+ return;
+ }
+
+ // Skip if already connected
+ if (wsRef.current?.readyState === WebSocket.OPEN) {
return;
}
// Small delay to avoid React Strict Mode double-connection issues
const connectTimeout = setTimeout(() => {
- if (isMountedRef.current && isAuthenticated) {
+ if (isMountedRef.current && isAuthenticated && !wsRef.current) {
connect();
}
}, 100);
return () => {
- isMountedRef.current = false;
clearTimeout(connectTimeout);
+ };
+ }, [connect, isAuthenticated, authLoading]);
- // Cleanup on unmount
- if (reconnectTimeoutRef.current) {
- clearTimeout(reconnectTimeoutRef.current);
- }
- if (pingIntervalRef.current) {
- clearInterval(pingIntervalRef.current);
- }
- if (wsRef.current) {
- // Only close if WebSocket is open or connecting
- if (wsRef.current.readyState === WebSocket.OPEN ||
- wsRef.current.readyState === WebSocket.CONNECTING) {
- wsRef.current.close(1000, 'Component unmounted');
- }
+ // Handle logout - separate effect to avoid reconnect loops
+ useEffect(() => {
+ if (!isAuthenticated && wsRef.current) {
+ wsRef.current.close(1000, 'User logged out');
+ wsRef.current = null;
+ setIsConnected(false);
+ }
+ }, [isAuthenticated]);
+
+ // Cleanup on unmount only
+ useEffect(() => {
+ return () => {
+ isMountedRef.current = false;
+ if (reconnectTimeoutRef.current) clearTimeout(reconnectTimeoutRef.current);
+ if (pingIntervalRef.current) clearInterval(pingIntervalRef.current);
+ if (wsRef.current?.readyState === WebSocket.OPEN) {
+ wsRef.current.close(1000, 'Component unmounted');
}
};
- }, [connect, isAuthenticated, authLoading]);
+ }, []);
const value: WebSocketContextValue = {
// Connection state
diff --git a/server/Dockerfile b/server/Dockerfile
index d1eb0eca..08549a49 100644
--- a/server/Dockerfile
+++ b/server/Dockerfile
@@ -42,4 +42,4 @@ HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
CMD sh -c "curl -f http://localhost:\${PORT}/health || exit 1"
# Run the application
-CMD ["npm", "run", "start"]
+CMD ["python", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "3010"]
diff --git a/server/routers/whatsapp.py b/server/routers/whatsapp.py
index fd23538e..801f3b8e 100644
--- a/server/routers/whatsapp.py
+++ b/server/routers/whatsapp.py
@@ -61,11 +61,13 @@ class RPCClient:
async def connect(self):
# 2 second timeout for initial connection (fail fast if Go service not running)
+ logger.info(f"[WhatsApp RPC] Connecting to {self.url}...")
self.ws = await asyncio.wait_for(
websockets.connect(self.url, ping_interval=30, max_size=100*1024*1024),
timeout=2.0
)
self._connected = True
+ logger.info("[WhatsApp RPC] WebSocket connected, starting receive loop")
self._task = asyncio.create_task(self._recv())
async def close(self):
@@ -75,13 +77,19 @@ class RPCClient:
async def _recv(self):
try:
+ logger.info("[WhatsApp RPC] Receive loop started")
async for msg in self.ws:
data = json.loads(msg)
+ logger.debug(f"[WhatsApp RPC] Received: {data.get('method', data.get('id', 'unknown'))}")
if data.get("id") in self.pending:
self.pending[data["id"]].set_result(data)
elif "method" in data and "id" not in data:
await self._handle_event(data)
- except ConnectionClosed:
+ except ConnectionClosed as e:
+ logger.warning(f"[WhatsApp RPC] Connection closed: {e}")
+ self._connected = False
+ except Exception as e:
+ logger.error(f"[WhatsApp RPC] Receive loop error: {e}")
self._connected = False
async def _handle_event(self, data: dict):
@@ -193,6 +201,7 @@ class RPCClient:
elif method == "event.message_received":
# Message received - broadcast as custom event
+ logger.info(f"[WhatsApp RPC] Broadcasting message_received event to trigger nodes")
await broadcaster.send_custom_event("whatsapp_message_received", params)
# Forward to custom handler if set