Skip to content

fix(clone): replace removed --on-demand with --restore-mode#36

Merged
CMGS merged 1 commit into
mainfrom
fix/restore-mode
Jul 16, 2026
Merged

fix(clone): replace removed --on-demand with --restore-mode#36
CMGS merged 1 commit into
mainfrom
fix/restore-mode

Conversation

@CMGS

@CMGS CMGS commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Refs #34.

Problem

cocoon#127 removed --on-demand from vm clone in favor of --restore-mode copy|ondemand|mmap. vk-cocoon emitted --on-demand on every non-Windows Cloud Hypervisor clone path (normal, fork, from-dir, hibernation wake), so all of them fail at argv parse against current cocoon.

Change

  • CloneOptions.OnDemand boolRestoreMode enum (copy / ondemand / mmap), emitted as --restore-mode <mode> in the slot --on-demand occupied.
  • copy (and empty) emits no flag — cocoon omits memory_restore_mode for it, so the argv stays valid on cocoon builds predating the flag.
  • Firecracker never receives the flag (same negative guard as --nics); an empty backend keeps its existing treated-as-CH semantics.
  • Policy in one helper: Windows always copy (lazy restore stalls DHCP boot), everything else uses the node-wide mode.
  • Node-wide mode from VK_RESTORE_MODE, default ondemand — the same restore semantics shipped today, so the fix carries zero behavior delta. Invalid values abort startup.
  • mmap is opt-in only: it requires a Cloud Hypervisor build with mmap restore support (cocoonstack/cloud-hypervisor dev); on other CH builds clones fail. Documented in docs/configuration.md.

The hibernation-wake path needs no carve-out for ondemand/mmap: cocoon hardlinks the snapshot memory files into the VM run dir and CH restores from there, so the post-wake snapshot rm only unbinds the store name while the inode stays alive.

Evidence

  • git grep -- '--on-demand' -- '*.go' → zero matches; no OnDemand field remains.
  • Argv table tests cover copy/ondemand/mmap on CH, FC suppression (plain and from-dir), empty-backend-as-CH, and NIC combination; ParseRestoreMode has its own table.
  • make lint 0 issues on linux+darwin; go test -race ./... all packages ok; make build ok.
  • Pending (tracked in fix/perf: migrate clone restores to --restore-mode and use mmap for Linux fan-out #34): testbed e2e against current cocoon for all four clone paths, and the 1/8/16-way copy-vs-mmap fan-out comparison on an mmap-capable host.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates vk-cocoon’s clone argument generation to match cocoon’s newer vm clone interface by replacing the removed --on-demand flag with --restore-mode copy|ondemand|mmap, and wires a node-wide restore mode configuration through startup and provider clone paths.

Changes:

  • Replaced CloneOptions.OnDemand with a RestoreMode enum and added ParseRestoreMode validation.
  • Updated clone argv construction to emit --restore-mode <mode> for Cloud Hypervisor semantics while suppressing it for Firecracker (and emitting nothing for copy/empty to preserve compatibility with older cocoon builds).
  • Added VK_RESTORE_MODE configuration plumbing (default ondemand), Windows override-to-copy policy, updated unit tests, and documented the new env var.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
vm/runtime.go Introduces RestoreMode enum, parse/validation helper, and updates CloneOptions to use it.
vm/cocoon_cli.go Switches clone argv emission from --on-demand to conditional --restore-mode <mode>.
vm/cocoon_cli_test.go Updates clone argv table tests and adds ParseRestoreMode test coverage.
provider/cocoon/update.go Uses restore-mode policy helper for hibernation wake clone path.
provider/cocoon/update_test.go Replaces old on-demand policy test with restore-mode policy test.
provider/cocoon/provider.go Adds node-wide RestoreMode field and defaults it to ondemand.
provider/cocoon/create.go Applies restore-mode policy to all clone paths and defines restoreModeFor (Windows forced to copy).
provider/cocoon/create_test.go Updates expectations for clone options to check RestoreMode.
main.go Adds VK_RESTORE_MODE env var, validates via vm.ParseRestoreMode, and wires into provider.
docs/configuration.md Documents VK_RESTORE_MODE, including Windows/Firecracker behavior and mmap caveats.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

cocoon#127 removed the --on-demand flag in favor of
--restore-mode copy|ondemand|mmap, so every non-Windows CH clone
(normal, fork, from-dir, hibernation wake) fails at argv parse
against current cocoon.

CloneOptions.OnDemand becomes a RestoreMode enum. The node-wide
default comes from VK_RESTORE_MODE (invalid values abort startup)
and defaults to ondemand — the same restore semantics shipped
today, so the compatibility fix carries no behavior change.
Windows stays on copy (lazy restore stalls DHCP boot) and
firecracker never receives the flag. copy emits no flag at all,
keeping the argv valid on cocoon builds predating --restore-mode.
mmap is opt-in only: it needs a CH build with mmap restore
support and fails clones on any other build.
@CMGS
CMGS force-pushed the fix/restore-mode branch from 57e1c1e to d86671d Compare July 16, 2026 07:37
@CMGS
CMGS merged commit a3361dd into main Jul 16, 2026
2 checks passed
@CMGS
CMGS deleted the fix/restore-mode branch July 16, 2026 07:38
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