← Back to Pull requests

fix(scheduler): stop nextest runs inside mbx reserve from waiting on their own lease #1040

Closed
unknown closed this pull request without merging on Nov 29, 2026 20:40 UTC
View on GitHub
unknown unknown commented on Nov 29, 2026 20:17 UTC
Author

With scheduler.tests = true, a cargo nextest run started inside mbx reserve (or by a wrapper that exports MBX_SCHED_DISABLE) asked the machine-wide pool for the run's cores a second time, even though the enclosing reservation already pays for them. The compilers in the same run correctly take nothing. When the second request couldn't fit beside the enclosing lease, the run waited at listing forever for capacity its own reservation held:

$ MBX_SCHEDULER_CPUS=2 mbx reserve --cpus 2 -- mbx nextest run
mbx: waiting for machine-wide scheduler capacity before running tests; nextest does not time this wait; held by a reservation (2 cores)

That happened whenever the enclosing reservation held the whole budget, and also for a 1-core reservation with nextest's default thread count, which asks for the whole pool. When the request did fit, the run held two leases for the same work. This was a regression in 1.31.0, which added the run-wide nextest reservation.

Now a nextest run inside an enclosing reservation takes no reservation of its own, as on 1.30.0. Its tests start right away and are charged to the enclosing lease. mbx still runs them through its target runner, so configured runners still chain and each test still gets MBX_SCHEDULER=0. As before 1.31.0, nextest picks its own width (pass --test-threads "$MBX_RESERVED_CPUS" to keep it inside the lease), and these runs don't record test history. Runs that aren't inside a reservation are unchanged.

A run without a reservation now also exports an empty MBX_NEXTEST_RUN, so a nested run can't inherit an outer run's reservation directory and post its listings there.

docs/scheduling.md describes the behavior.

Validation: a new end-to-end test, a_nextest_run_inside_an_enclosing_reservation_takes_no_lease_of_its_own, uses a two-core budget and covers three cases: a 1-core mbx reserve with one test thread, a 2-core mbx reserve with default threads, and a separate mbx reserve holding both cores while the run only gets MBX_SCHED_DISABLE=1. In each case the test must start within 20 s, see MBX_SCHEDULER=0, run while exactly one lease is held, and print no capacity note. Without the fix the first case fails with left: 2, right: 1. mise run ci passes locally on Linux.

Fixes #1038

AI-assisted — Tool: Claude Code; model: anthropic/claude-sonnet-5-5; version: 2.1.332.

🤖 Generated with Claude Code

<!-- CURSOR_SUMMARY -->
---

[!NOTE]

Medium Risk

Changes nextest run reservation and nested env inheritance in the scheduler/test runner path; behavior outside enclosing reservations is intended to stay the same, validated by new e2e tests.

> Overview

Fixes a regression where cargo nextest run inside mbx reserve (or with MBX_SCHED_DISABLE) tried to take a second run-wide scheduler reservation on top of the enclosing lease, which could deadlock at listing or hold duplicate leases.

> RunReservation::start now skips creating a run reservation when covered_by_enclosing_reservation() is true (presence of MBX_SCHED_DISABLE), reusing the parent lease so tests start without waiting. Scheduler session setup uses the same helper.

> MBX_NEXTEST_RUN is always set in the runner overlay—empty when there is no reservation—so nested runs do not inherit an outer run’s directory or post listings there; listing logic ignores an empty value.

> Adds an end-to-end test covering reserve-wrapped nextest, full-pool reserve, and disable-env sibling cases, plus docs/scheduling.md notes (including --test-threads "$MBX_RESERVED_CPUS" and no test history in this mode).

> <sup>Reviewed by Cursor Bugbot for commit 5cbe7bf48a98996307316deb611cce51c6a1c4aa. Bugbot is set up for automated code reviews on this repo. Configure here.</sup>

<!-- /CURSOR_SUMMARY -->

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
<!-- coderabbit-ai-generated:v1 -->

Summary by CodeRabbit

Bug Fixes
Test runs started within an existing reservation no longer request a separate scheduler reservation, avoiding unnecessary waits.
Runs handle inherited reservation settings consistently when no reservation is active.

Documentation
Updated the scheduling guide with details on running tests within an existing reservation, including guidance on matching test concurrency to reserved capacity.
Clarified that these runs do not record test history.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Diff: 582 lines (+436 / -146) across 7 files Reviewer: jdx Review duration: 23m
All Vouch review confidence checks passed
Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 582 lines diff across 7 files
0.50
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.381
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #1040"
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: 49.9% (MEDIUM) · Higher = larger blast radius
49.9%
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: 19.7% · Safe to merge
19.7%