How to know if a Note ID is still valid

Probably not, at least not directly.

There are functions like waitForRelease and isNoteHeld which can help you find out if note has received a note off message. But if the envelope is set to oneshot mode then it’s possible the voice will be released (stop playing) even if the note is still held. There are couple of functions that deal with used voices. So you could keep track of the number of used voices and update the value with each new note on and note off. You could also read the values of amp envelope and work out the total time you need to wait since note on and then check for used voices. However this can get complicated if you use quick controls to offset envelope times.