Skip to content

Commit e3cf79c

Browse files
committed
Skip HTTP health check for HuggingFace Spaces
Fixed the issue where private HuggingFace Spaces would continuously poll because the HTTP health check endpoint returns 404 for unauthenticated requests. Why this is the right solution: 1. Private Spaces block unauthenticated HTTP requests (returns 404) 2. We already have reliable health state from HuggingFace API 3. When Space stage is RUNNING and domain is READY, we know the deployment is genuinely healthy 4. HuggingFace platform handles internal health checks for us The health check method now simply returns True, relying on the comprehensive Space runtime state validation we perform in do_get_deployment_state(). This allows deployments to complete successfully for both public and private Spaces.
1 parent 5898dc3 commit e3cf79c

File tree

1 file changed

+12
-58
lines changed

1 file changed

+12
-58
lines changed

src/zenml/integrations/huggingface/deployers/huggingface_deployer.py

Lines changed: 12 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -589,72 +589,26 @@ def _check_deployment_health(
589589
self,
590590
deployment: DeploymentResponse,
591591
) -> bool:
592-
"""Check if the deployment is healthy by calling its health check endpoint.
592+
"""Check if the deployment is healthy.
593593
594-
Overrides base method to add better logging for debugging.
594+
For HuggingFace Spaces, we skip the HTTP health check because:
595+
1. Private Spaces block unauthenticated health check requests (404)
596+
2. We already have reliable state from HuggingFace API
597+
3. If Space stage is RUNNING and domain is READY, deployment is healthy
595598
596599
Args:
597600
deployment: The deployment to check.
598601
599602
Returns:
600-
True if the deployment is healthy, False otherwise.
603+
True if the deployment is healthy (always True for HF Spaces).
601604
"""
602-
import requests
603-
604-
from zenml.config.deployment_settings import (
605-
DeploymentDefaultEndpoints,
606-
)
607-
608-
assert deployment.snapshot, "Deployment snapshot not found"
609-
610-
settings = (
611-
deployment.snapshot.pipeline_configuration.deployment_settings
605+
# HuggingFace Spaces: Skip HTTP health check, rely on Space runtime state
606+
# We already verified Space is RUNNING and domain is READY in get_deployment_state
607+
logger.debug(
608+
f"Skipping HTTP health check for HuggingFace Space deployment "
609+
f"{deployment.name} (relying on Space runtime state)"
612610
)
613-
614-
# If the health check endpoint is disabled, we consider the deployment healthy.
615-
if (
616-
DeploymentDefaultEndpoints.HEALTH
617-
not in settings.include_default_endpoints
618-
):
619-
logger.debug(
620-
f"Health check disabled for deployment {deployment.name}"
621-
)
622-
return True
623-
624-
if not deployment.url:
625-
logger.debug(
626-
f"No URL available for deployment {deployment.name}, health check fails"
627-
)
628-
return False
629-
630-
health_check_path = f"{settings.root_url_path}{settings.api_url_path}{settings.health_url_path}"
631-
health_check_url = f"{deployment.url}{health_check_path}"
632-
633-
logger.info(
634-
f"Checking health endpoint for deployment {deployment.name}: {health_check_url}"
635-
)
636-
637-
# Attempt to connect to the deployment and check if it is healthy
638-
try:
639-
response = requests.get(health_check_url, timeout=3)
640-
if response.status_code == 200:
641-
logger.info(
642-
f"Health check passed for deployment {deployment.name}"
643-
)
644-
return True
645-
else:
646-
logger.warning(
647-
f"Health check endpoint for deployment '{deployment.name}' "
648-
f"at '{health_check_url}' returned status code "
649-
f"{response.status_code}"
650-
)
651-
return False
652-
except Exception as e:
653-
logger.warning(
654-
f"Health check endpoint for deployment '{deployment.name}' "
655-
f"at '{health_check_url}' is not reachable: {e}"
656-
)
657-
return False
611+
return True
658612

659613
def do_get_deployment_state_logs(
660614
self,

0 commit comments

Comments
 (0)