fix(scheduler): keep memory charges near recent peaks after cold rebuilds #767
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #767"
general
weight: 0.35
jbellis
After cold rebuilds, the scheduler could charge a compile far more memory than it had ever used. On our build host, two WSL crashes left incremental caches cold. The scheduler then charged a link job whose recent peak was 17.3 GiB as using 39.3 GiB. Three such jobs held 78 of the 80 GiB budget, and 73 compiles waited on a mostly idle machine until the estimator history was cleared by hand. With this change, charges stay close to recent peaks after cold rebuilds, and waiting compiles pick up lower charges as soon as the history changes.
Cause
The estimator adds a margin learned from recent runs. It scored each run as
(ln peak - mean) / spread, where each key's spread is shrunk toward a pooled value of about 0.08. After the crashes, many crates peaked 1.3 to 1.5 times above their recent maximum. For a key with a spread of 0.05, that is a score near 7. The 95th percentile of those scores, 5.4, then multiplied every key's own spread, so keys with a wide spread were charged 2.3 times their recent peak.A waiting compile also kept the charge computed when it joined the queue. After the history was cleared, one 30.9 GiB charge still held 15 small jobs back for a minute.
Change
ln(peak / window maximum), using the window maximum frozen at admission. The charge iswindow maximum exp(q), never below the window maximum. As before,qis the 95th-percentile rank of the last 256 scores for compiles or links. These scores mean the same thing for every key, and cold rebuilds raise them only as far as the memory those builds actually use, about 1.5 times here.memory_log_ratios. The oldmemory_residualsfield is ignored, so an upgraded ledger calibrates from new data instead of mixing scales. Older mbx versions ignore the new field.gatedevent now records the charge used for that attempt. This can differ from the charge in theenqueuedevent.Results
We replayed 33,044 recorded runs from our build host, including the crash period, through both estimators. The replay used the observed timings, so it cannot show the queue stall itself.
| | Current | New |
|---|---|---|
| Highest compile margin during the crash | 5.44 spreads | 0.40, about 1.5 times the window maximum |
| Charge for the 17.3 GiB link job at the incident | 39.3 GiB | 23.1 GiB |
| Compile coverage, share of peaks at or below the charge | 95.7% | 95.1% |
| Link coverage | 92.2% | 92.1% |
| Over-charge during the crash period, compile / link | 7.9 / 11.7 GiB-hours | 6.9 / 9.4 GiB-hours |
| Over-charge over the whole range, compile / link | 129.0 / 110.9 GiB-hours | 132.3 / 113.6 GiB-hours |
The tradeoff: over the whole range, over-charge rises by about 2.5%, because one margin per kind costs more on keys with a narrow spread. In exchange, a burst of cold rebuilds can no longer multiply charges.
We also tried limiting each key to 4 of the 256 history entries. It raised link over-charge from 110.9 to 143.6 GiB-hours, because the link history then stretched from 33 to 380 minutes, and it did not change compile. It is not included.
This change has run on the same host, with an 80 GiB budget and 120 CPUs, since 2026-10-19T20:06Z. These are its first 2.4 hours, against the 4 hours before, which included the incident. The figures cover estimates from each key's own history:
| | Before | After |
|---|---|---|
| Coverage | 94.6% | 94.8% |
| Over-charge per hour | 10.5 GiB-hours | 6.1 GiB-hours |
| Median charge / peak | 1.16 | 1.08 |
| 90th percentile charge / peak | 1.77 | 1.52 |
After calibration,
exp(q)was 1.03 for compiles and 1.01 for links.Validation
New unit tests cover the score and charge, the short-history fallback, loading an old ledger, re-predicting a waiting charge, features frozen at admission, reusing a prediction until the ledger reloads, skipping the ledger for nextest and CPU-only admissions, the ledger cache's file-identity and age checks, and a re-predicted waiter that is then gated. An independent review checked budget safety, ledger compatibility in both directions, and races with queue scans.
AI-assisted — Tool: Claude Code via Mjolnir; model: anthropic/claude-opus-5-5, openai/gpt-6.1-sol.
🤖 Generated with Claude Code
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
Summary by CodeRabbit
Improvements
Memory estimates now adapt to recent successful runs, with a fallback estimate used until enough calibration data is available.
Waiting requests are re-evaluated when memory history changes, helping keep admission decisions current.
Recent scheduling data is reused briefly to improve consistency and responsiveness.
Gate status changes are now reported consistently, including when a request is already queued.
Scheduling statistics now provide clearer calibration and memory-measurement details.
Documentation
* Updated scheduling guidance to describe memory estimates and calibration.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->