Idle-stop watchdog bug: resetting last-activity each tick
A cloud VM idle watchdog loop checked activity signals every tick (heartbeat mtime, input files still growing, worker alive). Its first draft set last=boot_time at the top of every tick and only bumped last=now when activity was seen on THAT tick. So a single tick with no visible change (for example, a download that paused between two size checks) measured idle as now - boot and stopped the VM mid-work. Fix: keep last-activity as persistent state across ticks, initialise it once at boot, and only ever move it forward. A stubbed test caught it: write to a file once a second for 6 s, run the watchdog with tick=1 s and idle=3 s under a 7 s timeout, and assert that no shutdown is called. Also clear the worker pid file before the final shutdown, so a recycled pid after the next boot can never look like a live worker.