← Back to Pull requests

feat(scheduler): log admission decisions and cancelled waits #760

Closed
unknown closed this pull request without merging on Oct 19, 2026 19:49 UTC
View on GitHub
unknown unknown commented on Oct 19, 2026 14:34 UTC
Author

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 events enabled (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 to decisions.jsonl.1 at 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, or error. 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, or pass) and, for pass, the CPU and memory slack the pass rule computed. overtook_total and overtook_logged show 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_ms as the age of its last queue stint (a gate requeue resets it), and first_arrival_ms for 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 abandoned means 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 with events = 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 --scheduler gains an "Admission decisions" section. It shows:

  • admissions by rule;

  • how many admissions overtook older waiters, and for which reasons;

  • gate and dequeue reasons;

  • the five longest-waiting overtaken requests;

  • abandoned waits older than 15 minutes, measured from the request's first arrival, so a request the gate requeued for a long time is still listed.
  • 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 warnings on 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 -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: jbellis Review duration: 314m
    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
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%