app stays open script goes flakey

Well, I guess I’m being dense because I still don’t “get it”.
I just duplicated your script and saved it as a stay open app. When I run it
(double-click the script’s icon), it performs as expected. Then, once the
script is done, it’s still running but there is no way to interact further. Either
I’m overlooking something simple or there are more details to reveal.
You said “From the time I leave in the evening to the time I come in in the
morning, I can click yes”. I don’t understand how you do this when you
aren’t there. Do you do this (click yes) from a remote Mac?
Putting my density aside, it almost sounds like someone is playing
games with you and slipping another script in when you aren’t
looking.

: You said "From the time I leave in the evening to the time I come in in
: the morning, I can click yes". I don't understand how you do this
: when you aren't there. Do you do this (click yes) from a remote Mac?

It sounds like you have the Macs set to restart overnight at some point. Problem is, that dialog box will prevent the shut-down. Then when the person in the morning clicks “Yes” the computer finally can continue doing what it wants (shutdown).
Oops!
You’ll either want to have a time-out on that dialog box, or not have the Mac auto-restart (Energy Saver control panel)

Like Rob J, I am totally mystified. What is the point of saving it as “stay open” if it can only do its work - display the dlog - once? If it stays ‘running’ after the dlog is dismissed it just sits there doing zilch - why? I could understand more if you had a “rerun handler”:

on reopen
run
end reopen

but of course, not being a ‘newbie’ you already knew that. Actually I lie when I say I could understand more because I understand nothing. What is the point of keeping it open? What do you gain over it closing after it has performed its single (pretty simple) task? What also is the point of - as Krioni says - keeping a modal dialog on screen so that the computer can do nothing else - nothing! - absolutely nothing! - until it is dismissed.
I presume that a URL of “http://” is an abbreviation just for this posting - otherwise you really do have miracles happening - or expect them to happen.
All in all there must be more to this than you have said so far. My puzzlement is mainly because you say you are NOT a ‘newbie’. Quite a few of us here try to help when we can. Three of us have now responded to you, but we need more information. Come on - what is this really all about?