launchd Caveats: StartCalendarInterval and Sleeping

After a couple hours of testing, and searching on Google I’ve come to the realization (and subsequent confirmation) that the reason my launchd periodic task doesn’t always run on time (but sometimes hours late) is that the process is tied to a timer and not a specific time of the day like you specify in the plist.

So if your computer is asleep for 3 hours, the process will run 3 hours later unless you restart your computer which will fix the timer issue, until the next time you sleep.

I really hope this is fixed in Leopard, and have subsequently filed a bug report. (Radar 5091911 - link will only work for Apple employees)

So in summary, don’t depend on StartCalendarInterval to run your launchd process at the time you’ve said unless you know the computer has restarted since the last time it was put to sleep.

Note: This was fixed in Leopard. Unsure if it was fixed in 10.4.11 as I don’t use Tiger anymore.