Repository navigation
fix(server): end in-flight generations when the backend worker dies - #958
Merged
Merged
Conversation
- 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
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.
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 inwait_for_ackforever. 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_mapplus the stats tracker's in-flight uids, which include client-aborted ones) with a finishedUserReply(error=message,error_code="backend_failed"). Each reply goes throughstats.observelike a real one, soactivedrops to 0 and a later prepare-stop drain does not time out. It runs on the event loop throughcall_soon_threadsafe, likefail_pending_rebuilds.fail_pending_rebuilds, before the exit timer starts. Shell mode gets it too, so the running turn ends with the error.backend_failedreply 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./generatestreams an error frame ({"error": ..., "code": ...}) before[DONE]instead of ending like a finished generation.vLLM does the same: on engine death it puts
EngineDeadErrorinto 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 inwait_for_ackends with the error whenfail_inflight_requestsis called from another thread,ack_map/event_mapare 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.kill -9of the scheduler while 4 requests run:server_errorevent (backend_failed) +[DONE]0.8 s after the killserver_error,code: backend_failedapi_error/generate, streambackend_failed) +[DONE]Waiting for connections to closeuntil the client disconnects