How/when does COMMAND_ACK work?

Hello,
I am sending mav_cmd messages, like do_set_mode and nav_takeoff, while in guided mode over radio with a script.

I am noticing sometimes the commands doesn’t go through and decided to check the command_ack message.

To test I did a simple routine, change mode to guided, send the takeoff command and check the output of command_ack.

When the command works, the output shows the id of the command and that it was accepted and executed. When it doesn’t work, the output shows the id of the previous command, in this case, mav_cmd_do_set_mode.

So, if I am not mistaken, there are two possibilities : either the command is not being sent or it arrives and it is not being acknowledged.

Can someone confirm if my reasonsing is correct? Also, in case of being correct, is there other message to help debug this?

Did you check out Command Protocol · MAVLink Developer Guide ?
I would suggest you, instead of waiting vehicle to emit COMMAND_ACK, check corresponding data fields on other messages.
For example, if you really want to change the mode, then send do set mode and check the vehicle’s mode from custom_mode in HEARTBEAT message.
For whether vehicle is armed or not, check it out from base_mode in HEARTBEAT.
You can also check whether the vehicle is taking of or not with vehicle’s relative altitude and periodically send take off command. This state can also be observed with EXTENDED_SYS_STATE message but AFAIK you must first need to request it as a stream.