[GH-ISSUE #2496] [Engine] serve drops the connection when the engine program cannot be started #1013

Closed
opened 2026-11-04 01:47:43 +07:00 by bsakaguchi · 4 comments
Owner

Originally created by @devYRPauli on GitHub (Oct 14, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/2496

Area

[Engine] (speed, kernels, models, the server and API)

Desktop app, Terminal or source?

Source (START-HERE.bat, setup.sh or a build)

What happened

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. This happens on a lazy first load and on a restart after the engine stopped.

Any OSError from subprocess.Popen takes this path. Three examples:

  • The engine program is missing (FileNotFoundError).
  • The file is not executable (PermissionError).
  • Windows blocks the program (#735, WinError 4551 or 1260). I simulated this case with an OSError at the subprocess.Popen boundary.

Expected: a 503 with the reason. An engine that exits before READY already gets one (#1527). The comment above raise EngineDied in StrataEngine.__init__ asks for the same result.

I re-tested each of the three cases on 0.2.0-beta (3d1fb480) with 6 requests: chat, messages and responses, streamed and not.

  • All 18 requests end with RemoteDisconnected.
  • The server prints the FileNotFoundError, PermissionError or OSError traceback for each request.
  • /health still reports status: ok.
  • Each failed start leaves one start narrator thread alive. After 6 requests, 6 narrator threads are alive.
  • The engine log handle of the last failed start stays open.

Cause: StrataEngine.__init__ calls popen() with no handler. The OSError passes through restart(), which catches only RuntimeError, and through Service.ensure_loaded(). The request handler's except OSError branch records disconnected and re-raises, so socketserver closes the socket. On this path __init__ also never sets the loading event and never closes self.log.

PR #2497 fixes this and contains 0.2.0-beta. I ran the same 18 requests on its head (e7680b9d7). All 18 get 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.

Smallest steps or command that reproduce it

Save this as repro.py in the repo root and run python repro.py. It needs no GPU and no engine build.

import json
import urllib.request
from pathlib import Path
from serve.server import ByteTokenizer, ChatTemplate, Service, StrataEngine, serve

eng = StrataEngine("/no/such/strata", [], log="strata-test.log", lazy=True)
svc = Service(eng, ByteTokenizer(), ChatTemplate(Path("serve/chat_template.jinja")))
httpd = serve(svc, port=0)
url = f"http://127.0.0.1:{httpd.server_address[1]}/v1/chat/completions"
body = json.dumps({"messages": [{"role": "user", "content": "hi"}], "max_tokens": 8}).encode()
try:
    urllib.request.urlopen(urllib.request.Request(url, body, {"Content-Type": "application/json"}))
except Exception as e:
    print(type(e).__name__, getattr(e, "code", ""), e.read().decode() if hasattr(e, "read") else e)

On 0.2.0-beta (3d1fb480) the script prints this line:

RemoteDisconnected  Remote end closed connection without response

Reproduction status

Reproduced locally

Strata version

Strata 0.2.0-beta, tag v0.2.0-beta, commit 3d1fb480. serve/ only, no engine build.

Graphics card, memory and system

No GPU used (the engine never starts). Apple M1 Pro, 16 GB RAM, macOS 27.0.1, Python 3.12.14

Model, size and settings

None. The failure happens before a model loads.

Logs

The server output for one request on 0.2.0-beta:

[strata] loading the model again (it was unloaded) ...
[strata] starting the engine: reading the model's weights ...
...
  File "serve/server.py", line 3831, in ensure_loaded
    self.engine.restart()
  File "serve/server.py", line 1253, in restart
    self.__init__(*self.spawn)
  File "serve/server.py", line 997, in __init__
    self.proc = popen("the Strata engine", [exe, "--serve", *args], cwd=cwd, stdin=subprocess.PIPE,
  File "serve/lifeline.py", line 256, in popen
    child = subprocess.Popen(args, **kw)
FileNotFoundError: [Errno 2] No such file or directory: '/no/such/strata'
Originally created by @devYRPauli on GitHub (Oct 14, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/2496 ### Area [Engine] (speed, kernels, models, the server and API) ### Desktop app, Terminal or source? Source (START-HERE.bat, setup.sh or a build) ### What happened 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. This happens on a lazy first load and on a restart after the engine stopped. Any `OSError` from `subprocess.Popen` takes this path. Three examples: - The engine program is missing (`FileNotFoundError`). - The file is not executable (`PermissionError`). - Windows blocks the program (#735, WinError 4551 or 1260). I simulated this case with an `OSError` at the `subprocess.Popen` boundary. Expected: a 503 with the reason. An engine that exits before READY already gets one (#1527). The comment above `raise EngineDied` in `StrataEngine.__init__` asks for the same result. I re-tested each of the three cases on 0.2.0-beta (3d1fb480) with 6 requests: chat, messages and responses, streamed and not. - All 18 requests end with `RemoteDisconnected`. - The server prints the `FileNotFoundError`, `PermissionError` or `OSError` traceback for each request. - `/health` still reports `status: ok`. - Each failed start leaves one start narrator thread alive. After 6 requests, 6 narrator threads are alive. - The engine log handle of the last failed start stays open. Cause: `StrataEngine.__init__` calls `popen()` with no handler. The `OSError` passes through `restart()`, which catches only `RuntimeError`, and through `Service.ensure_loaded()`. The request handler's `except OSError` branch records `disconnected` and re-raises, so `socketserver` closes the socket. On this path `__init__` also never sets the `loading` event and never closes `self.log`. PR #2497 fixes this and contains 0.2.0-beta. I ran the same 18 requests on its head (e7680b9d7). All 18 get 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. ### Smallest steps or command that reproduce it Save this as `repro.py` in the repo root and run `python repro.py`. It needs no GPU and no engine build. ```python import json import urllib.request from pathlib import Path from serve.server import ByteTokenizer, ChatTemplate, Service, StrataEngine, serve eng = StrataEngine("/no/such/strata", [], log="strata-test.log", lazy=True) svc = Service(eng, ByteTokenizer(), ChatTemplate(Path("serve/chat_template.jinja"))) httpd = serve(svc, port=0) url = f"http://127.0.0.1:{httpd.server_address[1]}/v1/chat/completions" body = json.dumps({"messages": [{"role": "user", "content": "hi"}], "max_tokens": 8}).encode() try: urllib.request.urlopen(urllib.request.Request(url, body, {"Content-Type": "application/json"})) except Exception as e: print(type(e).__name__, getattr(e, "code", ""), e.read().decode() if hasattr(e, "read") else e) ``` On 0.2.0-beta (3d1fb480) the script prints this line: ``` RemoteDisconnected Remote end closed connection without response ``` ### Reproduction status Reproduced locally ### Strata version Strata 0.2.0-beta, tag v0.2.0-beta, commit 3d1fb480. serve/ only, no engine build. ### Graphics card, memory and system No GPU used (the engine never starts). Apple M1 Pro, 16 GB RAM, macOS 27.0.1, Python 3.12.14 ### Model, size and settings None. The failure happens before a model loads. ### Logs The server output for one request on 0.2.0-beta: ``` [strata] loading the model again (it was unloaded) ... [strata] starting the engine: reading the model's weights ... ... File "serve/server.py", line 3831, in ensure_loaded self.engine.restart() File "serve/server.py", line 1253, in restart self.__init__(*self.spawn) File "serve/server.py", line 997, in __init__ self.proc = popen("the Strata engine", [exe, "--serve", *args], cwd=cwd, stdin=subprocess.PIPE, File "serve/lifeline.py", line 256, in popen child = subprocess.Popen(args, **kw) FileNotFoundError: [Errno 2] No such file or directory: '/no/such/strata' ```
Author
Owner

@qiuzan2001 commented on GitHub (Oct 15, 2026):

Reproduced on Linux with main 296b59d2 (Python 3.14, no GPU needed). The test that #2497 adds (serve/test_ready_timeout.py, SpawnFailure, an engine path that does not exist) fails on main's serve/server.py with RemoteDisconnected: Remote end closed connection without response on all 4 requests, and passes on #2497's branch (python -m unittest serve.test_ready_timeout: 3 tests OK).

<!-- gh-comment-id:6184172398 --> @qiuzan2001 commented on GitHub (Oct 15, 2026): Reproduced on Linux with main 296b59d2 (Python 3.14, no GPU needed). The test that #2497 adds (`serve/test_ready_timeout.py`, `SpawnFailure`, an engine path that does not exist) fails on main's `serve/server.py` with `RemoteDisconnected: Remote end closed connection without response` on all 4 requests, and passes on #2497's branch (`python -m unittest serve.test_ready_timeout`: 3 tests OK).
Author
Owner

@Niko1221 commented on GitHub (Oct 19, 2026):

Thanks for taking the time to report this.

We're resetting the tracker for 0.2.0-beta. There are more than 1,300 open issues and pull requests, too many for us to read properly, so we're closing everything that isn't being worked on right now. Closed here does not mean rejected.

To reopen it takes about two minutes:

  1. Re-test on 0.2.0-beta. It may already be fixed. Write down what you see.
  2. Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other].
  3. Fill in the parts of the issue form: what happened, the Strata version, your graphics card, memory and system.
  4. Comment /reopen. A check runs and either reopens the issue or lists what is still missing.

The rules are in CONTRIBUTING.md.

<!-- gh-comment-id:6271086824 --> @Niko1221 commented on GitHub (Oct 19, 2026): Thanks for taking the time to report this. We're resetting the tracker for 0.2.0-beta. There are more than 1,300 open issues and pull requests, too many for us to read properly, so we're closing everything that isn't being worked on right now. Closed here does not mean rejected. To reopen it takes about two minutes: 1. Re-test on 0.2.0-beta. It may already be fixed. Write down what you see. 2. Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other]. 3. Fill in the parts of the issue form: what happened, the Strata version, your graphics card, memory and system. 4. Comment `/reopen`. A check runs and either reopens the issue or lists what is still missing. The rules are in [CONTRIBUTING.md](https://github.com/Niko1221/Strata/blob/main/CONTRIBUTING.md).
Author
Owner

@devYRPauli commented on GitHub (Oct 19, 2026):

/reopen

<!-- gh-comment-id:6271673428 --> @devYRPauli commented on GitHub (Oct 19, 2026): /reopen
Author
Owner

@github-actions[bot] commented on GitHub (Oct 19, 2026):

Reopened, thank you. A maintainer will pick it up from here.

<!-- gh-comment-id:6271677108 --> @github-actions[bot] commented on GitHub (Oct 19, 2026): Reopened, thank you. A maintainer will pick it up from here.
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#1013
No description provided.