Finally, I tracked it to the line
select @replica_id = replicas.replica_id from master.sys.availability_replicas as replicas where upper(replicas.replica_server_name COLLATE Latin1_General_CI_AS) = upper(@@SERVERNAME COLLATE Latin1_General_CI_AS) and group_id = @group_id
It turns out, that @@ServerName was returning a value that I had never heard of. It certainly wasn't my Sql Server name! But... it WAS the name of the cloned machine before it had been sysprepped and handed to me! It seems that @@ServerName uses a stored version of the servername.
If you want the current running name, use: