Auto-pull images on instance creation#147
Merged
sjmiller609 merged 6 commits intomainfrom Mar 17, 2026
Merged
Conversation
When CreateInstance is called with an image that hasn't been pulled yet, automatically trigger a pull and wait for it to complete instead of returning an error. This fixes the recurring issue where `hypeman run <image>` fails unless `hypeman pull` is run first. Adds TestCreateInstance_AutoPullImage integration test that verifies instance creation succeeds without pre-pulling the image. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The original TestCreateInstance_AutoPullImage in cmd/api/api/ required KVM and skipped in CI/non-KVM environments. Replace it with unit tests in lib/instances/ that mock the image manager to verify the auto-pull flow without needing a VM: - TestCreateInstance_AutoPullImage: verifies GetImage→CreateImage→ WaitForReady→GetImage flow when image is not found - TestCreateInstance_AutoPullImage_CreateImageFails: verifies error propagation when CreateImage fails - TestCreateInstance_AutoPullImage_WaitForReadyFails: verifies error propagation when WaitForReady fails - TestCreateInstance_ImageAlreadyReady_NoAutoPull: verifies no pull is triggered when image already exists Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Delete lib/instances/auto_pull_test.go (mock-based unit tests) and add TestCreateInstance_AutoPullImage in cmd/api/api/instances_test.go that follows the existing integration test patterns. The new test: - Checks for /dev/kvm, skips if unavailable - Creates a newTestService - Does NOT pre-pull the image (tests auto-pull) - Ensures system files with system.NewManager - Calls CreateInstance with alpine:latest and networkEnabled: false - Asserts 201 response - Cleans up by deleting the instance Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When CreateInstance encounters a missing image, it now starts the pull and waits up to 5 seconds. If the image isn't ready in time, returns an image_not_ready error while allowing the pull to continue in the background so a subsequent run finds it ready. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CreateInstanceis called with an image not found locally, automatically trigger a pull (CreateImage+WaitForReady) instead of returning an errorTestCreateInstance_AutoPullImageintegration test that creates an instance without pre-pulling the image, verifying the auto-pull path works end-to-endhypeman run <image>fails unlesshypeman pullis run firstChanges
lib/instances/create.go: WhenGetImagereturnsErrNotFound, callCreateImageto trigger a pull, wait for it withWaitForReady, then re-fetch the imagecmd/api/api/instances_test.go: New testTestCreateInstance_AutoPullImagethat verifies instance creation succeeds without pre-pullingTest plan
TestCreateInstance_AutoPullImagepasses on a KVM-enabled hosthypeman run alpine:latestworks on a fresh host with no pre-pulled images🤖 Generated with Claude Code
Note
Medium Risk
Changes
CreateInstancebehavior to trigger background image pulls and introduce a new timeout-based readiness path, which may affect instance creation reliability and error handling under slow registries or large images.Overview
CreateInstancenow auto-pulls an image whenGetImagereturnsimages.ErrNotFound, callingCreateImage, waiting up to 5 seconds viaWaitForReady, then re-fetching before continuing; if the pull isn’t ready in time it returnsErrImageNotReadyadvising the caller to retry while the pull continues.Adds an integration test
TestCreateInstance_AutoPullImagethat creates an instance without pre-pullingalpine:latest(with KVM/system files prerequisites) to verify the end-to-end auto-pull path and cleanup.Written by Cursor Bugbot for commit eedfbc0. This will update automatically on new commits. Configure here.