Skip to content

Quit anyway: don't wait for the abandoned work before shutting down - #162

Merged
A21-devs merged 4 commits into
mainfrom
fix/quit-anyway-no-wait
Dec 5, 2026
Merged

A21-devs merged 4 commits into
mainfrom
fix/quit-anyway-no-wait

Conversation

@A21-devs

@A21-devs A21-devs commented Dec 5, 2026

Copy link
Copy Markdown
Owner

Closes #155

After Quit anyway (or Quit now in the tray while waiting for the work), the work is left unfinished, but if the VM doing it was also running, Shut down VMs and quit still waited for that work before pressing the VM's power button. With a profile save going that can be minutes, and the app sat in the tray saying it was shutting down.

How:

  • workFirst now returns the set of VMs whose work was abandoned instead of true: everything still working when Quit anyway was clicked, or still working when Quit now was picked in the tray. Waiting until it finished gives an empty set.
  • That set goes through askAndQuit to shutDownAllAndQuit. For those VMs the power button is pressed right away, with no workDone and no wait for the guest agent after a save.
  • Work that starts on a VM after the work question, or work the user waited for, is handled as before. The power button in the middle of a hibernate is still avoided there (Toolbar: show a running profile save and disable what it would refuse #121).
  • The power button part (resume if paused, then shutdown) moved into pressPower so both paths use it.

For an abandoned profile save the power button can arrive while the guest hibernates and turn it into a plain shutdown. That's what Quit anyway already says ("no profile is made and the VM is not started again"), so I think it's the right trade.

Testing

  • 4 new tests in tests/quitFlow.test.ts: tray Quit then Quit anyway, window close with the quit close behavior, work starting on another VM after the question still being waited for, and tray Quit now. All four fail on main (two by timing out in the wait).
  • npm run typecheck, npm test (184 pass), npm run build
  • Hidden Electron smoke test with a temp data folder: SMOKE OK

Quit anyway says the work is left unfinished, but when a VM was also
running, Shut down VMs and quit still waited for that VM's work before
pressing its power button. A profile save can take minutes, so the quit
looked stuck with the window already in the tray.

The work question now returns which VMs' work was abandoned (Quit anyway,
or Quit now in the tray while waiting), and the shutdown presses the
power button on those right away. Work that starts after the question,
or that the user chose to wait for, is still waited for as before.
Covers the tray's Quit and the window's close with the quit close
behavior, and that work which starts on another VM after the question is
still waited for.
@A21-devs A21-devs added bug Something isn't working backend labels Dec 5, 2026

@A21-devs A21-devs left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

The direction is right and the tests cover the orderings in the issue. Two problems, the first one real enough to fix before merging.

Comment thread src/main/quitFlow.ts
// only makes the quit look stuck, and a hibernate the power button turns into a shutdown is fine
await Promise.all(
names.map(async (n) => {
if (abandoned.has(n)) return this.pressPower(n)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

The abandoned work keeps running in the main process; only the quit stops waiting for it. For a session profile save that matters: takeSession waits for the guest to power off and then calls runner.start(cfg) to boot it again. With the power button pressed mid-hibernate, the guest powers off (a plain shutdown reads as 'guest' too, see #120), waitForExit here returns true, and at about the same time the save snapshots the disk and starts the VM again. Then host.quit() runs and before-quit calls killAll(), so a guest that is just booting gets a hard power off. Before this PR the quit waited for the save, so that couldn't happen.

The save shouldn't be able to start the VM again once the quit has given up on it. Something like a per-VM hold on start that the quit sets for the abandoned VMs (and lifts if the user cancels the Force off question) would do it.

Comment thread src/main/quitFlow.ts Outdated
noLink: true
})
if (choice === NOW) return true
if (choice === NOW) return this.workingNames()

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

workingNames() reads the work at the moment of the click, not the work the question listed. If another VM starts a profile save or disk work while the question is open, it gets counted as abandoned even though the message never named it. Using the VMs from work (the list the question showed) keeps the answer to what the user was asked about.

A session profile save boots the guest again once it has hibernated. If
the app is quitting and no longer waits for that save, the boot only
leads to a hard power off from killAll a moment later. holdStarts makes
start() refuse that VM until it is let go.
…d about

Quit anyway and Quit now hold starts for the VMs whose work is left
unfinished, and let go of them if the quit doesn't happen after all
(Cancel, keeping the VMs in the tray, or Cancel in the Force off
question).

Quit anyway now only counts the VMs the question named. Work that starts
on another VM while the question is open is still waited for.
@A21-devs

A21-devs commented Dec 5, 2026

Copy link
Copy Markdown
Owner Author

Both findings were right.

  • Restarted save: a2bfdb7 adds VmRunner.holdStarts(name, hold), and start() refuses a held VM with "was not started again because the app is quitting". 406d27b holds starts for every abandoned VM (Quit anyway, and Quit now in the tray) and lets go of them on every path where the app ends up staying: Cancel or Keep them running in the tray in the running VMs question, and Cancel in the Force off question. The save itself still finishes its snapshot, it just fails at the boot, so the profile is kept.
  • Quit anyway now counts only the VMs the question listed. A test has kali start deleting a profile while the question is open and checks its power button still waits for that.

Checked with: 5 more quitFlow tests (hold set, released on the three stay paths, only the named VMs), a new tests/holdStarts.test.ts for the runner, npm run typecheck, npm test (192 pass), npm run test:qemu (209 pass), npm run build and the hidden smoke test (SMOKE OK).

@A21-devs A21-devs left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Went through the two follow-up commits against the first review.

  • Restarted save: fixed. abandon() holds starts for the abandoned VMs, start() checks the hold before anything else, and every path that ends with the app staying lets go (lines 141, 151 and 297). The no-VMs-running path quits with the hold still set, which is fine since nothing is left to start.
  • Only the listed work: fixed, abandon(new Set(work.map(([n]) => n))) uses the question's own list, and the kali test covers it.

One note below, not something to fix here.

Comment thread src/main/quitFlow.ts
})
)
if (!(await this.waitForShutdown(names))) return
if (!(await this.waitForShutdown(names))) return this.release(abandoned)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Letting go here is right, but by the time the Force off question gets its Cancel (at least a minute in), the abandoned save has usually already reached its start() and failed on the hold. So after Cancel the VM stays off and the save reports an error, even though the app didn't quit. That is the same "Cancel after the guests were already told to shut down" situation as #158, so it fits better there than in this PR.

@A21-devs
A21-devs merged commit 75d18bd into main Dec 5, 2026
1 check passed
@A21-devs
A21-devs deleted the fix/quit-anyway-no-wait branch December 5, 2026 20:05
@A21-devs A21-devs mentioned this pull request Dec 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Quit anyway still waits for the work before the power button

1 participant