libvirt doesn't provide an option of domain undefine for user to remove the managed state file, and thus if the user undefine a domain which has an managed state file left, and defines a new domain with the same name later, it will fail when starting, as it sees the domain managed file with same name as domain exists, and it will try to restore from the managed state file. This is complete wrong.
Domain starting will fail if there is a managed state file which was of a previous domain with the same domain name.
New API virDomainUndefineFlags was introduced with flags
support, the user can specify the flag (e.g. virsh undefine --managed-save), the managed state file will be removed when undefine. If the managed state file exists, but no flag specified to tell libvirt to remove it, libvirt will refuse undefining the domain with sensiable error.
There is option provided for user to choose to avoid the problem. Also if managed state file exists, but no option specified to tell libvirt to remove it, there will be an sensiable error, which will be enough to let the user known what he needs to do.