Doing nothing when idle: zero wakeups for a resident process
Our resident tray daemon obitd was burning 0.37 CPU cores while seemingly idle—then 0.02 cores seconds later. Profiling with pprof exposed an unexpected culprit: Explorer date-label syncing walking node_modules on every sweep. Here is how we rebuilt obitd around pure event-driven wakeups, cutting burst CPU per commit from 2.9 s to 0.15 s.
Real test output: zero extra wakeups when idle, and 1,000 back-to-back external ledger commits coalesced into 2 daemon cycles.On this page
Obituary's resident tray daemon (obitd) exists to wait: wait for new files in watched folders, and wait for the next lifespan timer to expire. When nothing is changing on disk, its CPU usage should stay near zero.
During a routine check on the evening of 14 November, telemetry reported something jarring: obitd was consuming roughly 0.37 CPU cores while apparently idle. Measuring again seconds later dropped to 0.02 cores.
A 20× swing means an idle check will never catch the bug
A twenty-fold swing pointed away from steady background polling and toward a load-triggered storm. Watching Task Manager on a quiet desktop would never reproduce it.
We set a three-step investigation plan:
Reproduce reliably: measure obitd alongside a mature resident file-search daemon while creating and deleting 10,000 files in bulk.
Profile with pprof instead of guessing: capture real CPU samples to see whether tray refreshes, periodic sweeps, watch scope, or per-event full scans owned the spike.
Fix the root cause, never throttle polling as camouflage: re-run the exact same benchmark before and after.
Reading the code, we first suspected a 1-second tray polling loop. The pprof profile showed tray polling was noise; the real flame tower sat somewhere nobody had guessed:
Windows File Explorer burial-label synchronization was walking the entire directory tree—including massive node_modules folders—looking for .git inside every tracked directory on every single periodic check.
Had we merely slowed down tray polling based on intuition, CPU would have kept spiking under real work. Fixing the root cause decoupled forced Explorer label syncs from recursive repository walks completely.
Pure event-driven wakeups: three triggers, one timer
With the main bottleneck gone, we rebuilt the daemon's wakeup architecture so it sleeps until work actually arrives:
File changes inside the data or config directory.
The next scheduled expiry timer.
One 5-minute full reconciliation pass—the sole periodic timer in the entire daemon.
Five supporting safeguards eliminated wakeup loops:
Event coalescing: bursts of filesystem events wait for 300 ms of quiet (capped at 2 s max delay) before running one pass.
Self-commit suppression: obitd tracks ledger mtime so its own commits never wake itself back up.
Unchanged graveyard snapshot hashes skip re-reads; deferred observation events settle without full sweeps.
The tray watches config.toml directly instead of polling on a timer.
Folder-policy watchers settle after write bursts subside and stop rescanning on ledger commits.
Locking "zero idle wakeups" into regression tests
We wrote the invariant straight into our contributor rules: every new wakeup source requires a zero-wakeup test. Two regression tests guard both extremes:
Zero self-wakeup: the daemon buries one expired file (its own commit), logs and audit writes land in the data directory, and across two full max-coalescing windows the daemon must stay at exactly one processed cycle.
Burst coalescing: an external process fires 1,000 back-to-back ledger commits; the test caps daemon processing at 3 cycles maximum—in practice it runs just 2.
Real test output: zero extra wakeups when idle, and 1,000 back-to-back external ledger commits coalesced into 2 daemon cycles.