@@ -259,8 +259,11 @@ async def _register_with_controller(self, local_channel: grpc.aio.Channel):
259259 )
260260 # Mark exporter as registered internally
261261 self ._registered = True
262- # Report that exporter is available to the controller
263- await self ._report_status (ExporterStatus .AVAILABLE , "Exporter registered and available" )
262+ # Only report AVAILABLE status during initial registration (no lease context)
263+ # During per-lease registration, status is managed by serve() to avoid
264+ # overwriting LEASE_READY with AVAILABLE
265+ if self ._lease_context is None :
266+ await self ._report_status (ExporterStatus .AVAILABLE , "Exporter registered and available" )
264267
265268 async def _report_status (self , status : ExporterStatus , message : str = "" ):
266269 """Report the exporter status with the controller and session."""
@@ -410,16 +413,16 @@ async def handle_lease(self, lease_name: str, tg: TaskGroup, lease_scope: LeaseC
410413 # Populate the lease scope with session and socket path
411414 lease_scope .session = session
412415 lease_scope .socket_path = path
413- # Sync current status to the newly created session
414- # This ensures the session has the correct status even if _report_status
415- # was called before the session was created (race condition fix)
416- session .update_status (lease_scope .current_status , lease_scope .status_message )
417416
418417 # Wait for before-lease hook to complete before processing client connections
419418 logger .info ("Waiting for before-lease hook to complete before accepting connections" )
420419 await lease_scope .before_lease_hook .wait ()
421420 logger .info ("Before-lease hook completed, now accepting connections" )
422421
422+ # Sync status to session AFTER hook completes - this ensures we have LEASE_READY
423+ # status from serve() rather than the default AVAILABLE
424+ session .update_status (lease_scope .current_status , lease_scope .status_message )
425+
423426 # Process client connections
424427 # Type: request is jumpstarter_pb2.ListenResponse with router_endpoint and router_token fields
425428 async for request in listen_rx :
0 commit comments