Skip to content

test: hold the hog in the waiting-queue backstop test - #163

Merged
Gajesh2007 merged 10 commits into
mainfrom
test/scheduler-backstop-deterministic
Sep 28, 2026
Merged

Gajesh2007 merged 10 commits into
mainfrom
test/scheduler-backstop-deterministic

Conversation

@davidtai

@davidtai davidtai commented Sep 25, 2026 •

Copy link
Copy Markdown

Proposed changes

CBv2SchedulerLoopTests.testWaitingQueueBackstopEmitsCanonicalQueueFullMarker failed once in the Fork Tests whole-package step of #161 (run https://github.com/Layr-Labs/mlx-swift-lm/actions/runs/36182132297, attempt 1):

Tests/MLXLMTests/CBv2SchedulerLoopTests.swift:241: error: -[MLXLMTests.CBv2SchedulerLoopTests testWaitingQueueBackstopEmitsCanonicalQueueFullMarker] : XCTAssertTrue failed - hog must be running before filling the waiting queue

Cause: the test polls every 5 ms, for at most 10 s, until the capacity gauge shows the hog request running and nothing waiting. The hog has maxTokens: 60 on the scripted model, so it runs for only milliseconds. When the poll comes late, as on a loaded 3-core runner, it misses that window, and the condition never comes true again. The later steps of the test also need the hog to hold the single running slot.

Fix: the test now owns the hog's lifetime, as testDuplicateSubmitThrowsAndFirstStreamStillDelivers does:

  • The harness uses CBv2EngineLoopConfig(eventBufferCapacity: 4). The test does not read the hog's stream, so the stream hits backpressure and the hog pauses with its slot retained. It cannot finish before the test drains its stream.
  • The wait now also requires loopForTesting.pausedIDsSnapshot() == [hogID]. After the pause, the condition stays true, so a late poll cannot miss it.
  • The test then drains the hog's stream. The hog resumes and finishes its 60 tokens, and the assertions stay the same: the overflow request gets "token_budget_exhausted: request queue full", and the hog and the waiter finish with .length.

The engine cannot admit the waiter while the hog is paused: a paused row stays in SchedulerV2.running, and admission requires running.count < maxConcurrentRequests. The backpressure lease is 120 s by default, far longer than the test.

Only this test changes in behavior. Commit 26f54f2 also adds a Fork Tests step that runs CBv2SchedulerLoopTests (see Test plan). A second commit, ce39176 (style: format CBv2SchedulerLoopTests.swift), runs swift format format --configuration .swift-format on the whole file, so the format check of #160 passes. It changes five places outside this test (near lines 97-117, 694, 761 and 811): two nested CBv2Request calls and three comment alignments. It changes no code.

Checklist

Put an x in the boxes that apply.

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes: the changed file is formatted with swift format format and .swift-format in the separate commit ce39176
  • I have added tests that prove my fix is effective or that my feature works: not applicable, this PR fixes one test and adds none
  • I have updated the necessary documentation (if needed): not applicable, no document describes this test

Test plan

Local run on a laptop with 10 CPU cores (Apple silicon), on commit ce39176:

  • Build: swift build --build-tests with the Xcode 27.0 toolchain (Swift 6.4), --build-system native, and the Xcode XCTest search paths. The Xcode license is not accepted on this laptop, so the build called the toolchain directly instead of xcrun. The successful build took 2.0 min, after earlier attempts that failed on setup had compiled part of the package. The rebuild for the control took 13 s.
  • Without a Metal library, the suite stops with "MLX error: Failed to load the default metallib". So I staged the full AOT library from work/mlx-metallib-aot (JIT off, deployment target 26.2) with scripts/stage-test-metallib.sh. Its MLX source commit could not be checked, because that checkout no longer exists.
  • Each run executed the whole CBv2SchedulerLoopTests class (37 tests) with Xcode's xctest -XCTest MLXLMTests.CBv2SchedulerLoopTests. This is the XCTest pass that swift test --skip-build --filter CBv2SchedulerLoopTests runs.
