[PR #4018] [CLOSED] [GUI] Update and restart from the server's web page (strata update, then the same server again) #4877

Closed
opened 2026-11-07 16:31:03 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4018
Author: @elightcap
Created: 10/24/2026
Status: ❌ Closed

Base: main ← Head: serve-update-button


📝 Commits (1)

  • f2faca9 Web page: Update and restart (strata update from the server, then the same server again)

📊 Changes

6 files changed (+590 additions, -2 deletions)

View changed files

📝 docs/DETAILS.md (+12 -0)
➕ serve/self_update.py (+244 -0)
📝 serve/server.py (+46 -1)
➕ serve/test_self_update.py (+199 -0)
📝 serve/web/app.js (+77 -1)
📝 serve/web/index.html (+12 -0)

📄 Description

Problem and result

To update a running server today you go to a terminal: stop the server, run strata update, then start the server again with the same command and environment. For a server started by a script (run-<model>.sh with its own environment variables) that means finding and re-running that script.

With this change the server's web page has an Updates card on the About tab:

  • Check for updates runs strata update --check and shows what would change, for example "Engine: 0.1.47 → 0.1.48 (189 MiB download)". It reads the signed feed and changes nothing.
  • Update and restart:
    1. Stops taking new inference requests: 503 server_draining, the same as a draining server. Running requests get up to 5 minutes to finish.
    2. Unloads the model, so the update's test start has the GPU.
    3. Runs strata update --model-config <this server's run config>.
    4. If something was updated, the server stops the usual way (QUIT to the engine, MCP servers ended) and starts itself again in place with the command line, environment and folder it started with. The process ID stays the same, so a script waiting on it keeps running. The page reloads when the new instance answers.
  • If nothing changed or the update failed, the server takes requests again, the old version stays in use, and the card says why.

None for this design. #1266 (closed in the 0.2.0-beta tracker reset, not rejected) added a different engine-update card built on its own updater (serve/update.py, #1265), from before strata update existed. This one uses strata update, so the feed signature, the test start, rollback and the "takes effect after a test start" rules stay in one place.

Approach

  • serve/self_update.py holds the state behind GET /update and POST /update {"action": "check" | "install"}, runs strata, and does the restart (os.execve of sys.executable + sys.orig_argv, with the environment and folder recorded at the start of main()).
  • POST /update follows the same rules as /config: JSON from Strata's own page only (_own_page), behind the API key.
  • The card shows the buttons only when they can work: a server started directly on Linux or macOS, whose run config names "exe": "component:strata-engine", with strata on the PATH (or in ~/.local/bin) and no STRATA_NO_ACQUIRE. In every other case it shows the reason instead:
    • strata serve, strata launch or the app started it (main(argv), --owner-fd, --ready-file, a lifecycle sink);
    • Windows;
    • a hand-built exe, which strata update would not change.
  • The run config's exe is read before with_component_engine() swaps in the package folder. Read after the swap, the reference is gone.
  • The main loop now also ends on the updater's flag (while not svc.updater.restart_wanted), not only on Ctrl+C. Signalling the main thread would not work here: _thread.interrupt_main() does nothing when SIGINT is ignored, which is the case for a server started in the background (nohup ./run-<model>.sh &). The first version used it and the restart never happened in that setup.
  • Default path: with the button unused, the server behaves as before. The loop condition is a bool read once a second, the card makes no network request until clicked, and GET /update only reads state. The About tab does show one more card.

Validation

Passed:

  • python -m pytest serve/test_self_update.py, 8 tests (Linux, Python 3.13, this branch on origin/main 7dd5cf18). They use a fake strata that prints the real --check and --output jsonl formats, and cover:
    • the check;
    • an update, which drains with the run config passed to --model-config, then restarts, with 503 server_draining meanwhile;
    • nothing to update, after which the server serves again;
    • a failed update, with the reason shown, after which the server serves again;
    • a refused request: unsupported server, text/plain, foreign Origin, unknown action;
    • the reasons a server cannot update itself;
    • restart in place: same PID, argv, folder and starting environment, in a subprocess.
  • python -m pytest serve on this branch: 1026 passed, 15 skipped (the lifeline test below deselected). That run was before the last two small edits: closing the update's pipes, and the wording of the not-supported message. serve/test_self_update.py was run again after them and passes.
  • End to end with serve/server.py --engine mock, started in the background, with a fake strata on PATH, driven in headless Chromium: check, Update and restart, then the restart in place (same PID, new instance id, chat answers), the page reloads and shows an "Updated" toast.
  • On an RX 6900 XT box (Linux, HIP, engine package 0.1.47 rx6000, run-agents.sh with "exe": "component:strata-engine" and an API key on 0.0.0.0):
    • the card shows Check for updates;
    • the check lists engine 0.1.47 → 0.1.48;
    • without the API key the card says to enter it; before this fix it hid itself silently.

Failed:

  • serve/test_lifeline.py::Lifeline::test_the_portable_watcher_ends_the_child_when_the_server_is_killed fails on this machine with and without this change (checked with the change stashed). Not related.

Not run:

  • A real strata update that installs a new engine from the button on GPU hardware. The update and restart are tested with a fake strata; the real update's test start is strata update's own and is unchanged.
  • macOS: the restart in place is POSIX execve and should behave as on Linux, but it was not run there.
  • Windows: the card shows the "run strata update in a terminal" reason there; not run on Windows.
  • No C++/CUDA/HIP/SYCL/Metal file is touched.

Limits

  • While updating, inference gets 503 for a few minutes (download plus the model's test start). Clients that do not retry on 503 fail during that time.
  • A server started by strata serve, strata launch or the app does not get the button. Those would need their parent to do the restart.
  • An update that changes only the Terminal (Control) also restarts the server, which does nothing for a server run from a git checkout. A server that strata serve runs from the Terminal's own folder does not get the button anyway.
  • --port 0 would come back on a new port after the restart.

🤖 Generated with Claude Code

https://claude.ai/code/session_013gUv2Q9PHQERdYCFX4DUNm


🔄 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/4018 **Author:** [@elightcap](https://github.com/elightcap) **Created:** 10/24/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `serve-update-button` --- ### 📝 Commits (1) - [`f2faca9`](https://github.com/Niko1221/Strata/commit/f2faca91c37a361dc293df82361878f67e31d21d) Web page: Update and restart (strata update from the server, then the same server again) ### 📊 Changes **6 files changed** (+590 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `docs/DETAILS.md` (+12 -0) ➕ `serve/self_update.py` (+244 -0) 📝 `serve/server.py` (+46 -1) ➕ `serve/test_self_update.py` (+199 -0) 📝 `serve/web/app.js` (+77 -1) 📝 `serve/web/index.html` (+12 -0) </details> ### 📄 Description ## Problem and result To update a running server today you go to a terminal: stop the server, run `strata update`, then start the server again with the same command and environment. For a server started by a script (`run-<model>.sh` with its own environment variables) that means finding and re-running that script. With this change the server's web page has an **Updates** card on the About tab: - **Check for updates** runs `strata update --check` and shows what would change, for example "Engine: 0.1.47 → 0.1.48 (189 MiB download)". It reads the signed feed and changes nothing. - **Update and restart**: 1. Stops taking new inference requests: 503 `server_draining`, the same as a draining server. Running requests get up to 5 minutes to finish. 2. Unloads the model, so the update's test start has the GPU. 3. Runs `strata update --model-config <this server's run config>`. 4. If something was updated, the server stops the usual way (QUIT to the engine, MCP servers ended) and starts itself again in place with the command line, environment and folder it started with. The process ID stays the same, so a script waiting on it keeps running. The page reloads when the new instance answers. - If nothing changed or the update failed, the server takes requests again, the old version stays in use, and the card says why. ## Related discussion None for this design. #1266 (closed in the 0.2.0-beta tracker reset, not rejected) added a different engine-update card built on its own updater (`serve/update.py`, #1265), from before `strata update` existed. This one uses `strata update`, so the feed signature, the test start, rollback and the "takes effect after a test start" rules stay in one place. ## Approach - `serve/self_update.py` holds the state behind `GET /update` and `POST /update {"action": "check" | "install"}`, runs `strata`, and does the restart (`os.execve` of `sys.executable` + `sys.orig_argv`, with the environment and folder recorded at the start of `main()`). - `POST /update` follows the same rules as `/config`: JSON from Strata's own page only (`_own_page`), behind the API key. - The card shows the buttons only when they can work: a server started directly on Linux or macOS, whose run config names `"exe": "component:strata-engine"`, with `strata` on the PATH (or in `~/.local/bin`) and no `STRATA_NO_ACQUIRE`. In every other case it shows the reason instead: - `strata serve`, `strata launch` or the app started it (`main(argv)`, `--owner-fd`, `--ready-file`, a lifecycle sink); - Windows; - a hand-built `exe`, which `strata update` would not change. - The run config's `exe` is read before `with_component_engine()` swaps in the package folder. Read after the swap, the reference is gone. - The main loop now also ends on the updater's flag (`while not svc.updater.restart_wanted`), not only on Ctrl+C. Signalling the main thread would not work here: `_thread.interrupt_main()` does nothing when SIGINT is ignored, which is the case for a server started in the background (`nohup ./run-<model>.sh &`). The first version used it and the restart never happened in that setup. - Default path: with the button unused, the server behaves as before. The loop condition is a bool read once a second, the card makes no network request until clicked, and `GET /update` only reads state. The About tab does show one more card. ## Validation **Passed:** - `python -m pytest serve/test_self_update.py`, 8 tests (Linux, Python 3.13, this branch on `origin/main` 7dd5cf18). They use a fake `strata` that prints the real `--check` and `--output jsonl` formats, and cover: - the check; - an update, which drains with the run config passed to `--model-config`, then restarts, with 503 `server_draining` meanwhile; - nothing to update, after which the server serves again; - a failed update, with the reason shown, after which the server serves again; - a refused request: unsupported server, `text/plain`, foreign `Origin`, unknown action; - the reasons a server cannot update itself; - restart in place: same PID, argv, folder and starting environment, in a subprocess. - `python -m pytest serve` on this branch: 1026 passed, 15 skipped (the lifeline test below deselected). That run was before the last two small edits: closing the update's pipes, and the wording of the not-supported message. `serve/test_self_update.py` was run again after them and passes. - End to end with `serve/server.py --engine mock`, started in the background, with a fake `strata` on PATH, driven in headless Chromium: check, Update and restart, then the restart in place (same PID, new instance id, chat answers), the page reloads and shows an "Updated" toast. - On an RX 6900 XT box (Linux, HIP, engine package 0.1.47 rx6000, `run-agents.sh` with `"exe": "component:strata-engine"` and an API key on 0.0.0.0): - the card shows Check for updates; - the check lists engine 0.1.47 → 0.1.48; - without the API key the card says to enter it; before this fix it hid itself silently. **Failed:** - `serve/test_lifeline.py::Lifeline::test_the_portable_watcher_ends_the_child_when_the_server_is_killed` fails on this machine with and without this change (checked with the change stashed). Not related. **Not run:** - A real `strata update` that installs a new engine from the button on GPU hardware. The update and restart are tested with a fake `strata`; the real update's test start is `strata update`'s own and is unchanged. - macOS: the restart in place is POSIX `execve` and should behave as on Linux, but it was not run there. - Windows: the card shows the "run `strata update` in a terminal" reason there; not run on Windows. - No C++/CUDA/HIP/SYCL/Metal file is touched. ## Limits - While updating, inference gets 503 for a few minutes (download plus the model's test start). Clients that do not retry on 503 fail during that time. - A server started by `strata serve`, `strata launch` or the app does not get the button. Those would need their parent to do the restart. - An update that changes only the Terminal (Control) also restarts the server, which does nothing for a server run from a git checkout. A server that `strata serve` runs from the Terminal's own folder does not get the button anyway. - `--port 0` would come back on a new port after the restart. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_013gUv2Q9PHQERdYCFX4DUNm --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 16:31:03 +07:00
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#4877
No description provided.