feat(scheduler): log admission decisions and cancelled waits #760
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 #760"
general
weight: 0.35
jbellis
When a build waits a long time for a scheduler permit, mbx currently leaves no record of why. The observation log shows how long a job waited and what it was charged, but not what happened while it waited. It does not record which requests started ahead of it, or which rule let them do so. It also does not record whether a memory or pressure gate removed it from the queue, or whether a dead waiter's queue entry was cleaned up. This PR adds that record.
With
eventsenabled (the existing setting that gates the observation log), mbx now appends one JSON line per admission transition to<cache_dir>/scheduler/decisions.jsonl. Like the observation log, it rotates todecisions.jsonl.1at about 8 MiB.Events:
enqueued: a request starts waiting. Records name, mode key, CPU and memory charge, domain, build, priority, ticket, and first arrival time.gated: a request is held back by the available-memory, pressure, or resumes-pending gate before it joins the queue. Written only when the gate reason changes, never on every retry.dequeued: a waiting request leaves the queue without starting, with the reason:available-memory,pressure,resumes-pending, orerror. The first arrival time is kept when the request re-enters the queue, so the total wait stays visible.admitted: a request starts. Records whether it started in queue order (ordered) or by passing older waiters (passing), and the free CPU and memory in the global, domain, and build scopes at that moment. It also lists the older waiters it started ahead of, oldest first, up to 16. For each one the record gives the reason it was overtaken (exception:priority,exception:build,exception:domain, orpass) and, forpass, the CPU and memory slack the pass rule computed.overtook_totalandovertook_loggedshow when the list was cut short.abandoned: mbx found and removed the queue entry of a process that died while waiting. Records the entry's details,waited_msas the age of its last queue stint (a gate requeue resets it), andfirst_arrival_msfor the request's total age.To tell a dead waiter from one that left normally, a waiting request now empties its queue file before releasing the file's lock. An empty queue file is treated as a request that is leaving, never as abandoned. So
abandonedmeans the waiting process ended without releasing its place: it was killed, or it panicked (release builds abort on panic). Emptying the file has not been tested on Windows; if it fails there, a normal release can still be logged as abandoned. An older mbx, or a process withevents = false, removes dead waiters without logging them.Events are collected while the scheduler's lock is held and written after it is released, so slow log writes never delay other builds' admission. Because of this, lines from different processes can appear slightly out of order; each line has a timestamp and ticket. Admission lines are at most 4 KiB, and other lines are under 1 KiB. A normal line is one append. After a short write, mbx appends a newline to end the partial line. That is a separate write, so a line from another process can still be lost. Logging failures are only debug-logged. With
events = false, admission does no decision-log work. The only remaining cost is that a releasing waiter empties its queue file.mbx stats --schedulergains an "Admission decisions" section. It shows:The JSON output includes every recorded overtake.
This does not change which requests can start. The admission code now reports the values it already computes to an optional trace. The existing randomized scheduler simulations check that decisions with and without tracing are identical. Old mbx versions ignore the two new fields in queue records (
pid,first_arrival_ms). When an old version's entry has no arrival time, the file's modification time is used instead.Validation:
cargo fmt, Clippy with-D warningson all targets and features, and the scheduler (186), reservation (39) and stats (15) test filters pass. New tests cover: a normal release seen as an empty file while still locked; events written only after the scheduler's lock is released; gate-reason changes; and the read loop stopping on a read error. It has not run on a live host yet. This PR will stay a draft until it has.AI-assisted — Tool: Claude Code; model: Anthropic/claude-opus-5-5; version: 2.1.302.
AI-assisted — Tool: Codex; model: OpenAI/gpt-6.1-sol; version: unavailable.
🤖 Generated with Claude Code
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
Summary by CodeRabbit
New Features
Added optional scheduler decision logs that record queue changes, admission outcomes, gate reasons, and abandoned waits.
Scheduler reports now summarize admissions, overtakes, gate reasons, and long-abandoned waits.
Bug Fixes
Improved handling of incomplete log writes to preserve record boundaries.
Documentation
* Added details on scheduler event logging, report summaries, rotation, and limitations.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->