Skip to content

[CLI] Space hot-reload: wait for up-to-date infos#4049

Open
cbensimon wants to merge 2 commits intomainfrom
spaces-hot-reload-wait
Open

[CLI] Space hot-reload: wait for up-to-date infos#4049
cbensimon wants to merge 2 commits intomainfrom
spaces-hot-reload-wait

Conversation

@cbensimon
Copy link
Copy Markdown
Contributor

@cbensimon cbensimon commented Apr 3, 2026

Space backend webhook handler is sometimes lagging, let's make hot-reload still work


Note

Medium Risk
Changes the Spaces hot-reload flow by pinning uploads to the current running SHA and polling space_info until it reflects the new commit, which could impact CLI behavior (including potential waits) if the backend is slow or inconsistent.

Overview
Improves hf spaces hot-reload robustness when Space metadata lags by capturing the current running SHA and using it as parent_commit for the upload.

After triggering the hot-reload, the CLI now polls api.space_info until the SHA changes and then validates that the reported SHA matches the newly created commit, failing fast with a clear error if the expected commit isn’t reflected yet.

Written by Cursor Bugbot for commit dd2c0ea. This will update automatically on new commits. Configure here.

@cbensimon cbensimon requested a review from hanouticelina April 3, 2026 19:23
@bot-ci-comment
Copy link
Copy Markdown

bot-ci-comment bot commented Apr 3, 2026

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

typer.secho("Waiting for up-to-date Space infos", fg=typer.colors.BRIGHT_BLACK)
time.sleep(2)
if space_info.sha != commit_sha:
raise CLIError(f"Expected SHA {commit_sha} after hot-reload but got {space_info.sha}")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SHA check crashes when skip_checks is True

Medium Severity

When skip_checks=True, current_sha is None, so the while-loop condition space_info.sha == None is almost always False and the polling loop is never entered. The code then falls through to space_info.sha != commit_sha, which will likely fail because the webhook hasn't processed yet — the exact lag scenario this PR is meant to handle. This is a regression: before this change, --skip-checks users could still see the summary; now they get a CLIError.

Additional Locations (1)
Fix in Cursor Fix in Web

if current_sha is None:
break
typer.secho("Waiting for up-to-date Space infos", fg=typer.colors.BRIGHT_BLACK)
time.sleep(2)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Polling loop lacks timeout, may hang indefinitely

Low Severity

The while loop polling for updated Space info has no timeout or maximum retry count. If the backend never updates the SHA (e.g., server error, stuck webhook), the CLI will hang indefinitely making API calls every 2 seconds with no way to exit besides Ctrl+C and no feedback about progress or elapsed time.

Fix in Cursor Fix in Web

Comment on lines +352 to +356
while (space_info := api.space_info(space_id)).sha == current_sha:
if current_sha is None:
break
typer.secho("Waiting for up-to-date Space infos", fg=typer.colors.BRIGHT_BLACK)
time.sleep(2)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should use StatusLine which overwrites the same line on stderr instead of printing a new line every 2 sec

Suggested change
while (space_info := api.space_info(space_id)).sha == current_sha:
if current_sha is None:
break
typer.secho("Waiting for up-to-date Space infos", fg=typer.colors.BRIGHT_BLACK)
time.sleep(2)
status = StatusLine()
while (space_info := api.space_info(space_id)).sha == current_sha:
if current_sha is None:
break
status.update("Waiting for up-to-date Space info...")
time.sleep(2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants