Skip to content

Commit 5521643

Browse files
mauromoralesclaude
andcommitted
Address Copilot review: explicit flags take priority, guard invalid values
- Use fs.Visit to detect whether -memory/-cpus were explicitly passed; only seed from disk's saved values when the user did not provide them, so an explicit flag always wins over the persisted default - Guard persisted values with > 0 checks to prevent saving invalid flag values (e.g. -memory 0) that bypass interactive review with --yes Signed-off-by: Mauro Morales <mauro@example.com> Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent e3043cc commit 5521643

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

internal/app/app.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -397,13 +397,16 @@ func runStart(args []string, stdin io.Reader, stdout, stderr io.Writer, store *s
397397
}
398398
}
399399

400-
// For existing disks, prefer the saved memory/CPU settings over the flag
401-
// defaults so that the user's previous choices persist across restarts.
400+
// For existing disks, seed memory/CPU from the disk's saved settings so
401+
// that the user's previous choices persist across restarts — but only when
402+
// the user did not explicitly pass -memory/-cpus on this invocation.
402403
if !isNewDisk {
403-
if disk.MemoryGB > 0 {
404+
explicitFlags := map[string]bool{}
405+
fs.Visit(func(f *flag.Flag) { explicitFlags[f.Name] = true })
406+
if disk.MemoryGB > 0 && !explicitFlags["memory"] {
404407
*memory = disk.MemoryGB
405408
}
406-
if disk.CPUs > 0 {
409+
if disk.CPUs > 0 && !explicitFlags["cpus"] {
407410
*cpus = disk.CPUs
408411
}
409412
}
@@ -570,10 +573,16 @@ func runStart(args []string, stdin io.Reader, stdout, stderr io.Writer, store *s
570573

571574
writeLine(stdout, "[2/3] Recording VM state")
572575
// Persist the chosen memory and CPU settings on the disk so they become
573-
// the default next time this disk is started.
576+
// the default next time this disk is started. Guard against zero/negative
577+
// values that could arrive via explicit flags (e.g. -memory 0) without
578+
// going through the interactive reviewer.
574579
if stateDisk := state.FindDiskByName(st, disk.Name); stateDisk != nil {
575-
stateDisk.MemoryGB = vmConfig.MemoryGB
576-
stateDisk.CPUs = vmConfig.CPUs
580+
if vmConfig.MemoryGB > 0 {
581+
stateDisk.MemoryGB = vmConfig.MemoryGB
582+
}
583+
if vmConfig.CPUs > 0 {
584+
stateDisk.CPUs = vmConfig.CPUs
585+
}
577586
}
578587
st.Network.Mode = *network
579588
st.Network.BridgeInterface = networkIface

0 commit comments

Comments
 (0)