macOS: pre-established stop mechanism when a VM supervisor stops progressing

I am evaluating a bounded workload host using Virtualization.framework on Apple silicon. This is a question about supported architecture and API contracts, not a report of a reproduced bug. No particular macOS release has yet been qualified for this design; please identify the releases and prerequisites to which an answer applies.

I have read the discussions about cleanup after the VM-owning application terminates:
https://developer.apple.com/forums/thread/848542
https://developer.apple.com/forums/thread/850709

I understand that this cleanup is different from an externally observable, time-bounded teardown guarantee. I am not asking again for a replacement application's handle to a VM whose owner has already died.

The unresolved case is different:

  • A host application owns a VM, but its serial VM-control queue is no longer progressing.
  • A separate supervisor is intended to initiate the fallback stop action against that application.
  • An external stop trigger occurs. The supervisor is then lost or stops progressing before it enters the signal operation; the VM-owning application remains alive.
  • Loss of the supervisor role does not necessarily mean that its process has exited, so a process-exit notification cannot be assumed.
  • Complete host or kernel failure is not part of this scenario.

Is there a supported public mechanism that can be established before workload preparation and retain authority to act on the same target application after this loss, without requiring another action by the supervisor or progress on the VM-control queue?

For any such mechanism, I would particularly appreciate clarification of:

  1. How its authority is bound to the intended target during incomplete setup, including process creation that has begun but has not returned a usable target identity. Assuming an already-running watchdog leaves this setup boundary unanswered.
  2. Which actor performs the remaining action when the supervisor cannot, and what lifecycle, privilege and progress assumptions that actor requires.
  3. Whether any documented progress bound applies when a required operation does not return. The design requirement is completion of the whole prescribed stop/escalation attempt, including required failure-handling steps, within 10 seconds of the same first external trigger. Starting a timer or entering a signal call is not equivalent to completing that attempt. This is not a request for unconditional successful process or VM termination.

A supported narrower mechanism, or an explicit statement that macOS provides no such contract for this case, would also be useful. I am looking for public interfaces and their documented limits, not private helper-process identities or kernel implementation details.

Thank you.

Answered by DTS Engineer in 917100022

So, your concern is:

  1. You have a host process running a VM.
  2. That process has become unresponsive.
  3. You have a supervisor process monitoring the host process.
  4. That process has become unresponsive.

Right?

If so, I can’t see how this question is any different from the threads that you mentioned in your original post:

  • If the host process quits, the system will clean up any VMs it owns.
  • There’s no documented bound on how long that’ll take.
  • There’s no way to get a handle to a VM in order to clean it up from outside.

If the supervisor process is stuck, and thus it can’t terminate the host process, then there’s really not much you can do about that. I mean, I guess you could create a meta supervisor process that monitors the supervisor process, but that doesn’t strike me as a great plan. It just pushes the problem up a level, in that now you have to worry about the meta supervisor getting stuck. At that point it’s turtles all the way down.

Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Accepted Answer

So I was reading your problem spec and it kinda made sense until you got to this point:

Written by FELIX1988 in 857405021

retain authority to act on the same target application after this loss

What does “target application” mean in this context? You’ve carefully defined all your other terms, but then introduced this one without explanation )-:

Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thank you, Quinn. By “target application” I mean the macOS host process that owns the VZVirtualMachine instance. It is distinct from the separate supervisor process. I do not mean a process inside the guest or an internal Apple virtualization helper.

In this scenario, the VM-owning host process remains alive, but its serial VM-control queue has stopped progressing. The separate supervisor then also stops progressing before initiating the fallback action against that host process.

So the intended target is that same VM-owning host-process instance. My question is whether a mechanism established beforehand can still act on it without further progress by either the supervisor or the VM-control queue.

So, your concern is:

  1. You have a host process running a VM.
  2. That process has become unresponsive.
  3. You have a supervisor process monitoring the host process.
  4. That process has become unresponsive.

Right?

