Skip to content

fix(server): end in-flight generations when the backend worker dies - #958

Merged
jason-fxz merged 2 commits into
mainfrom
fix/backend-worker-death
Nov 27, 2026
Merged

jason-fxz merged 2 commits into
mainfrom
fix/backend-worker-death

Conversation

@jason-fxz

@jason-fxz jason-fxz commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

When a backend worker dies, the supervisor wakes pending cache rebuilds and, BACKEND_DEATH_EXIT_GRACE_S (10 s) later, sends the API server SIGTERM. Generations that were already running got no reply: their handlers stayed in wait_for_ack forever. uvicorn's orderly stop waits for open connections, so one streaming client kept the serve from exiting, and the client never got an error.

Changes

  • FrontendManager.fail_inflight_requests(message): ends every admitted request (ack_map plus the stats tracker's in-flight uids, which include client-aborted ones) with a finished UserReply (error=message, error_code="backend_failed"). Each reply goes through stats.observe like a real one, so active drops to 0 and a later prepare-stop drain does not time out. It runs on the event loop through call_soon_threadsafe, like fail_pending_rebuilds.
  • The supervisor's failure handler calls it right after fail_pending_rebuilds, before the exit timer starts. Shell mode gets it too, so the running turn ends with the error.
  • A backend_failed reply is a server error, not a bad request: OpenAI routes answer 500 / server_error (error event in streams), Anthropic routes 500 / api_error. Other reply errors stay 400 / invalid_request_error.
  • /generate streams an error frame ({"error": ..., "code": ...}) before [DONE] instead of ending like a finished generation.

vLLM does the same: on engine death it puts EngineDeadError into every in-flight request (OutputProcessor.propagate_error), maps it to 500, and its watchdog then stops the HTTP server. SGLang kills the whole process tree on SIGQUIT, so its in-flight connections drop without an error body.

Tests

  • tests/server/test_rebuild_maintenance.py::test_a_worker_death_ends_the_inflight_generations: a consumer waiting in wait_for_ack ends with the error when fail_inflight_requests is called from another thread, ack_map / event_map are left empty, and the stats tracker has no active request left, including one the client had already aborted.
  • pytest tests/server tests/tokenizer: 757 passed, 24 skipped.
  • End to end, Llama-3.2-1B-Instruct, kill -9 of the scheduler while 4 requests run:
main this PR
OpenAI chat, stream no more data, no error; ends only when the client gives up (120 s read timeout here) server_error event (backend_failed) + [DONE] 0.8 s after the kill
OpenAI chat, non-stream - 500 server_error, code: backend_failed
Anthropic messages, non-stream - 500 api_error
/generate, stream - error frame (backend_failed) + [DONE]
serve stuck at Waiting for connections to close until the client disconnects exits 10.9 s after the kill

- OpenAI routes answer backend_failed with 500 / server_error, Anthropic with 500 / api_error; other reply errors stay 400
- /generate streams the error frame before [DONE]
- the failure replies go through the stats tracker, so client-aborted requests stop counting as active
@jason-fxz
jason-fxz merged commit d819084 into main Nov 27, 2026
1 check passed
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.

1 participant