[Bugfix] Validate sleep stage_ids before blocking admission (#8501)

Signed-off-by: Yufeng He <40085740+he-yufeng@users.noreply.github.com>
This commit is contained in:
Yufeng He authored and GitHub committed 2026-10-05 10:27:53 -04:00
1 parent 023716ecc4
commit a0e626caaf
4 files changed
+48 -4

No files matched your search

+6 -2
View File
@@ -959,6 +959,12 @@ class AsyncOmni(AsyncOmniBase, EngineClient):
engines have no EngineCore pause to hold, so ``wake_up`` restores
admission and ``sleep → wake → generate`` keeps working.
"""
# Validate before touching admission state. Raising after
# ``_paused = True`` would wedge generate() for good: nothing was
# slept, so wake_up() has no tags to restore and never reaches the
# block that clears ``_paused``.
ar_stage_ids, diffusion_stage_ids = self._split_stage_ids_by_type(stage_ids)
# Block admission before any sleep RPC so generate() waits on
# _pause_cond during the drain/offload window. Wait until generate()
# coroutines that already passed the pause check have submitted (or
@@ -966,8 +972,6 @@ class AsyncOmni(AsyncOmniBase, EngineClient):
async with self._pause_cond:
self._paused = True
await self._pause_cond.wait_for(lambda: getattr(self, "_admitting", 0) == 0)
ar_stage_ids, diffusion_stage_ids = self._split_stage_ids_by_type(stage_ids)
# EngineCore.sleep resets receiver caches itself; only clear P0 here.
if 0 in ar_stage_ids:
await self._clear_frontend_mm_cache()
@@ -3062,6 +3062,8 @@ async def omni_sleep(request: OmniSleepRequest, raw_request: Request):
raise HTTPException(status_code=501, detail="Engine does not support sleep")
try:
acks = await engine_client.sleep(stage_ids=request.stage_ids, level=request.level)
except ValueError as e:
raise HTTPException(status_code=HTTPStatus.BAD_REQUEST.value, detail=str(e)) from e
except RuntimeError as e:
raise HTTPException(status_code=HTTPStatus.INTERNAL_SERVER_ERROR.value, detail=f"Failed to sleep: {e}") from e
finally:
@@ -3086,6 +3088,8 @@ async def omni_wakeup(request: OmniWakeupRequest, raw_request: Request):
acks = await engine_client.wake_up(stage_ids=request.stage_ids)
except NotImplementedError:
raise
except ValueError as e:
raise HTTPException(status_code=HTTPStatus.BAD_REQUEST.value, detail=str(e)) from e
except RuntimeError as e:
raise HTTPException(status_code=HTTPStatus.INTERNAL_SERVER_ERROR.value, detail=f"Failed to wake up: {e}") from e
for sid in request.stage_ids: