Revisiting this.
To avoid issues like this, what if the script could return false when Opus calls it for an item? If it does, Opus will call the script again. You could use that to build a list of items on the first call, return false, and then on the second call process all related items in bulk.