Skip to content

test: cover graceful shutdown and clear() during mid-preemption - #78

Merged
nosyndicate merged 1 commit into
mainfrom
phase4_30
Jul 13, 2026
Merged

test: cover graceful shutdown and clear() during mid-preemption#78
nosyndicate merged 1 commit into
mainfrom
phase4_30

Conversation

@nosyndicate

@nosyndicate nosyndicate commented Jul 13, 2026

Copy link
Copy Markdown
Owner

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).

  • Add _StopOnPreemption test control that halts the engine run loop right after a preemption is recorded, leaving the victim sequence sitting in scheduler.waiting with state PREEMPTED.
  • Add test_shutdown_mid_preemption_cancels_and_frees_preempted_request, verifying that a graceful engine shutdown mid-preemption still cancels all requests, clears scheduler.running/scheduler.waiting, frees all blocks, and untracks all sequences/requests.
  • Add test_clear_handles_preempted_sequence_in_waiting, verifying Scheduler.clear() doesn't double-free blocks or otherwise choke when a PREEMPTED sequence (which already released its blocks at eviction) is sitting in waiting.

@nosyndicate nosyndicate changed the title add some test coverage test: cover graceful shutdown and clear() during mid-preemption Jul 13, 2026
@nosyndicate
nosyndicate marked this pull request as ready for review July 13, 2026 07:19
Copilot AI review requested due to automatic review settings July 13, 2026 07:19

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 _StopOnPreemption control 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() handles waiting entries in PREEMPTED state 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]
@nosyndicate
nosyndicate merged commit b8f83e5 into main Jul 13, 2026
1 check passed
@nosyndicate
nosyndicate deleted the phase4_30 branch July 13, 2026 07:24
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.

2 participants