serve: give the engine its graceful exit — stdin drain, SIGBREAK, group isolation - #1734
Merged
Merged
Conversation
…up isolation The engine's only teardown is atexit (qt_shutdown writes HEAT_FILE); every launcher stop path hard-killed it (terminate/TerminateProcess), so warm-start persistence never happened under coli serve, on any platform. - Engine.close: close the engine's stdin and wait a generous drain window first — the serve loop reads requests from stdin, EOF runs atexit — then fall through to the existing terminate/kill ladder (_ENGINE_DRAIN_S / COLI_ENGINE_DRAIN_S, default 30 s) - serve(): on Windows also handle SIGBREAK — CTRL_BREAK is the one console signal a controller can target at this process group, and without a handler it killed the serve loop before its finally could drain - Engine.__init__: spawn the engine in its own process group on Windows so the group-targeted CTRL_BREAK cannot kill it before the drain lands - coli stop: stop launchers first and give them the drain window before touching engine pids - tests/test_engine_close_drain.py: the shutdown handshake against real subprocesses (EOF exit 0 within the window; hung engine falls back)
The drain wait() may simply return None for a process (or a test double, see FakeProcess in test_openai_server.py) that only terminates when asked — the CI DispatcherTest caught the first version skipping terminate() entirely. poll() after the drain reflects both a real EOF exit and a stubbed one; the ladder runs only when the process is still alive.
This was referenced Sep 24, 2026
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.
Fixes #1733.
The engine's only teardown is atexit (qt_shutdown writes HEAT_FILE); every launcher stop path hard-killed it, so warm-start persistence never happened under coli serve, on any platform. On Windows there was additionally no way to reach a graceful exit from outside at all.
COLI_ENGINE_DRAIN_S, default 30 s — the serve loop reads requests from stdin, EOF runs atexit; EOF only lands between turns) before the existing terminate/kill ladderValidation on Windows (RTX 5070 Laptop 8 GB, Qwen3.6-35B-A3B int4-gs64, CUDA tier): before — no heat file after any shutdown; after —
[qtier] HEAT_FILE savedon every stop,[qtier] HEAT_FILE loadedon restart, and the warm-persisted pass beats the same-process warm pass (decode 10.1-11.0 → 12.1-15.0 tok/s; long-context TTFT 43.9 → 26.6 s). Localmake checkequivalent: unit tests pass (python -m unittest discover -s tests -p test_engine_close_drain.py); no C changes.Known remaining gap (needs a control channel, out of scope):
coli stopfrom another console still cannot deliver a graceful stop on Windows.