Skip to content

< all problems96 · Level 08, Production

Fix the Health Check That Kills Workers While They Warm Up

medium · debug · Production

Agent workers load a twelve-second cache when they start. The health check restarts any worker that is not serving, so a worker that is loading gets restarted at tick 10, starts loading again, and the cluster never comes up. Meanwhile a worker whose model call has hung is still being sent traffic. Fix alive, ready, patrol and route.

A Worker records last_progress (the last tick it loaded, took or finished anything), cache_loaded, inflight, draining and restarts. LIVENESS_TIMEOUT and CAPACITY are provided.

  1. alive(worker, now) is False only when now - worker.last_progress > LIVENESS_TIMEOUT. Loading the cache is progress. A worker is dead when it stops moving, not when it is not ready.
  2. ready(worker, now) is True when the worker is alive, its cache is loaded, it is not draining, and inflight < CAPACITY.
  3. patrol(workers, now) restarts every worker that is not alive, with worker.restart(now), and returns their indices. It never restarts a worker for being unready.
  4. route(workers, now) returns the index of the ready worker with the fewest in-flight tasks, the lowest index on a tie, or None when nobody is ready.

Kubernetes calls these two checks the liveness probe and the readiness probe, and the bug here is the one everybody ships once: a single check wired to both.