Skip to content

Prevent stale Created state after restore - #387

Merged
sjmiller609 merged 1 commit into
mainfrom
hypeship/coalesce-restore-wake
Aug 10, 2026
Merged

Prevent stale Created state after restore#387
sjmiller609 merged 1 commit into
mainfrom
hypeship/coalesce-restore-wake

Conversation

@sjmiller609

@sjmiller609 sjmiller609 commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • publish the running hypervisor state after a successful restore resume
  • prevent concurrent restore callers from observing a stale cached Created state and receiving a 409
  • add a regression test covering two concurrent restores with a transitional state query

Tests

  • go test -race ./lib/instances -run '^(TestConcurrentRestoreClearsTransitionalHypervisorStateCache|TestLifecycleNoopTransitionsReturnCurrentInstanceWithoutEvent)$' -count=1
  • go vet ./lib/instances
  • go test ./lib/instances -count=1 (integration tests requiring mkfs.erofs and 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, restoreInstance now writes hypervisor.StateRunning into the hypervisor state cache immediately after metadata is saved and before building the API response. That clears a transitional Created value that can be left when a state query hits the VMM during RestoreVM (before resume finishes), which could otherwise make a overlapping restore see the wrong cached state and fail with a conflict.

A new regression test TestConcurrentRestoreClearsTransitionalHypervisorStateCache runs two concurrent RestoreInstance calls while the fake starter pins Created in 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.

@sjmiller609
sjmiller609 marked this pull request as ready for review August 10, 2026 21:14
@sjmiller609
sjmiller609 requested a review from yummybomb August 10, 2026 21:16

@yummybomb yummybomb left a comment

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.

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.

@sjmiller609
sjmiller609 merged commit eed540f into main Aug 10, 2026
9 checks passed
@sjmiller609
sjmiller609 deleted the hypeship/coalesce-restore-wake branch August 10, 2026 21:56
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