Machine Learning
Predicting goroutine scheduling in Go proves harder than training AI models can handle
A new study shows that machine learning struggles to forecast concurrent event sequences in Go programs, even when trained on thousands of examples.
Researchers have tackled a thorny problem in concurrent programming: predicting which scheduler event will occur next in a Go program. Their findings suggest the challenge is more complex than standard machine learning approaches can easily solve.
The Core Problem#
The challenge stems from the nature of concurrent execution itself. When a Go program runs the same sequence of events multiple times, the scheduler may choose different next steps each time — and all of those choices are equally valid. This inherent nondeterminism makes traditional single-label prediction inadequate. Instead of treating the problem as "guess the one right answer," the researchers reframed it as estimating a distribution of probable next events based on what happens across multiple runs.
Data and Methods#
The team assembled a dataset of 945 training examples drawn from both hand-written code and algorithmically generated programs. They evaluated their models against 798 held-out predictions taken from 54 real-world bugs found in production systems like CockroachDB, Kubernetes, gRPC, and etcd — cases where scheduler behavior matters for correctness.
They fine-tuned Qwen2.5-Coder-7B using low-rank adapters, testing two training objectives:
- Cross-entropy loss — the conventional approach
- KL divergence to empirical distribution — tailored to match observed event distributions
Disappointing Results#
The findings were sobering. The fine-tuned models achieved only 36–37% accuracy on predicting the most likely next event, while a trivial baseline — simply always guessing the most common event in the training data — reached 35.5%. Even a simple n-gram model of event sequences matched the adapted models at 33–34% accuracy.
The theoretical upper bound for any deterministic predictor was just 58.9% top-1 accuracy, since each evaluation case contained labels from only about five runs. That noise floor matters: a sensitivity study with 100 runs per program revealed that five-run datasets had substantial variance (mean total-variation distance of 0.24 from more stable benchmarks), likely constraining what any learning objective could extract.
Structural Insights#
The model struggled most with rare events — those that occur infrequently are almost never predicted. Interestingly, one pattern did emerge reliably not from learning but from reasoning about Go's concurrency model: a scheduler behavior associated with goroutine leaks fell out naturally from analyzing how the scheduler itself works.