[PR #4893] [TUI] the managed runtime host leaves when its server exits instead of staying a husk (Fix #4574) #5233

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4893
Author: @XiaoBinGan
Created: 11/1/2026
Status: 🔄 Open

Base: main ← Head: fix/runtime-host-leaves-with-its-server


📝 Commits (1)

  • 65dd499 Fix #4574: the managed runtime host leaves when its server exits on its own

📊 Changes

2 files changed (+54 additions, -1 deletions)

View changed files

📝 strata_control/runtime.py (+31 -1)
📝 tests/terminal/test_runtime.py (+23 -0)

📄 Description

Problem and result

A managed runtime host never watched the server it started. When that server exited - a crash, an external kill, an
engine that stopped on its own - the host stayed in its accept loop with the profile's private state file and activity
lease, and reported state: failed for ever. Every later strata runtime start / strata launch for that profile then
refused with "this profile already has a live managed runtime", although nothing was serving, until a person killed a
host PID that runtime status did not point at as the problem.

After the change the host notices within about a second that its server has ended and leaves through the cleanup it
already has: the private state file, the ready file, the child marker and the activity lease are released, so the next
start recovers by itself. It first gives a client that was waiting for the failure two more seconds to read failed and
the log tail.

Reproduction on this checkout (Windows 11, Python 3.11.16), using the registered fake engine of
tests/terminal/test_runtime.py: start the profile, kill the server child, then watch the host. Before the change the
host was alive with status_state=failed at every 0.5 s step for 10 s and the private state file was still there; with
the change the new case sees the host process end (one accept cycle plus the 2 s grace), the private state file gone and
the next start ready.

#4574 - the report (host husks after its server child exits; profile locked until a manual kill). The issue expected
the host to "log it and either restart (bounded) or tear down cleanly (release state lock, exit non-zero)"; this is the
tear-down, which is the smaller change.
#4824 - strata launch meets such a host after a long tune and refuses to start; removing the host removes that blocker
(it is not the whole of #4824 - the launch-side handling of a host it finds is a separate change).

Approach

strata_control/runtime.py:

  • Host.serve() polls self.child at the top of its accept loop. An exit the host did not ask for is recorded once,
    and after a 2 s grace (so a client that was waiting for the failure can read failed + log_tail) the loop ends
    with exit status 1; the existing finally block then removes the state file, ready file, child marker, snapshots and
    the activity lease.
  • _stop_child() marks every stop the host itself asks for (a stop, a restart, the failed-probe stop), and
    _launch() clears the mark for a new child. So a restart, a deliberate stop and a failed generation probe behave
    exactly as before; only an unasked-for exit ends the host.

Validation

Passed: the new case fails on an unmodified checkout and passes with the change. With strata_control/runtime.py
from main (everything else including the new test file unchanged):

python -m pytest tests/terminal/test_runtime.py -q -k "the_host_leaves"
... AssertionError: the owner host stays alive as a husk after its server child exits
1 failed, 1 error in 26.52s

The error is the teardown of the husk the case leaves behind in that run; the failure is the case itself. With the
change:

python -m pytest tests/terminal/test_runtime.py -q -k "the_host_leaves"
1 passed in 15.70s

Passed: the whole file in CI. The branch's tests/terminal/test_runtime.py passes the "Linux / runtime requirements
only" job (tools/minimal_server_smoke.py, which runs the whole file in a runtime-only venv), and the portable-monitor
jobs on Windows and Ubuntu (Python 3.10 and 3.11) are green too (run 41294189141).

Failed: none in CI. On this Windows machine a full run of the file has one pre-existing failure at teardown,
test_local_management_bridge_and_cli_share_owner_and_journal: PermissionError: [WinError 32] ... local.host.log;
the same failure appears on the unmodified tree (48 passed, 2 skipped, 1 failed before; 49 passed, 2 skipped, 1 failed
with the new case). A later repeat of the whole file on this shared machine also produced a few unrelated
startup_wait_expired timeouts; the CI run above is the stable measurement.

Not run: a POSIX session by hand. The CI job above runs the whole file on Linux and passes, including the new case;
the reproduction output pasted here and the full local runs are from Windows 11. A real strata launch/desktop session
that loses its server child was not run either: the case drives the host with the same fake engine the rest of
test_runtime.py uses.

Limits

  • The host chooses to leave rather than to restart the server. Restarting a crashed engine automatically would hide the
    failure; the issue allows either. The recorded reason remains in <profile>.host.log and in <profile>.server.log.
  • A client that is polling the start gets the failed status during the 2 s grace. A client that asks for status after
    the host has left sees stopped (the record is gone), not failed.
  • A failed start (the server never became ready) is unchanged: the host still stays and reports failed with the log
    tail, because that is the only place a launcher reads the reason; that path is not an unasked-for exit.

🔄 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/4893 **Author:** [@XiaoBinGan](https://github.com/XiaoBinGan) **Created:** 11/1/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/runtime-host-leaves-with-its-server` --- ### 📝 Commits (1) - [`65dd499`](https://github.com/Niko1221/Strata/commit/65dd499e6c9e2d254e7ecd48cb729e3dca4aa2ea) Fix #4574: the managed runtime host leaves when its server exits on its own ### 📊 Changes **2 files changed** (+54 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `strata_control/runtime.py` (+31 -1) 📝 `tests/terminal/test_runtime.py` (+23 -0) </details> ### 📄 Description ## Problem and result A managed runtime host never watched the server it started. When that server exited - a crash, an external kill, an engine that stopped on its own - the host stayed in its accept loop with the profile's private state file and activity lease, and reported `state: failed` for ever. Every later `strata runtime start` / `strata launch` for that profile then refused with "this profile already has a live managed runtime", although nothing was serving, until a person killed a host PID that `runtime status` did not point at as the problem. After the change the host notices within about a second that its server has ended and leaves through the cleanup it already has: the private state file, the ready file, the child marker and the activity lease are released, so the next start recovers by itself. It first gives a client that was waiting for the failure two more seconds to read `failed` and the log tail. Reproduction on this checkout (Windows 11, Python 3.11.16), using the registered fake engine of `tests/terminal/test_runtime.py`: start the profile, kill the server child, then watch the host. Before the change the host was alive with `status_state=failed` at every 0.5 s step for 10 s and the private state file was still there; with the change the new case sees the host process end (one accept cycle plus the 2 s grace), the private state file gone and the next start ready. ## Related discussion #4574 - the report (host husks after its server child exits; profile locked until a manual kill). The issue expected the host to "log it and either restart (bounded) or tear down cleanly (release state lock, exit non-zero)"; this is the tear-down, which is the smaller change. #4824 - `strata launch` meets such a host after a long tune and refuses to start; removing the host removes that blocker (it is not the whole of #4824 - the launch-side handling of a host it finds is a separate change). ## Approach `strata_control/runtime.py`: - `Host.serve()` polls `self.child` at the top of its accept loop. An exit the host did not ask for is recorded once, and after a 2 s grace (so a client that was waiting for the failure can read `failed` + `log_tail`) the loop ends with exit status 1; the existing `finally` block then removes the state file, ready file, child marker, snapshots and the activity lease. - `_stop_child()` marks every stop the host itself asks for (a `stop`, a `restart`, the failed-probe stop), and `_launch()` clears the mark for a new child. So a restart, a deliberate stop and a failed generation probe behave exactly as before; only an unasked-for exit ends the host. ## Validation **Passed:** the new case fails on an unmodified checkout and passes with the change. With `strata_control/runtime.py` from `main` (everything else including the new test file unchanged): ```text python -m pytest tests/terminal/test_runtime.py -q -k "the_host_leaves" ... AssertionError: the owner host stays alive as a husk after its server child exits 1 failed, 1 error in 26.52s ``` The error is the teardown of the husk the case leaves behind in that run; the failure is the case itself. With the change: ```text python -m pytest tests/terminal/test_runtime.py -q -k "the_host_leaves" 1 passed in 15.70s ``` **Passed:** the whole file in CI. The branch's `tests/terminal/test_runtime.py` passes the "Linux / runtime requirements only" job (`tools/minimal_server_smoke.py`, which runs the whole file in a runtime-only venv), and the portable-monitor jobs on Windows and Ubuntu (Python 3.10 and 3.11) are green too (run 41294189141). **Failed:** none in CI. On this Windows machine a full run of the file has one pre-existing failure at teardown, `test_local_management_bridge_and_cli_share_owner_and_journal`: `PermissionError: [WinError 32] ... local.host.log`; the same failure appears on the unmodified tree (48 passed, 2 skipped, 1 failed before; 49 passed, 2 skipped, 1 failed with the new case). A later repeat of the whole file on this shared machine also produced a few unrelated `startup_wait_expired` timeouts; the CI run above is the stable measurement. **Not run:** a POSIX session by hand. The CI job above runs the whole file on Linux and passes, including the new case; the reproduction output pasted here and the full local runs are from Windows 11. A real `strata launch`/desktop session that loses its server child was not run either: the case drives the host with the same fake engine the rest of `test_runtime.py` uses. ## Limits - The host chooses to leave rather than to restart the server. Restarting a crashed engine automatically would hide the failure; the issue allows either. The recorded reason remains in `<profile>.host.log` and in `<profile>.server.log`. - A client that is polling the start gets the `failed` status during the 2 s grace. A client that asks for status after the host has left sees `stopped` (the record is gone), not `failed`. - A failed start (the server never became ready) is unchanged: the host still stays and reports `failed` with the log tail, because that is the only place a launcher reads the reason; that path is not an unasked-for exit. --- <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#5233
No description provided.