@@ -91,15 +91,17 @@ def _resolve_bin(mode: str) -> str: # noqa: ARG001
9191_CENTRAL_API_URL = os .environ .get ("CENTRAL_API_URL" , "" ).rstrip ("/" )
9292_AGENT_ADVERTISE_URL = os .environ .get ("AGENT_ADVERTISE_URL" , "" )
9393_AGENT_MODE = os .environ .get ("AGENT_MODE" , "cdp" )
94- # Deployment/startup type reported to center: "docker" (running in container) | "shell" (native process)
94+ # Deployment/startup type reported to center:
95+ # "docker" (container) | "shell" (native process).
9596_AGENT_DEPLOY_TYPE = os .environ .get ("AGENT_DEPLOY_TYPE" , "docker" )
9697# True when the image was built with INSTALL_CHROME=true (Chrome bundled inside container).
9798# False → Chrome runs on the host; localhost must be remapped to host.docker.internal.
9899_AGENT_HAS_CHROME = os .environ .get ("AGENT_HAS_CHROME" , "false" ).lower () == "true"
99100_AGENT_LABEL = os .environ .get ("AGENT_LABEL" , socket .gethostname ())
100101# Registration mode:
101102# http — LAN mode: agent POSTs its URL to center, center calls back via HTTP (default)
102- # ws — NAT/reverse-channel mode: agent opens WS to center, registration via WS handshake (Phase 2)
103+ # ws — NAT/reverse-channel mode: agent opens WS to center, then
104+ # registers through the WS handshake.
103105# off — disable auto-registration entirely
104106_AGENT_REGISTER = os .environ .get ("AGENT_REGISTER" , "http" ).lower ()
105107# opencli subprocess execution timeout in seconds
@@ -191,7 +193,12 @@ async def _register_with_center(advertise_url: str) -> None:
191193 return
192194 except Exception as exc :
193195 wait = attempt * 3
194- logger .warning ("Registration attempt %d failed: %s — retrying in %ds" , attempt , exc , wait )
196+ logger .warning (
197+ "Registration attempt %d failed: %s — retrying in %ds" ,
198+ attempt ,
199+ exc ,
200+ wait ,
201+ )
195202 await asyncio .sleep (wait )
196203 logger .error ("Could not register with center after 5 attempts" )
197204
@@ -281,7 +288,11 @@ async def _send_result(result: dict) -> None:
281288 "event" : event ,
282289 }))
283290 except Exception as exc :
284- logger .error ("WS: failed to send agent_event for request_id=%s: %s" , request_id , exc )
291+ logger .error (
292+ "WS: failed to send agent_event for request_id=%s: %s" ,
293+ request_id ,
294+ exc ,
295+ )
285296 if terminal_event is None :
286297 # Contract violation (adapter yielded nothing) — still must resolve
287298 # the center's pending future rather than hang it until timeout.
@@ -293,7 +304,11 @@ async def _send_result(result: dict) -> None:
293304 }
294305 await _send_result (terminal_event )
295306 except RuntimeInvocationError as exc :
296- logger .exception ("WS agent_task request_id=%s: adapter invocation error: %s" , request_id , exc )
307+ logger .exception (
308+ "WS agent_task request_id=%s: adapter invocation error: %s" ,
309+ request_id ,
310+ exc ,
311+ )
297312 await _send_result ({
298313 "type" : "error" ,
299314 "task_id" : request_id ,
@@ -409,11 +424,19 @@ async def lifespan(app: FastAPI):
409424 _CENTRAL_API_URL or "" , _AGENT_REGISTER )
410425 elif _AGENT_REGISTER == "http" :
411426 advertise_url = _detect_advertise_url ()
412- logger .info ("LAN registration: advertise_url=%s → center=%s" , advertise_url , _CENTRAL_API_URL )
427+ logger .info (
428+ "LAN registration: advertise_url=%s → center=%s" ,
429+ advertise_url ,
430+ _CENTRAL_API_URL ,
431+ )
413432 asyncio .get_event_loop ().create_task (_register_with_center (advertise_url ))
414433 elif _AGENT_REGISTER == "ws" :
415434 advertise_url = _detect_advertise_url ()
416- logger .info ("WS registration: advertise_url=%s → center=%s" , advertise_url , _CENTRAL_API_URL )
435+ logger .info (
436+ "WS registration: advertise_url=%s → center=%s" ,
437+ advertise_url ,
438+ _CENTRAL_API_URL ,
439+ )
417440 _ws_task = asyncio .get_event_loop ().create_task (_register_via_ws (advertise_url ))
418441 yield
419442 if _ws_task and not _ws_task .done ():
@@ -468,7 +491,11 @@ async def _cleanup_cdp_tabs(cdp_endpoint: str, pre_existing_ids: set[str]) -> No
468491 if tab .get ("type" ) == "page" and tab_id not in pre_existing_ids :
469492 try :
470493 await client .get (f"{ cdp_endpoint } /json/close/{ tab_id } " )
471- logger .info ("cleanup: closed new tab %s url=%s" , tab_id , tab .get ("url" , "" )[:80 ])
494+ logger .info (
495+ "cleanup: closed new tab %s url=%s" ,
496+ tab_id ,
497+ tab .get ("url" , "" )[:80 ],
498+ )
472499 remaining_pages -= 1
473500 except Exception :
474501 pass
@@ -560,7 +587,7 @@ async def collect(req: CollectRequest) -> dict:
560587 )
561588 stdout , stderr = await asyncio .wait_for (proc .communicate (), timeout = _OPENCLI_TIMEOUT )
562589 rc = proc .returncode
563- except asyncio . TimeoutError :
590+ except TimeoutError :
564591 logger .error ("timeout | cmd=%s" , " " .join (cmd ))
565592 if proc :
566593 proc .kill ()
0 commit comments