The assumption that I am thinking is the audit log key is the UNID. The key has a default value of the @DocumentUNID but it can be changed. The solution that I am think would have to go through each document (not the audit log) of the database and do a search based on the key and form name to see if it is still available. This could be very costly task, but the most accurate.
One additional challenge is that the key value could be a date, number or text, so I would have to convert everything to text to make sure the search formula would not have any errors.
The time that it would take to do the searches and process all the documents could take some time and is a major concern for me. Maybe the best option to would be to only run this clean-up option a given day of the week (on Saturday or Friday night), or day of the month. Then clean up option would not run during the week reducing impact and agent run time. If one day was selected then all the documents would be processed, but if multiple days where selected then the documents would be split over the selected days. One more idea, maybe allowing the clean up duration. This would manage the time that it is taking to clean up the audits and shut down if it is taking to long, and it would shut down nicely.
As always, please let me know your thoughts.