[PR #4896] [Engine] update: a lost runtime record is recovered instead of refusing with a model is running (Fix #3977, #4872) #5236

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

📋 Pull Request Information

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

Base: main ← Head: fix/update-recovers-a-lost-runtime-record


📝 Commits (2)

  • 671dfa0 Fix #3977 #4872: a lost managed-runtime record is not a model that is running
  • 980fd48 Read the record's state again before recovering it

📊 Changes

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

View changed files

📝 strata_control/updater.py (+35 -3)
➕ tests/terminal/test_serving_stale.py (+77 -0)

📄 Description

Problem and result

A managed-runtime record whose owner host is gone is not a model that is running. runtime.active_managed_instances()
reports such a record as state: stale (the host's lease is not held), but updater.serving_now() returned every
non-stopped record, stale ones included. strata update therefore refused with "a model is running, so nothing was
changed" although nothing was loaded - for as long as the leftover record stayed, and the app told the person to unload a
model they had never loaded.

After the change serving_now() recovers a stale record with the same path strata runtime stop uses - the recorded
server and engine are verified by PID, start time and command line before anything is ended, then the private state is
cleared - and only reports what cannot be cleared (a record whose recorded child is still there, so an engine may really
be serving). A starting or ready instance is reported exactly as before.

Reproduction (Windows 11, Python 3.11.16, a private state file written into a temporary runtime folder, no model and no
GPU involved):

runtime.status("app-1"): {'ok': False, 'profile': 'app-1', 'state': 'stale', 'error': 'owner_host_lost', ...}
updater.serving_now():   [{'profile': 'app-1', 'state': 'stale'}]          # before
updater.serving_now():   []                                               # after, and status is "stopped"

This is the same leftover record, and the same serving_now() result, that #3977's follow-up comment captured on a
desktop (state: stale, serving_now() returning [{"profile": "app-1", "state": "stale"}], and the verified workaround
runtime.stop("app-1") clearing it).

#3977 - the report and the maintainer's "check Task Manager next time" reply; its 2026-11-01 follow-up captures the exact
stale-record state and serving_now() result above, and asks whether the update path could safely recover stale records
before deciding an engine is serving. This does that.
#4872 - the newer report of the same false "a model is running" message with no model loaded (screenshot of the desktop).

Approach

strata_control/updater.py:

  • serving_now() keeps every managed instance except the stale ones in the answer, as before, and returns them when
    there is one (a starting server is using the card, a ready one is serving).
  • If the only records are stale, each is recovered with runtime.stop(profile), which is the existing lost-host path:
    _stop_lost ends only processes that exactly match the record (PID, start time, command line), refuses while a
    recorded child is still present, and clears state, marker and snapshots. The record's state is read once more first, so
    a host that came back between the list and the recovery is reported rather than stopped. A record that cannot be
    recovered is reported, so a lost owner with a live child never gets treated as "nothing is serving".
  • The shared-lease check that follows is unchanged: a real strata serve (no managed record) is still reported.

Validation

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

python -m pytest tests/terminal/test_serving_stale.py -q
... AssertionError: - [{'profile': 'app-1', 'state': 'stale'}] + []
1 failed, 2 passed in 0.36s

With the change:

python -m pytest tests/terminal/test_serving_stale.py -q
3 passed in 0.20s

The three cases are: a real stale record on disk is recovered and serving_now() is empty, and the record is stopped
afterwards (not merely ignored); a starting/ready managed instance is still reported; a stale record whose child is
still there (the recovery refusal) is still reported as serving.

Passed: python -m pytest tests/terminal/test_updater.py tests/terminal/test_update_feed.py tests/terminal/test_calibration.py -q
on this checkout (Windows 11, Python 3.11.16): 119 passed, 4 skipped, 27 subtests passed.

Failed: none.

Not run: a real desktop engine update after a stale-record recovery (#3977's follow-up verified the manual-workaround
version of that); a POSIX lost owner with a live orphan child (the refusal branch is pinned with a mocked runtime.stop,
not with a real orphan). No GPU or model was involved, which is the point of the report.

Limits

  • Only stale records are recovered. A live host that reports failed (its server child exited) is still counted as
    serving, because it still holds the profile's lease and state; how a failed host releases them is #4574.
  • The recovery is the runtime.stop path, so it can take as long as that path takes for the recorded leftovers to be
    verified and ended. If it cannot verify a process it leaves everything alone and the update is still refused.
  • serving_now() now has a side effect (it may clear a lost host's record). Callers that only wanted to look -
    strata update --check does not use it - should note that a stale record is no longer reported.

🔄 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/4896 **Author:** [@XiaoBinGan](https://github.com/XiaoBinGan) **Created:** 11/1/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/update-recovers-a-lost-runtime-record` --- ### 📝 Commits (2) - [`671dfa0`](https://github.com/Niko1221/Strata/commit/671dfa01312a49d0d3358c364986cf5930fcfd00) Fix #3977 #4872: a lost managed-runtime record is not a model that is running - [`980fd48`](https://github.com/Niko1221/Strata/commit/980fd48d28a2dcb00492a4cd85c5f081f385337c) Read the record's state again before recovering it ### 📊 Changes **2 files changed** (+112 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `strata_control/updater.py` (+35 -3) ➕ `tests/terminal/test_serving_stale.py` (+77 -0) </details> ### 📄 Description ## Problem and result A managed-runtime record whose owner host is gone is not a model that is running. `runtime.active_managed_instances()` reports such a record as `state: stale` (the host's lease is not held), but `updater.serving_now()` returned every non-stopped record, stale ones included. `strata update` therefore refused with "a model is running, so nothing was changed" although nothing was loaded - for as long as the leftover record stayed, and the app told the person to unload a model they had never loaded. After the change `serving_now()` recovers a stale record with the same path `strata runtime stop` uses - the recorded server and engine are verified by PID, start time and command line before anything is ended, then the private state is cleared - and only reports what cannot be cleared (a record whose recorded child is still there, so an engine may really be serving). A `starting` or `ready` instance is reported exactly as before. Reproduction (Windows 11, Python 3.11.16, a private state file written into a temporary runtime folder, no model and no GPU involved): ```text runtime.status("app-1"): {'ok': False, 'profile': 'app-1', 'state': 'stale', 'error': 'owner_host_lost', ...} updater.serving_now(): [{'profile': 'app-1', 'state': 'stale'}] # before updater.serving_now(): [] # after, and status is "stopped" ``` This is the same leftover record, and the same `serving_now()` result, that #3977's follow-up comment captured on a desktop (`state: stale`, `serving_now()` returning `[{"profile": "app-1", "state": "stale"}]`, and the verified workaround `runtime.stop("app-1")` clearing it). ## Related discussion #3977 - the report and the maintainer's "check Task Manager next time" reply; its 2026-11-01 follow-up captures the exact stale-record state and `serving_now()` result above, and asks whether the update path could safely recover stale records before deciding an engine is serving. This does that. #4872 - the newer report of the same false "a model is running" message with no model loaded (screenshot of the desktop). ## Approach `strata_control/updater.py`: - `serving_now()` keeps every managed instance except the `stale` ones in the answer, as before, and returns them when there is one (a `starting` server is using the card, a `ready` one is serving). - If the only records are `stale`, each is recovered with `runtime.stop(profile)`, which is the existing lost-host path: `_stop_lost` ends only processes that exactly match the record (PID, start time, command line), refuses while a recorded child is still present, and clears state, marker and snapshots. The record's state is read once more first, so a host that came back between the list and the recovery is reported rather than stopped. A record that cannot be recovered is reported, so a lost owner with a live child never gets treated as "nothing is serving". - The shared-lease check that follows is unchanged: a real `strata serve` (no managed record) is still reported. ## Validation **Passed:** the new test fails on an unmodified `strata_control/updater.py` and passes with the change. With `updater.py` from `main` (everything else unchanged): ```text python -m pytest tests/terminal/test_serving_stale.py -q ... AssertionError: - [{'profile': 'app-1', 'state': 'stale'}] + [] 1 failed, 2 passed in 0.36s ``` With the change: ```text python -m pytest tests/terminal/test_serving_stale.py -q 3 passed in 0.20s ``` The three cases are: a real stale record on disk is recovered and `serving_now()` is empty, and the record is `stopped` afterwards (not merely ignored); a `starting`/`ready` managed instance is still reported; a stale record whose child is still there (the recovery refusal) is still reported as serving. **Passed:** `python -m pytest tests/terminal/test_updater.py tests/terminal/test_update_feed.py tests/terminal/test_calibration.py -q` on this checkout (Windows 11, Python 3.11.16): 119 passed, 4 skipped, 27 subtests passed. **Failed:** none. **Not run:** a real desktop engine update after a stale-record recovery (#3977's follow-up verified the manual-workaround version of that); a POSIX lost owner with a live orphan child (the refusal branch is pinned with a mocked `runtime.stop`, not with a real orphan). No GPU or model was involved, which is the point of the report. ## Limits - Only `stale` records are recovered. A live host that reports `failed` (its server child exited) is still counted as serving, because it still holds the profile's lease and state; how a failed host releases them is #4574. - The recovery is the `runtime.stop` path, so it can take as long as that path takes for the recorded leftovers to be verified and ended. If it cannot verify a process it leaves everything alone and the update is still refused. - `serving_now()` now has a side effect (it may clear a lost host's record). Callers that only wanted to look - `strata update --check` does not use it - should note that a stale record is no longer reported. --- <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#5236
No description provided.