[PR #2155] [Engine] serve: answer GET /models/sse (llama.cpp's model status feed) #3889

Open
opened 2026-11-07 15:31:27 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/2155
Author: @Daniel-Aaron-Bloom
Created: 10/12/2026
Status: 🔄 Open

Base: main ← Head: serve-models-sse


📝 Commits (4)

  • e76fcf1 serve: answer GET /models/sse (llama.cpp's model status feed) so front-ends that watch model loads get events (#2154)
  • e8a3710 serve: /models/sse: a load that fails sends unloaded too, so a watcher does not stay on "loading" (#2154)
  • 41f474d Merge remote-tracking branch 'origin/main' into serve-models-sse
  • 08e30a6 Merge remote-tracking branch 'origin/main' into serve-models-sse

📊 Changes

3 files changed (+121 additions, -4 deletions)

View changed files

📝 docs/DETAILS.md (+8 -0)
📝 serve/server.py (+58 -4)
📝 serve/test_lifecycle.py (+55 -0)

📄 Description

Issue: Resolves #2154

Problem and result

Front-ends that watch model status the way llama.cpp's router does GET /models/sse and get a 404, so they reconnect forever and never see the model (#2154). Now GET /models/sse streams llama.cpp-shaped status_change events - loading, loaded (with the model info), unloaded (with the exit code) - and quiet stretches get the usual SSE-comment keep-alive. A load that fails sends unloaded too, so a watcher does not stay on "loading".

Resolves #2154. Review point on this PR by @qiuzan2001: a failed load left the watcher on "loading" forever; fixed in e8a37109 with a new test (test_models_sse_reports_a_failed_load_as_unloaded).

Approach

Purely additive: a per-watcher queue on Service (sse_lock / sse_clients) and sse_notify(), and status_change emissions on the transitions the server already has: loading and loaded around a load, unloaded (exit code 0) on unload, unloaded with the exit code when the engine had died and is started again, and unloaded when a start fails. /models now builds its entry through a new Service.model_entry(), which the SSE info reuses; the /models answer itself is unchanged. No default changes, no C++ files touched, so nothing to build for CUDA, HIP or SYCL.

Validation

Passed:

  • python -m pytest serve/test_lifecycle.py -q -> 13 passed (9 existing + 4 SSE tests), on this branch at 08e30a6e (merged with main at 011c9e60), macOS, Python 3.11.
  • python -m pytest serve/ -q -> 919 passed, 12 skipped, 2 failed (listed under Failed), same revision.

Failed:

  • serve/test_gpu_roles_server.py::Roles::test_every_card_off (expects SystemExit, not raised) and serve/test_server.py::VisionArgs::test_min_tokens_is_passed_only_when_set (serve/lifeline.py AttributeError on a mocked Proc without .pid). Both fail identically on a clean checkout of origin/main 011c9e60: pre-existing on main in this environment, not caused by this change.

Not run:

  • Watching the feed live against a real client session (no real model was loaded; the tests run the endpoint over real HTTP with fixtures).
  • CUDA, HIP, SYCL and Metal builds: no C++ files are touched.

Limits

The feed covers the transitions this server has (load, unload, an engine that had died being started again, a failed start); llama.cpp's router also reports per-slot details this single-slot feed does not. One watcher queue per connection; a watcher that hangs up is dropped by its own handler.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/2155 **Author:** [@Daniel-Aaron-Bloom](https://github.com/Daniel-Aaron-Bloom) **Created:** 10/12/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `serve-models-sse` --- ### 📝 Commits (4) - [`e76fcf1`](https://github.com/Niko1221/Strata/commit/e76fcf1d4c23b2a2e5a0181d0d1931a9bb61089f) serve: answer GET /models/sse (llama.cpp's model status feed) so front-ends that watch model loads get events (#2154) - [`e8a3710`](https://github.com/Niko1221/Strata/commit/e8a371099860f143ff5ad2208a6d417aa597d0dc) serve: /models/sse: a load that fails sends unloaded too, so a watcher does not stay on "loading" (#2154) - [`41f474d`](https://github.com/Niko1221/Strata/commit/41f474db85275f7c7f75f87c5984127dd99c4ff5) Merge remote-tracking branch 'origin/main' into serve-models-sse - [`08e30a6`](https://github.com/Niko1221/Strata/commit/08e30a6e6afe8b7eee2f44dde56809f8521668d3) Merge remote-tracking branch 'origin/main' into serve-models-sse ### 📊 Changes **3 files changed** (+121 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `docs/DETAILS.md` (+8 -0) 📝 `serve/server.py` (+58 -4) 📝 `serve/test_lifecycle.py` (+55 -0) </details> ### 📄 Description Issue: Resolves #2154 ## Problem and result Front-ends that watch model status the way llama.cpp's router does GET `/models/sse` and get a 404, so they reconnect forever and never see the model (#2154). Now `GET /models/sse` streams llama.cpp-shaped `status_change` events - `loading`, `loaded` (with the model `info`), `unloaded` (with the exit code) - and quiet stretches get the usual SSE-comment keep-alive. A load that fails sends `unloaded` too, so a watcher does not stay on "loading". ## Related discussion Resolves #2154. Review point on this PR by @qiuzan2001: a failed load left the watcher on "loading" forever; fixed in `e8a37109` with a new test (`test_models_sse_reports_a_failed_load_as_unloaded`). ## Approach Purely additive: a per-watcher queue on `Service` (`sse_lock` / `sse_clients`) and `sse_notify()`, and `status_change` emissions on the transitions the server already has: `loading` and `loaded` around a load, `unloaded` (exit code 0) on unload, `unloaded` with the exit code when the engine had died and is started again, and `unloaded` when a start fails. `/models` now builds its entry through a new `Service.model_entry()`, which the SSE `info` reuses; the `/models` answer itself is unchanged. No default changes, no C++ files touched, so nothing to build for CUDA, HIP or SYCL. ## Validation **Passed:** - `python -m pytest serve/test_lifecycle.py -q` -> 13 passed (9 existing + 4 SSE tests), on this branch at `08e30a6e` (merged with `main` at `011c9e60`), macOS, Python 3.11. - `python -m pytest serve/ -q` -> 919 passed, 12 skipped, 2 failed (listed under Failed), same revision. **Failed:** - `serve/test_gpu_roles_server.py::Roles::test_every_card_off` (expects `SystemExit`, not raised) and `serve/test_server.py::VisionArgs::test_min_tokens_is_passed_only_when_set` (`serve/lifeline.py` `AttributeError` on a mocked `Proc` without `.pid`). Both fail identically on a clean checkout of `origin/main` `011c9e60`: pre-existing on main in this environment, not caused by this change. **Not run:** - Watching the feed live against a real client session (no real model was loaded; the tests run the endpoint over real HTTP with fixtures). - CUDA, HIP, SYCL and Metal builds: no C++ files are touched. ## Limits The feed covers the transitions this server has (load, unload, an engine that had died being started again, a failed start); llama.cpp's router also reports per-slot details this single-slot feed does not. One watcher queue per connection; a watcher that hangs up is dropped by its own handler. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#3889
No description provided.