If so, I can’t see how this question is any different from the threads that you mentioned in your original post:

  • If the host process quits, the system will clean up any VMs it owns.
  • There’s no documented bound on how long that’ll take.
  • There’s no way to get a handle to a VM in order to clean it up from outside.

If the supervisor process is stuck, and thus it can’t terminate the host process, then there’s really not much you can do about that. I mean, I guess you could create a meta supervisor process that monitors the supervisor process, but that doesn’t strike me as a great plan. It just pushes the problem up a level, in that now you have to worry about the meta supervisor getting stuck. At that point it’s turtles all the way down.

Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I understand the limitation of adding another supervisor, and I am not asking for bounded VM teardown.

For our design decision, should we treat the following requirement as outside the documented public macOS contracts: a mechanism armed before workload preparation that can initiate the fallback independently when both the VM-control queue and the supervisor stop progressing, while their processes remain alive?

The 10-second requirement concerns completion of the prescribed stop/escalation attempt, not guaranteed successful VM termination.

If no documented public mechanism covers this scenario, that clarification is sufficient. If a narrower mechanism exists under explicit assumptions, could you identify it?

I’m sorry but I don’t understand what you’re actually asking here.

Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Sorry. I didn’t explain the use case clearly. I’m building a tool that runs one job at a time in a VM on an Apple silicon Mac. A launcher prepares a directory for the job and starts a helper process. That helper owns the VM. If the job is cancelled, I must not reuse its files while something from that run may still be writing to them.

My question is: can I arrange for macOS itself to stop the helper for that particular run if my launcher gets stuck, or does my design have to assume that another process remains responsive to do it?

Here’s the case I need to cover. The launcher starts creating the helper, but the launch call never returns a PID. The helper may already be alive. A cancellation request then arrives from outside the launcher. The launcher can’t act on it, and the helper’s VM queue isn’t progressing either. The Mac and kernel are otherwise running. I’m not asking another app to take over the VM.

I need to decide two things before allowing a job to start:

  1. Can protection be set up before creating the job directory or launching the helper? If there is a public API or system service for this, how would it receive the cancellation and identify the right helper and any child processes from that run, even if the launch call never returns?
  2. What timing, if any, is documented? Our requirement is to finish the stop attempt, including any required fallback if the first stop operation fails or hangs, within 10 seconds of the original cancellation. That is our requirement, not a deadline we assume macOS promises. We are not asking for a guarantee that the VM has finished shutting down or that its files are safe to reuse within those 10 seconds.
    If there’s a supported mechanism that covers only part of this, its name, applicable macOS versions and limits would help. If the design must instead assume a responsive external controller and has no documented 10-second bound, that’s useful too: it tells me not to start jobs that require that guarantee.

Thank you!

Written by FELIX1988 in 917770022

can I arrange for macOS itself to stop the helper for that particular run if my launcher gets stuck … ?

No.

Apple platform do have various watchdog concepts but there’s no API that let an app opt in to them.

Written by FELIX1988 in 917770022

The launcher starts creating the helper, but the launch call never returns a PID.

How is the launcher starting the helper?

If the launcher starts the helper by spawning a child process then the spawn itself returns the pid, and thus this situation never arises. However, there are circumstances where starting a child process isn’t appropriate (NSWorkspace, XPC service, and maybe more) and at that point things get more complex.

Written by FELIX1988 in 917770022

2- What timing, if any, is documented?

None. I covered that in the second of the two threads that you referenced at the start of this thread. I recommend that you go back and re-read them.

Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thanks, Quinn. The launcher design we reviewed creates a child directly with fork(), then calls execvp() in the child. It does not use NSWorkspace or XPC. We have not adopted that design or observed a launch hang.

On success, the parent gets the child’s PID from fork(), as you pointed out. My earlier wording was unclear: we were asking about the interval before the parent has returned from fork(), not about a successful launch that somehow returned no PID.

Your answer settles the platform question for us: we cannot rely on an opt-in macOS watchdog to stop that helper for a particular run, or on a documented cleanup deadline. Thank you for clarifying.