Repository navigation
fix(scheduler): stop promising a memory requeue that step() cannot carry out - #5322
Open
masterfasa wants to merge 2 commits into
Open
masterfasa wants to merge 2 commits into
masterfasa wants to merge 2 commits into
Conversation
masterfasa
force-pushed
the
fix/memory-enforcer-requeue-livelock
branch
from
November 23, 2026 00:39
b679218 to
6e7887d
Compare
Contributor
Author
|
Pushed a second commit (rebased cleanly onto
|
…rry out At hard memory pressure the enforcer asks the scheduler to store and requeue the live requests instead of aborting them, and a positive answer means it does not abort. request_memory_requeue() could answer yes indefinitely while nothing was released: - _process_pending_memory_requeue() cleared the flag and returned without a trace when a request was still in the batch generator's prefill batch (no generation row yet), so the next poll asked and was told yes again. - while the inference thread sat in a long step, the flag stayed pending and every poll was answered with the live count. Track unfulfilled asks per request and, after _MAX_MEMORY_REQUEUE_STALLS, report the request as not requeueable. request_memory_requeue() then returns 0 and the enforcer aborts as it did before requeueing existed. Entries are dropped with the request, and a skipped requeue now logs why.
… count The enforcer polls once a second. _process_pending_memory_requeue() clears the pending flag before it stores, so a poll during the store set the flag again and the following polls counted as stalls: after _MAX_MEMORY_REQUEUE_STALLS of them request_memory_requeue() answered 0 and the enforcer aborted requests whose requeue was under way. Any store longer than about four polls was affected. Once the requeue has moved the requests to waiting, running and prefilling are empty, so a poll during the detach or the cache clear read no live request and answered 0 as well, and the enforcer aborted the requests that had just been stored. Keep the number of requests being requeued from the point the requeue is committed until the cache clear returns, and answer polls in that window with it, before reading the queues and without setting the flag. A step() that has no requeue to carry out never sets it, so its polls are kept. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
masterfasa
force-pushed
the
fix/memory-enforcer-requeue-livelock
branch
from
December 4, 2026 02:07
6e7887d to
df30dd3
Compare
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.
Problem
At hard memory pressure,
ProcessMemoryEnforcerasks the scheduler to store and requeue live requests instead of aborting them, and a positive return fromScheduler.request_memory_requeue()suppressesabort_all_requests. That positive answer could be returned indefinitely while zero memory was freed:_process_pending_memory_requeue()clears_pending_memory_requeueand returns silently when a live request has no generation-batch row yet (still inBatchGenerator's prefill batch), while the request-side blocker check accepts any request with a validuid— so the next 1 s enforcer poll is told"yes"again.step(),_pending_memory_requeuestays set and every 1 s poll returnslen(running) + len(prefilling)unbounded.Observed on an Apple M5 Pro (64 GB) with
max_concurrent_requests=4:Hard memory pressure: storing and requeueing 4 request(s)repeating every ~1 s at 57.3 GB physical footprint with no token progress.Fix
Track unfulfilled requeue asks per request (
_memory_requeue_stalls). Whenstep()skips a requested requeue (now logged with the reason) or a poll arrives while_pending_memory_requeueis still undrained, increment the stall count. After_MAX_MEMORY_REQUEUE_STALLS(3),_memory_requeue_blockerreports"requeue stalled",request_memory_requeue()clears the pending flag and returns0, andProcessMemoryEnforcerfalls through to clean abort rather than livelocking. Stall entries are cleared on successful requeue, when a request exits, and onreset().Tests
Added two regression tests in
tests/test_scheduler_boundary_completion.pycovering both failure modes and recovery for subsequent requests (904 passedacrosstest_process_memory_enforcer.pyand scheduler suites;5/5mutations of the stall tracking and cleanup paths fail the new tests).