Skip to content

Commit 0584dcf

Browse files
committed
Fix critical bug: use SpaceStage enum values for comparison
Fixed a critical bug where we were comparing runtime.stage (a string) directly to SpaceStage enum objects, which always evaluated to False. This caused deployments to never reach RUNNING status and continue polling forever. The HuggingFace API returns runtime.stage as a string (e.g., "RUNNING"), so we must use enum.value for comparison (e.g., SpaceStage.RUNNING.value). Changes: - Use SpaceStage.RUNNING.value instead of SpaceStage.RUNNING - Use enum.value for all stage comparisons - Added comments explaining that runtime.stage is a string - Maintains type safety by using enum values instead of hardcoded strings This fixes the infinite polling issue where deployments would never stop polling even when the Space was running and healthy.
1 parent aad0c1e commit 0584dcf

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

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

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,12 @@ def do_provision_deployment(
312312
logger.info(f"Updating existing Space: {space_id}")
313313

314314
# Check if Space is sleeping/paused and restart it
315+
# Note: runtime.stage is a string, compare using enum.value
315316
runtime = api.get_space_runtime(repo_id=space_id)
316-
if runtime.stage in [SpaceStage.STOPPED, SpaceStage.PAUSED]:
317+
if runtime.stage in [
318+
SpaceStage.STOPPED.value,
319+
SpaceStage.PAUSED.value,
320+
]:
317321
logger.info(
318322
f"Space {space_id} is {runtime.stage}. Restarting..."
319323
)
@@ -504,8 +508,9 @@ def do_get_deployment_state(
504508
)
505509

506510
# Map HuggingFace Space stages to ZenML standard deployment states
511+
# Note: runtime.stage is a string, compare using enum.value
507512
# Only RUNNING + domain READY means fully provisioned with health endpoint available
508-
if runtime.stage == SpaceStage.RUNNING:
513+
if runtime.stage == SpaceStage.RUNNING.value:
509514
# Check if domain is also ready (not just Space running)
510515
if domains and domains[0].get("stage") == "READY":
511516
status = DeploymentStatus.RUNNING
@@ -522,23 +527,23 @@ def do_get_deployment_state(
522527
)
523528
# Building/updating states - health endpoint not yet available
524529
elif runtime.stage in [
525-
SpaceStage.BUILDING,
526-
SpaceStage.RUNNING_BUILDING, # Rebuilding, not fully ready
530+
SpaceStage.BUILDING.value,
531+
SpaceStage.RUNNING_BUILDING.value,
527532
]:
528533
status = DeploymentStatus.PENDING
529534
# Error states - deployment failed or misconfigured
530535
elif runtime.stage in [
531-
SpaceStage.BUILD_ERROR,
532-
SpaceStage.RUNTIME_ERROR,
533-
SpaceStage.CONFIG_ERROR,
534-
SpaceStage.NO_APP_FILE,
536+
SpaceStage.BUILD_ERROR.value,
537+
SpaceStage.RUNTIME_ERROR.value,
538+
SpaceStage.CONFIG_ERROR.value,
539+
SpaceStage.NO_APP_FILE.value,
535540
]:
536541
status = DeploymentStatus.ERROR
537542
# Stopped/paused states - deployment exists but not running
538543
elif runtime.stage in [
539-
SpaceStage.STOPPED,
540-
SpaceStage.PAUSED,
541-
SpaceStage.DELETING,
544+
SpaceStage.STOPPED.value,
545+
SpaceStage.PAUSED.value,
546+
SpaceStage.DELETING.value,
542547
]:
543548
status = DeploymentStatus.ABSENT
544549
else:

0 commit comments

Comments
 (0)