Files
alzeo/image-sglang/http-graceful-timeout.patch
T
Hasan BasbunarandClaude Opus 5.5 e0953f0d25 Image lane: a generation can be cancelled, and a Stop during one is clean
On 2026-09-23 a call for ten 2048x2048 images at 60 steps (about 47 minutes)
was running when the image lane was stopped to switch lanes. The runtime's
HTTP server waits on shutdown for every open connection, and a generation
holds one for as long as it runs: 60 s in "stopping", then systemd killed the
lane and the unit ended failed (Result=timeout), shown as "Qwen-Image failed,
read its journal". SGLang Diffusion cannot abort a request, and the page had
no Cancel, so the Stop was the only way out.

image-sglang/http-graceful-timeout.patch, the second local change to the
pinned source: uvicorn.run(..., timeout_graceful_shutdown=5). Proved in a
transient systemd unit with uvicorn 0.53 holding a ten-minute request:
without it, "stop-sigterm timed out, Killing", Result=timeout; with it,
stopped in 5.2 s, Result=success. install-image.sh applies every patch of
image-sglang/ from one list, recognises them, and takes them all off before a
new pin; the CI step fetches each patched file at the pin and checks it, and
fails when a patch in the repo is not in the installer's list.

The Image tab's Cancel shows while a generation runs (this page's or another
tab's) and restarts the lane, the only abort this runtime has, through the
same action API, gates and confirmation as the Engines card. It starts and
stops nothing, so the Image tab rule holds: its test now asserts the tab
sends no Start or Stop and exactly one restart, the cancel. A request cut by
Cancel, the lane's Stop or a restart reads as cancelled, not as a lane that
failed to answer.

A call may not ask for more pixels, all its images together, than the
largest call measured here (one 2752x1536 image, 44.8 GB at its peak): the
images of a call run as one batch (42 s per step for those ten, 4.6 for one),
their memory at that size was never measured, and running out of unified
memory hangs this box. Refused in the tab and on the server, with numbers.

The lifecycle carries systemd's Result, and a unit that ended "timeout" reads
"was killed while stopping, nothing broke while it was serving".

opencode's limits follow a boot after a switch: a switch writes the nominal
900,000 pair, and nothing fitted it after a switch and a Start from the page
(the Agent tab asked for 900,000 against 809,983 servable after the switch to
the uncensored target that morning). The cockpit now runs the Setup tab's
fit itself once the text engine is ready: once per activation, only when the
declared limits do not fit, never to raise one, as an audited job.
COCKPIT_AUTOFIT=0 turns it off.

Tests: pixel budget (the call that started this is refused before the lane
sees it, the largest measured call passes, the total counts, a size string
counts), autofit (once per boot, never while no text engine is ready, never a
raise, retried when the job lock is busy), Result in the lifecycle, the
cancel wiring, both patches through the installer's own lines. Five guards
were undone once each and their tests failed. CI 60/60.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-23 12:31:22 +02:00

15 lines
654 B
Diff

diff --git a/python/sglang/multimodal_gen/runtime/launch_server.py b/python/sglang/multimodal_gen/runtime/launch_server.py
index d3fa0a1..9a10bb5 100644
--- a/python/sglang/multimodal_gen/runtime/launch_server.py
+++ b/python/sglang/multimodal_gen/runtime/launch_server.py
@@ -491,6 +491,9 @@ def launch_http_server_only(server_args):
port=server_args.port,
reload=False,
ws_per_message_deflate=False,
+ # Without a bound, shutdown waits for every open connection, and a generation
+ # holds one for as long as it runs; 5 s, then in-flight requests are cancelled.
+ timeout_graceful_shutdown=5,
)