Test file Runs Suite passed Suite failed Backstop test passed Backstop test failed
This PR (fixed) 30 30 0 30 0
ci/fork-tests (unfixed, negative control) 30 29 1 30 0
  • The negative control did not reproduce the backstop failure: 0 failures of that test in 30 runs. A 10-core laptop does not reproduce the timing of the 3-core CI runner, so this loop does not prove the fix. The fix rests on the reasoning above.
  • The one control failure was a different test: CBv2SchedulerLoopTests.testCapacityLoserIsRequeuedNotErrored failed with caught error: "CancellationError" (CBv2SchedulerTestSupport.swift:533), in run 19 of the unfixed file. This PR does not change that test. It is a second flaky test. test: make the capacity-loser scheduler test deterministic #164 fixes it. The evidence table in test: make the capacity-loser scheduler test deterministic #164 also re-ran this PR's file 30 times under CPU load, and all 30 runs passed.
  • .build (5.0 GB) was deleted after the runs. git status was clean.
  • CI run of commit ce39176 (https://github.com/Layr-Labs/mlx-swift-lm/actions/runs/36215917865) only compiled the changed test.
  • Commit 26f54f2 (ci: run the scheduler loop suite through the no-skip runner) adds a gated Fork Tests step. It runs CBv2SchedulerLoopTests through scripts/run-nested-suite.sh, after the six Metal suites, with the same if: condition and a 10-minute limit. The step fails when the class executes zero tests or skips a test.
  • CI run of 26f54f2: https://github.com/Layr-Labs/mlx-swift-lm/actions/runs/36284644301, success. The step executed 37 tests with 0 failures and 0 skips. testWaitingQueueBackstopEmitsCanonicalQueueFullMarker passed in 0.066 s.
  • In that run, scripts/build-metallib.sh built the Metal library with cmake from the resolved mlx-swift checkout, .build/checkouts/mlx-swift/Source/Cmlx/mlx at MLX commit 3fa8f25e6451174d7b06be372c3a24272b77d88e (17,326 symbols). That is the MLX commit that the pinned mlx-swift d7c1d3dc records. So the CI run does not depend on the local library, whose source revision could not be checked.

Dependencies

Merge after #159 and before #164, #166, #167 and #161. #164 is stacked on this PR.

Merge order: #160, then #159, then delete ci/fork-tests so GitHub retargets the stacked PRs to main, then #162, then #163, then #164, then #166, then #167, then #161.

Authorship

Commits were written by Claude Opus 5.5 under the direction of Claude Fable 5.1.

🤖 Generated with Claude Code

davidtai and others added 7 commits September 25, 2026 12:58
Add the Fork Tests workflow. It builds the package on a macos-26
runner, builds the full MLX Metal library with cmake, copies it next
to the test binaries, and runs six CBv2 paged suites one step each.
A suite step fails when the suite executes zero tests or skips a test.

Port the scripts from d-inference and add them to fork.yaml.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
system_profiler SPDisplaysDataType prints nothing on the hosted
macos-26 VM. The CPU, memory and disk lines stay.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Pick the newest Xcode_26.x app whose name is only a version number.
Beta and release candidate apps are left out, so a new beta on the
runner image cannot change CI without a pull request. The step still
fails when the selected Swift is older than 6.3.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
swift build makes no Metal library. The pinned mlx-swift excludes the
MLX kernel sources and nojit_kernels.cpp from Cmlx, so SwiftPM builds
MLX in JIT mode, and every MLX operation traps without a staged
mlx.metallib. The partial 459-symbol library comes from xcodebuild,
which this workflow does not use.

State that the 10,000-symbol floor rejects a JIT-mode or incomplete
cmake build.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
End the cache key with the commit SHA, as d-inference does, so each
push to main saves a new entry. The prefix restore key still restores
the newest entry for the same Xcode.

Before the save, delete the staged mlx.metallib copies and the
coverage data, so the cache keeps only SwiftPM output.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
- run-nested-suite.sh: the suites need no model weights, but one test
  needs DARKBLOOM_EXCLUSIVE_NATIVE_GPU_TEST=1, which the caller sets.
- fork-tests.yml: runs on main are not cancelled once they start.
- Say "self-contained" instead of "hermetic" in the workflow and in
  fork.yaml.
- fork.yaml: write the Fork Tests paragraph as one sentence per line,
  so later pull requests can add a sentence without touching the same
  lines.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
testWaitingQueueBackstopEmitsCanonicalQueueFullMarker polled every
5 ms for the hog request to show as running, but the hog finished its
60 scripted tokens in milliseconds. A late poll missed the window and
the test failed after 10 s (Fork Tests run 36182132297, attempt 1).

Set eventBufferCapacity to 4, as testDuplicateSubmitThrowsAndFirst-
StreamStillDelivers does. The unread hog stream hits backpressure, so
the hog pauses with its slot retained until the test drains it. The
wait now also requires the hog to be paused. Only this test changes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Run swift format format with .swift-format on the whole file, so the
format check of #160 passes. It changes four places outside the
backstop test: two nested CBv2Request calls and three comment
alignments in CBv2EngineLoopConfig arguments. No code changes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@jonathan308

Copy link
Copy Markdown

Validation follow-up for head ce39176: before approval, please add a gating CI invocation of CBv2SchedulerLoopTests (using the suite runner's zero-test/skip checks), or provide an equivalent linked CI run of this exact candidate that actually executes the class.

The PR correctly documents that its current green Fork Tests job only compiles the changed scheduler test. The local 30-run evidence is useful, but the staged Metal library's source revision was not verifiable. Please build/stage the library from the candidate's resolved MLX dependency and record that revision in the run.

Please retain the deterministic backpressure setup and existing assertions. This request is about exercising the fix in the supported CI configuration, not evidence that the proposed fix is wrong. Update the dependency notes to include #164 before #161 as well.

Add a Fork Tests step that runs CBv2SchedulerLoopTests with
scripts/run-nested-suite.sh, after the six Metal suites. The step
fails when the class executes zero tests or skips a test, so CI runs
the backstop fix instead of only compiling it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@davidtai

Copy link
Copy Markdown
Author

Reply written by Claude (agent) on David Tai's behalf.

Done. Commit 26f54f2 adds a gated step that runs CBv2SchedulerLoopTests through scripts/run-nested-suite.sh (zero-test and skip checks). Run https://github.com/Layr-Labs/mlx-swift-lm/actions/runs/36284644301 executed 37 tests, 0 failures, 0 skips. The Metal library in that job is built by cmake from the resolved mlx-swift checkout, whose pinned MLX commit is 3fa8f25e (17,326 symbols). The backpressure setup and every assertion are unchanged. Dependencies now list #164 after this PR and before #161.

Base automatically changed from ci/fork-tests to main September 28, 2026 21:29
@Gajesh2007
Gajesh2007 merged commit 4884b9f into main Sep 28, 2026
8 checks passed
@Gajesh2007
Gajesh2007 deleted the test/scheduler-backstop-deterministic branch September 28, 2026 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants