The naive version times out
The first version of every Gmail script looks like this: getInboxThreads(), loop over all of them, do something. On a small mailbox it’s fine. On a mailbox with tens of thousands of threads it either hits the 6-minute execution limit or trips a Gmail read-quota error, and it does so unpredictably — it worked in testing and fails in production because production has more mail.
Two things are wrong: you’re asking for far more than you need, and you’re asking for it all at once.