How to check that the VM agent is running?

Is there a way to check that the VM agent is running in an incus VM?

I want to wait until the agent is running before using the Incus API to configure the VM (e.g. call InstanceServer.ExecInstance). Otherwise, I get the error “VM agent isn’t currently running”.

As a workaround, I added a delay between creating the instance and trying to run something in it.

I am now thinking of polling the agent by trying to ExecInstance /bin/sh (with empty input). Is there a better way?

A recent query on this, Is here a way to determine is lxd-agent running?

Too early, and Processes are -1.

$ incus info debianvm
Name: debianvm
Status: RUNNING
Type: virtual-machine
Architecture: x86_64
PID: 44523
Created: 2024/01/29 02:15 GMT+1
Last Used: 2024/02/14 15:12 GMT+1

Resources:
  Processes: -1
...

Ok, that provides some information. Processes is accessible from InstanceServer.GetInstanceState. But still, the agent is not the first process started, so there may be processes but no agent yet. So I still need to poll the agent, by trying to perform an operation that uses it.

Processes is a value that’s fetched from the agent, it will be -1 until the agent is running.

Ok, great. I should have read the referenced topic, which explains it.