DEV Community

Cover image for Why Adding Queue Length Made My Bayesian Cluster Scheduler Worse
Ayush Agarwal
Ayush Agarwal

Posted on Originally published at theayush.pages.dev

Why Adding Queue Length Made My Bayesian Cluster Scheduler Worse

When I started writing AegisFlow, a zero-dependency Python scheduler for clusters with silent node failures, my first instinct was obvious: use queue depth (queue_len) as distress evidence alongside latency and error rate.

It made inference worse. When I actually inspected env/cluster_env.py, queue_len did not depend on node health or sensor noise at all. It was literally echoing my own scheduler's past dispatches back to me. Feeding a deterministic echo of my own decisions into a Bayesian filter created circular confirmation bias.

Dropping queue_len completely and pulling real signal out of telemetry was where the numbers clicked.

Inferring node health without heuristics

Each node transitions latently between Healthy, Degraded, and Down. Instead of brittle z-score thresholds, agent.py runs an Exact 3-State Bayesian Hidden Markov Model forward filter over heartbeat_ok, latency_ms, error_rate, and per-task duration_remaining progress deltas. Across paired 400-step benchmarks, that reaches 99.58% hidden state accuracy, catching degradation in 0.13 steps and crashes in 0.35 steps with 0.000% false condemnations.

Two math barriers that stopped cascading misses and thrashing

  1. Analytical Triage Gating: Leaving a doomed task pending costs -0.01/step, whereas missing its deadline on a live node slot costs -1.00. Computing completion probability before dispatch keeps uncompletable jobs out of healthy slots, cutting deadline misses by 87% (98.2 -> 13.2, raising on-time completion to 98.3%). Removing triage alone swings ablation reward by +714 points.
  2. Cold-Restart Expected-Value Barrier: In stateful jobs, reassigning a running task resets duration_remaining back to duration_total. Caching duration_total on first sight and requiring target survival gain to strictly beat the lost-progress penalty dropped unnecessary migrations to 0.00 (zero churn), paired with a recovery probation ramp so recovering nodes do not get stampeded immediately.

Written in pure Python stdlib, agent.py runs at 0.64 ms/step (39x under the 25.0 ms budget), passes 31/31 deterministic invariant checks (test_invariants.py), and reaches 96% of the theoretical Oracle ceiling (745.00 vs 750.94).

Benchmark logs and ablation breakdown: https://theayush.pages.dev/projects/aegisflow

Source code: https://github.com/theayushagarwal/AegisFlow

Top comments (0)