test: cover graceful shutdown and clear() during mid-preemption - #78
Merged
Conversation
nosyndicate
marked this pull request as ready for review
July 13, 2026 07:19
There was a problem hiding this comment.
Pull request overview
Adds regression coverage for edge cases in the recompute-based preemption flow, specifically ensuring cleanup paths behave correctly when a victim sequence is left in PREEMPTED state (evicted but not yet resumed).
Changes:
- Adds a
_StopOnPreemptioncontrol to halt the schedule-engine run loop immediately after a preemption is observed. - Adds an engine-level test asserting graceful shutdown cancels and fully cleans up requests even when a preempted victim is sitting in
scheduler.waiting. - Adds a scheduler-level test asserting
Scheduler.clear()handleswaitingentries inPREEMPTEDstate without leaks/crashes.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/executor/test_scheduler.py | Adds a regression test for Scheduler.clear() when waiting contains a PREEMPTED sequence. |
| tests/executor/test_schedule_engine.py | Adds a stop-control and a regression test for graceful shutdown cleanup mid-preemption. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+395
to
+408
| def test_clear_handles_preempted_sequence_in_waiting() -> None: | ||
| # A PREEMPTED sequence in `waiting` already holds no blocks (freed at | ||
| # eviction) -- clear() must not double-free or otherwise choke on it. | ||
| sched = make_scheduler(block_size=4, total_blocks=16) | ||
| _prefill_running(sched, ["a"], num_tokens=4) | ||
| preempted = make_sequence(sequence_id="b", num_tokens=4) | ||
| preempted.state = SequenceState.PREEMPTED | ||
| sched.waiting.append(preempted) | ||
|
|
||
| sched.clear() | ||
|
|
||
| assert not sched.running | ||
| assert not sched.waiting | ||
| assert len(sched.block_manager.free_blocks) == 16 |
Comment on lines
+865
to
+877
| engine = ScheduleInferenceEngine(scheduler=scheduler, backend=backend) # type: ignore[arg-type] | ||
|
|
||
| req_a = _make_req(max_new_tokens=max_new_tokens) | ||
| req_a.request_id = "a" | ||
| req_b = _make_req(max_new_tokens=max_new_tokens) | ||
| req_b.request_id = "b" | ||
|
|
||
| inbound: Queue = Queue() | ||
| inbound.put(req_a) | ||
| inbound.put(req_b) | ||
| control = _StopOnPreemption(scheduler) | ||
| recorder: dict = {} | ||
| engine.run(inbound=inbound, control=control, callbacks=_callbacks(recorder)) # type: ignore[arg-type] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds regression tests for edge cases around the recompute-based preemption feature, ensuring the engine and scheduler correctly handle a sequence that is caught in the PREEMPTED state (evicted but not yet resumed).
_StopOnPreemptiontest control that halts the engine run loop right after a preemption is recorded, leaving the victim sequence sitting inscheduler.waitingwith statePREEMPTED.test_shutdown_mid_preemption_cancels_and_frees_preempted_request, verifying that a graceful engine shutdown mid-preemption still cancels all requests, clearsscheduler.running/scheduler.waiting, frees all blocks, and untracks all sequences/requests.test_clear_handles_preempted_sequence_in_waiting, verifyingScheduler.clear()doesn't double-free blocks or otherwise choke when aPREEMPTEDsequence (which already released its blocks at eviction) is sitting inwaiting.