Prevent stale Created state after restore - #387
Merged
Conversation
sjmiller609
marked this pull request as ready for review
August 10, 2026 21:14
yummybomb
approved these changes
Aug 10, 2026
yummybomb
left a comment
Contributor
There was a problem hiding this comment.
Looks good!
publishing Running before deriving the response correctly prevents the stale cache value from propagating into the lifecycle event and subsequent restore call. the focused concurrency test covers the regression well.
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
Createdstate and receiving a 409Tests
go test -race ./lib/instances -run '^(TestConcurrentRestoreClearsTransitionalHypervisorStateCache|TestLifecycleNoopTransitionsReturnCurrentInstanceWithoutEvent)$' -count=1go vet ./lib/instancesgo test ./lib/instances -count=1(integration tests requiringmkfs.erofsand completed local image builds could not run in this environment)Note
Low Risk
Small, targeted ordering fix on the restore success path plus a unit test; no auth or data-model changes.
Overview
After a successful standby restore,
restoreInstancenow writeshypervisor.StateRunninginto the hypervisor state cache immediately after metadata is saved and before building the API response. That clears a transitionalCreatedvalue that can be left when a state query hits the VMM duringRestoreVM(before resume finishes), which could otherwise make a overlapping restore see the wrong cached state and fail with a conflict.A new regression test
TestConcurrentRestoreClearsTransitionalHypervisorStateCacheruns two concurrentRestoreInstancecalls while the fake starter pinsCreatedin the cache mid-restore; both completes succeed and only one restore runs.Reviewed by Cursor Bugbot for commit cc9f608. Bugbot is set up for automated code reviews on this repo. Configure here.