While testing, I noticed that the collectoss github api-keys CLI would show all configured API keys as fully reset, but collection would still be sleeping (as calculated based on the timestamps and sleep times printed in the logs.
Im still not 100% certain of the cause, but my best theory so far (found with the help of sonnet 4.6 via cursor) is this:
CollectOSS uses two different types of waiting as it relates to API keys. Keyman itself stores the reset time for the key as a unix timestamp so that, the next time a request comes in, all expired keys get re-evaluated and added back to the valid pool when those times have elapsed. This essentially uses real/wall clock time.
The keyman clients, on the other hand, will wait using time.sleep(), which relies on monotonic time (essentially a counter).
According to Sonnet, on linux devices, the monotonic clock does not advance when the machine (such as a laptop) is asleep.
This means a key could be 15 minutes away from getting reset, but if the laptop goes to sleep and wakes up 30 minutes later, the collection process that was waiting still has to wait for the final 15 minutes of that time.sleep() to finish.
The part of the problem I cant explain is that this resetting behavior seems like it might persist from iteration to iteration, meaning a laptop going to sleep could mean affected collection tasks are now permanently "behind" the actual key reset time by some amount of time thats based on how long/when the laptop sleep happened and when in the key reset cycle it was.
The impact of this is low, but I think it may still be important to fix eventually, especially for the development experience or people running instances on laptops.
While testing, I noticed that the
collectoss github api-keysCLI would show all configured API keys as fully reset, but collection would still be sleeping (as calculated based on the timestamps and sleep times printed in the logs.Im still not 100% certain of the cause, but my best theory so far (found with the help of sonnet 4.6 via cursor) is this:
CollectOSS uses two different types of waiting as it relates to API keys. Keyman itself stores the reset time for the key as a unix timestamp so that, the next time a request comes in, all expired keys get re-evaluated and added back to the valid pool when those times have elapsed. This essentially uses real/wall clock time.
The keyman clients, on the other hand, will wait using
time.sleep(), which relies on monotonic time (essentially a counter).According to Sonnet, on linux devices, the monotonic clock does not advance when the machine (such as a laptop) is asleep.
This means a key could be 15 minutes away from getting reset, but if the laptop goes to sleep and wakes up 30 minutes later, the collection process that was waiting still has to wait for the final 15 minutes of that
time.sleep()to finish.The part of the problem I cant explain is that this resetting behavior seems like it might persist from iteration to iteration, meaning a laptop going to sleep could mean affected collection tasks are now permanently "behind" the actual key reset time by some amount of time thats based on how long/when the laptop sleep happened and when in the key reset cycle it was.
The impact of this is low, but I think it may still be important to fix eventually, especially for the development experience or people running instances on laptops.