fix(run): wait for image to be ready before creating instance#10
fix(run): wait for image to be ready before creating instance#10
Conversation
The CLI was immediately attempting to create an instance after calling POST /images, which returns 202 Accepted with status 'pending'. Since image builds are asynchronous, the instance creation would fail with 'image_not_ready' error. This fix adds polling logic to wait for the image status to become 'ready' (or 'failed') before proceeding to create the instance. Status updates are shown to the user as the image progresses through: pending -> pulling -> converting -> ready Fixes race condition where first 'hypeman run' would fail but second would succeed after background build completed.
Mesa DescriptionProblemThe CLI was immediately attempting to create an instance after calling This caused a race condition where the first SolutionAdded polling logic to wait for the image status to become Status updates are shown to the user as the image progresses through build stages:
Implementation DetailsThe Security ImpactTesting# Delete any existing debian:12 image first, then:
./hypeman run debian:12Should now show progress and wait for the image to be ready before creating the instance. Description generated by Mesa. Update settings |
There was a problem hiding this comment.
Performed full review of 9d7cf81...048ee73
Analysis
-
Unbounded Polling Risk: The
waitForImageReadyfunction lacks a timeout or retry limit, potentially causing the CLI to poll indefinitely if an image build stalls in a non-terminal state. This could be problematic for automated scripts, unaware users, or backend issues. -
Polling Efficiency Concerns: The fixed 1-second polling interval may be too aggressive for long-running image builds, potentially causing unnecessary API load. Consider implementing exponential backoff or configurable intervals.
-
Inconsistent Error Handling: Early status checks return errors without showing initial status information, which could confuse users about failure reasons. Additional user feedback would improve clarity when polling is skipped.
Tip
Help
Slash Commands:
/review- Request a full code review/review latest- Review only changes since the last review/describe- Generate PR description. This will update the PR body or issue comment depending on your configuration/help- Get help with Mesa commands and configuration options
1 files reviewed | 0 comments | Edit Agent Settings • Read Docs
Problem
The CLI was immediately attempting to create an instance after calling
POST /images, which returns202 Acceptedwithstatus: pending. Since image builds are asynchronous, the instance creation would fail withimage_not_readyerror.This caused a race condition where the first
hypeman run debian:12would fail (retrying 3 times), but a second run would succeed after the background build completed.Solution
Added polling logic to wait for the image status to become
ready(orfailed) before proceeding to create the instance.Status updates are shown to the user as the image progresses through build stages:
Queued...(pending)Pulling image...(pulling)Converting to disk image...(converting)Image ready.(ready)Testing
# Delete any existing debian:12 image first, then: ./hypeman run debian:12Should now show progress and wait for the image to be ready before creating the instance.