@@ -240,7 +240,10 @@ def send_command(self, command_type: str, params: dict[str, Any] = None) -> dict
240240 raise ValueError ("MCP call missing command_type" )
241241 if params is None :
242242 return MCPResponse (success = False , error = "MCP call received with no parameters (client placeholder?)" )
243- attempts = max (config .max_retries , 5 )
243+ # Use more retries for connection failures - Unity domain reload can take 20-30+ seconds
244+ # The reload_max_retries config is for when Unity *responds* with reloading state,
245+ # but connection failures during reload need their own generous retry window
246+ attempts = max (config .max_retries , 15 ) # Increased from 5 to 15 for CI stability
244247 base_backoff = max (0.5 , config .retry_delay )
245248
246249 def read_status_file (target_hash : str | None = None ) -> dict | None :
@@ -300,7 +303,9 @@ def read_status_file(target_hash: str | None = None) -> dict | None:
300303 try :
301304 # Ensure connected (handshake occurs within connect())
302305 if not self .sock and not self .connect ():
303- raise ConnectionError ("Could not connect to Unity" )
306+ # Include debug info in error to help diagnose CI connection issues
307+ debug_info = f"[attempt={ attempt + 1 } /{ attempts + 1 } , port={ self .port } , instance={ self .instance_id } ]"
308+ raise ConnectionError (f"Could not connect to Unity { debug_info } " )
304309
305310 # Build payload
306311 if command_type == 'ping' :
@@ -411,12 +416,15 @@ def read_status_file(target_hash: str | None = None) -> dict | None:
411416 pass
412417
413418 # Cap backoff depending on state
419+ # Note: During Unity domain reload after script changes, the socket may be
420+ # closed entirely (not just returning "reloading"). Use longer caps to handle
421+ # CI environments where reload can take 20-30+ seconds.
414422 if status and status .get ('reloading' ):
415- cap = 0.8
423+ cap = 1.5 # Increased from 0.8 - reloading state detected
416424 elif fast_error :
417- cap = 0.25
425+ cap = 0.8 # Increased from 0.25 - transient socket errors
418426 else :
419- cap = 3.0
427+ cap = 3.0 # General errors
420428
421429 sleep_s = min (cap , jitter * (2 ** attempt ))
422430 time .sleep (sleep_s )
0 commit comments