[PR #2497] [Engine] serve: an engine program that cannot be started is a 503, not a dropped connection #4079

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/2497
Author: @devYRPauli
Created: 10/14/2026
Status: 🔄 Open

Base: main ← Head: engine-spawn-failure-503


📝 Commits (2)

  • 048232e serve: an engine program that cannot be started is a 503 (#2496)
  • e7680b9 Merge branch 'main' into engine-spawn-failure-503

📊 Changes

2 files changed (+49 additions, -3 deletions)

View changed files

📝 serve/server.py (+14 -3)
📝 serve/test_ready_timeout.py (+35 -0)

📄 Description

Problem and result

When the server cannot start the engine program, the request that starts the engine gets no HTTP answer. The client sees a closed connection with no status line. Any OSError from subprocess.Popen takes this path: a missing program, a file that is not executable, or a program that Windows blocks (#735). Each failed start also leaves one start narrator thread running, and the last failed start keeps its engine log open.

With this PR, the request gets a 503 with the reason, for example the engine could not be started: [Errno 2] No such file or directory: '/no/such/strata'. No narrator thread stays alive, and the log handle is closed.

Resolves #2496. I re-tested the issue on 0.2.0-beta, and it is reopened.

Approach

  • StrataEngine.__init__: when popen() raises an OSError, the start sets the loading event and closes its handle on the engine log. Then it re-raises the same OSError, so the startup path keeps its exception type.
  • Service.ensure_loaded: an OSError from engine.restart() becomes EngineDied("the engine could not be started: ..."). The request path already answers EngineDied with a 503, as it does for an engine that exits before READY (#1527). The vision encoder unload on failure is unchanged.
  • serve/test_ready_timeout.py: new class SpawnFailure. A lazy engine with a missing program gets a 503 on chat, messages, responses and a streamed chat. The test also checks that the log handle is closed and that no narrator thread stays alive. The class runs on Windows too, because a missing program fails the same way there.

The diff is 2 files, +49/-3. It merges cleanly with main f57c0adc.

Validation

All runs: macOS 27.0.1, Apple M1 Pro, Python 3.12.14, no GPU, serve/ only. The PR head is e7680b9d7, which contains 0.2.0-beta (3d1fb480).

Passed:

  • python -m unittest serve.test_ready_timeout.SpawnFailure on the PR head: OK.
  • The same test file on 0.2.0-beta without the fix: 4 errors (the 4 requests drop) and 1 failure (a narrator thread stays alive). So the test catches the bug.
  • A script sends 6 requests for each of 3 causes. The requests are chat, messages and responses, streamed and not. The causes are a missing program, a file that is not executable, and a simulated WinError 4551 (an OSError raised at the subprocess.Popen boundary). On 0.2.0-beta all 18 requests end with RemoteDisconnected, 6 narrator threads stay alive per cause, and the log handle stays open. On the PR head all 18 get a 503 with the reason, no narrator thread stays alive, and the log handle is closed.
  • Earlier, on main 296b59d2, I reverted each half of the fix on its own. Without the ensure_loaded change, the 4 requests drop. Without the __init__ change, the log handle stays open and the narrator threads stay alive.

Failed:

python -m unittest discover -s serve -t . -p 'test_*.py': 882 tests on the PR head and 881 on 0.2.0-beta. Both runs have the same 3 failures and 1 error, so this PR adds no failure:

  • test_lifeline.Lifeline: 3 tests, for example the child outlived a killed server (watcher).
  • test_server.VisionArgs.test_min_tokens_is_passed_only_when_set: AttributeError: 'Proc' object has no attribute 'pid'.

Not run:

  • A real Windows machine. The WinError 4551 case is simulated, so the Windows error path is not verified on Windows.
  • Engine builds and GPU runs. The change is in serve/ only, and no engine starts in these tests.

Limits

  • The /load route catches only GpuBusy, so EngineDied and EngineStuck still drop its connection. That is a separate change.
  • A failed load on /v1/responses answers 503 without the "the next request restarts it" suffix. That text comes from the Responses handler, and this PR does not change it.
  • #2435 makes the same change for the elastic image encoder. #1563 edits the same popen() call, so one of the two PRs needs a rebase after the other merges.

🔄 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/2497 **Author:** [@devYRPauli](https://github.com/devYRPauli) **Created:** 10/14/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `engine-spawn-failure-503` --- ### 📝 Commits (2) - [`048232e`](https://github.com/Niko1221/Strata/commit/048232ecfb1cc64b51589e85c9d0132e4eeab814) serve: an engine program that cannot be started is a 503 (#2496) - [`e7680b9`](https://github.com/Niko1221/Strata/commit/e7680b9d782b6565c6b78183168bcedec9947a97) Merge branch 'main' into engine-spawn-failure-503 ### 📊 Changes **2 files changed** (+49 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `serve/server.py` (+14 -3) 📝 `serve/test_ready_timeout.py` (+35 -0) </details> ### 📄 Description ## Problem and result When the server cannot start the engine program, the request that starts the engine gets no HTTP answer. The client sees a closed connection with no status line. Any `OSError` from `subprocess.Popen` takes this path: a missing program, a file that is not executable, or a program that Windows blocks (#735). Each failed start also leaves one start narrator thread running, and the last failed start keeps its engine log open. With this PR, the request gets a 503 with the reason, for example `the engine could not be started: [Errno 2] No such file or directory: '/no/such/strata'`. No narrator thread stays alive, and the log handle is closed. ## Related discussion Resolves #2496. I re-tested the issue on 0.2.0-beta, and it is reopened. ## Approach - `StrataEngine.__init__`: when `popen()` raises an `OSError`, the start sets the `loading` event and closes its handle on the engine log. Then it re-raises the same `OSError`, so the startup path keeps its exception type. - `Service.ensure_loaded`: an `OSError` from `engine.restart()` becomes `EngineDied("the engine could not be started: ...")`. The request path already answers `EngineDied` with a 503, as it does for an engine that exits before READY (#1527). The vision encoder unload on failure is unchanged. - `serve/test_ready_timeout.py`: new class `SpawnFailure`. A lazy engine with a missing program gets a 503 on chat, messages, responses and a streamed chat. The test also checks that the log handle is closed and that no narrator thread stays alive. The class runs on Windows too, because a missing program fails the same way there. The diff is 2 files, +49/-3. It merges cleanly with main f57c0adc. ## Validation All runs: macOS 27.0.1, Apple M1 Pro, Python 3.12.14, no GPU, serve/ only. The PR head is e7680b9d7, which contains 0.2.0-beta (3d1fb480). **Passed:** - `python -m unittest serve.test_ready_timeout.SpawnFailure` on the PR head: OK. - The same test file on 0.2.0-beta without the fix: 4 errors (the 4 requests drop) and 1 failure (a narrator thread stays alive). So the test catches the bug. - A script sends 6 requests for each of 3 causes. The requests are chat, messages and responses, streamed and not. The causes are a missing program, a file that is not executable, and a simulated WinError 4551 (an `OSError` raised at the `subprocess.Popen` boundary). On 0.2.0-beta all 18 requests end with `RemoteDisconnected`, 6 narrator threads stay alive per cause, and the log handle stays open. On the PR head all 18 get a 503 with the reason, no narrator thread stays alive, and the log handle is closed. - Earlier, on main 296b59d2, I reverted each half of the fix on its own. Without the `ensure_loaded` change, the 4 requests drop. Without the `__init__` change, the log handle stays open and the narrator threads stay alive. **Failed:** `python -m unittest discover -s serve -t . -p 'test_*.py'`: 882 tests on the PR head and 881 on 0.2.0-beta. Both runs have the same 3 failures and 1 error, so this PR adds no failure: - `test_lifeline.Lifeline`: 3 tests, for example `the child outlived a killed server (watcher)`. - `test_server.VisionArgs.test_min_tokens_is_passed_only_when_set`: `AttributeError: 'Proc' object has no attribute 'pid'`. **Not run:** - A real Windows machine. The WinError 4551 case is simulated, so the Windows error path is not verified on Windows. - Engine builds and GPU runs. The change is in serve/ only, and no engine starts in these tests. ## Limits - The `/load` route catches only `GpuBusy`, so `EngineDied` and `EngineStuck` still drop its connection. That is a separate change. - A failed load on `/v1/responses` answers 503 without the "the next request restarts it" suffix. That text comes from the Responses handler, and this PR does not change it. - #2435 makes the same change for the elastic image encoder. #1563 edits the same `popen()` call, so one of the two PRs needs a rebase after the other merges. --- <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#4079
No description provided.