diff --git a/sky/serve/serve_utils.py b/sky/serve/serve_utils.py index 4ae40c24feb..fa0193185a7 100644 --- a/sky/serve/serve_utils.py +++ b/sky/serve/serve_utils.py @@ -542,11 +542,6 @@ def stream_replica_logs(service_name: str, replica_cluster_name = generate_replica_cluster_name( service_name, replica_id) - handle = global_user_state.get_handle_from_cluster_name( - replica_cluster_name) - if handle is None: - return _FAILED_TO_FIND_REPLICA_MSG.format(replica_id=replica_id) - assert isinstance(handle, backends.CloudVmRayResourceHandle), handle launch_log_file_name = generate_replica_launch_log_file_name( service_name, replica_id) @@ -580,6 +575,11 @@ def _get_replica_status() -> serve_state.ReplicaStatus: f'of replica {replica_id}...{colorama.Style.RESET_ALL}') backend = backends.CloudVmRayBackend() + handle = global_user_state.get_handle_from_cluster_name( + replica_cluster_name) + if handle is None: + return _FAILED_TO_FIND_REPLICA_MSG.format(replica_id=replica_id) + assert isinstance(handle, backends.CloudVmRayResourceHandle), handle # Always tail the latest logs, which represent user setup & run. returncode = backend.tail_logs(handle, job_id=None, follow=follow) if returncode != 0: