Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.
TypeScript browser-shellcontrol-planefile-managerhomelabmobile-firstnextjsptyreactself-hostedserver-managementshadcn-uisysadmintailwindcssterminaltypescriptvpsweb-desktopweb-terminal
fix(update): reject unowned live runtimes
Rahman3643789758d9
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.mdindex 8e5fad9d..4b94e473 100644--- a/docs/CHANGELOG.md+++ b/docs/CHANGELOG.md@@ -13,6 +13,7 @@ this is the *what*, and it is what Settings → About shows as “What's new”.**Fixed**+- `update` reject unowned live runtimes- `runtime` verify live update identities- `runtime` close final update web edges- `update` emit success after runtime restorediff --git a/docs/INSTALL.md b/docs/INSTALL.mdindex 362fee96..401da4a6 100644--- a/docs/INSTALL.md+++ b/docs/INSTALL.md@@ -447,7 +447,10 @@ The updater verifies the incoming checkout/build before replacing the service. Wthat invoked `mso update`; a secondary clone is never allowed to restart an unrelated live service.The updater then runs outside that service cgroup so it survives the restart. With no activeservice (including WSL without systemd), it performs the clean fast-forward/dependency/verify/build-path locally. Before either the service-active or offline in-place build, update inventories every gateway state for the canonical checkout, quiesces each verified owned fallback runtime, leaves active tunnel identities intact, rebuilds, then restores every previously-owned origin. A+path locally. Before an offline build mutates dependencies or `.next`, MSO also verifies the selected+loopback origin is either down or represented by gateway-owned lifecycle state; a manually started or+otherwise unowned healthy MSO runtime is refused and must be stopped first. Before either the+service-active or offline in-place build, update inventories every gateway state for the canonical checkout, quiesces each verified owned fallback runtime, leaves active tunnel identities intact, rebuilds, then restores every previously-owned origin. Acheckout-scoped private deployment receipt and restart marker mean a dependency/build failure afterGit already reached `origin/main` is retried by the next ordinary `mso update` instead of beingmislabeled "already up to date". The state is keyed by canonical checkout path, so two clones at thediff --git a/docs/TROUBLESHOOTING.md b/docs/TROUBLESHOOTING.mdindex d274dbbf..752f603f 100644--- a/docs/TROUBLESHOOTING.md+++ b/docs/TROUBLESHOOTING.md@@ -47,6 +47,13 @@ This is a safety refusal. A machine may contain multiple MSO clones, but an actione canonical `WorkingDirectory`. Run the update from that checkout (normally the directory targetedby the installer) instead of letting a secondary clone rebuild itself and restart someone else's unit.+### `mso update` says the selected loopback runtime is not safely update-owned++MSO found a healthy loopback responder while `mso.service` is inactive, but that process is not+recorded as a gateway-owned fallback runtime. This is commonly a manual `bun run start`/`next start`.+Stop that manual runtime first, then rerun `mso update`. MSO refuses here before dependency or `.next`+mutation rather than rebuilding underneath a process that is actively serving the old build.+### `mso gateway start` says an offline update is mutating this checkoutThis is an intentional safety exclusion. Every in-place `mso update` (service-active or offline) holds the checkout-wide runtime lock while `.next` can change, so `mso web`, onboarding fallback, and gateway runtime recovery cannot startdiff --git a/scripts/gateway-stop-identity.test.ts b/scripts/gateway-stop-identity.test.tsindex 1769cb41..5a2eebcd 100644--- a/scripts/gateway-stop-identity.test.ts+++ b/scripts/gateway-stop-identity.test.ts@@ -4,32 +4,36 @@ import { describe, expect, it } from "vitest";const COMMON = path.join(process.cwd(), "scripts/lib/gateway-common.sh");-function run(body: string) {- return spawnSync("bash", ["-c", `set -euo pipefail-source ${JSON.stringify(COMMON)}-${body}`], { encoding: "utf8" });-}-describe("gateway_stop_identity", () => {it("fails closed when the same process identity survives SIGKILL", () => {- const result = run(`+ const result = spawnSync("bash", [+ "-c",+ `set -euo pipefail+source "$1"gateway_identity_matches() { return 0; }kill() { return 0; }sleep() { :; }-gateway_stop_identity '{"pid":4242}'-`);+gateway_stop_identity '{"pid":4242}'`,+ "gateway-stop-test",+ COMMON,+ ], { encoding: "utf8" });expect(result.status).not.toBe(0);expect(result.stderr).toContain("survived SIGKILL; preserving lifecycle state");});it("succeeds once the recorded identity disappears", () => {- const result = run(`+ const result = spawnSync("bash", [+ "-c",+ `set -euo pipefail+source "$1"checks=0gateway_identity_matches() { checks=$((checks+1)); [ "$checks" -lt 3 ]; }kill() { return 0; }sleep() { :; }-gateway_stop_identity '{"pid":4242}'-`);+gateway_stop_identity '{"pid":4242}'`,+ "gateway-stop-test",+ COMMON,+ ], { encoding: "utf8" });expect(result.status).toBe(0);});});diff --git a/scripts/lib/gateway-runtime.sh b/scripts/lib/gateway-runtime.shindex db4522b0..b4eb84ba 100644--- a/scripts/lib/gateway-runtime.sh+++ b/scripts/lib/gateway-runtime.sh@@ -14,7 +14,6 @@ gateway_runtime_from_state() {RUNTIME_IDENTITY="$identity"; RUNTIME_INSTANCE_ID="$instance"; RUNTIME_OWNED=truefi}-gateway_start_runtime_if_needed() {local next host port pid identity instance node_exe current_exe i parent_ticks gate[ "$RUNTIME_OWNED" = true ] && gateway_health_url_ok "$LOCAL_URL" "$RUNTIME_INSTANCE_ID" && return 0@@ -123,6 +122,23 @@ gateway_persist_quiesced_state() {gateway_write_state "$provider" "$mode" "$url" "$tunnel"}+gateway_cmd_runtime_assert_update_safe_locked() {+ local state runtime owned+ state="$(gateway_state_read)"+ runtime="$(jq -c '.runtimeIdentity // null' <<<"$state")"+ owned="$(jq -r '.runtimeOwned // false' <<<"$state")"+ # A recorded owned runtime is handled by the subsequent checkout-wide quiesce+ # inventory. Do not stop anything here: this command is intentionally read-only.+ if [ "$owned" = true ] && [ "$runtime" != null ]; then+ gateway_info "runtime: update-owned"+ return 0+ fi+ if gateway_health_ok; then+ gateway_fail "a loopback MSO runtime is active but is not gateway-owned; stop it before an offline update"+ fi+ gateway_info "runtime: update-safe"+}+gateway_cmd_runtime_stop_locked() {local state runtime ownedgateway_recovery_marker_path >/dev/nulldiff --git a/scripts/lib/update-gateway-runtimes.sh b/scripts/lib/update-gateway-runtimes.shindex 22632dd2..28c62e81 100755--- a/scripts/lib/update-gateway-runtimes.sh+++ b/scripts/lib/update-gateway-runtimes.sh@@ -61,6 +61,14 @@ update_gateway_write_restore_urls() {|| fail "could not persist gateway restore inventory"}+update_gateway_assert_offline_selected_origin_safe() {+ local selected+ selected="${LOCAL_URL:-${MSO_GATEWAY_LOCAL_URL:-http://127.0.0.1:${MSO_PORT:-4005}}}"+ MSO_GATEWAY_ROOT="$ROOT" MSO_GATEWAY_ENV="$ROOT/.env.local" MSO_GATEWAY_LOCAL_URL="$selected" \+ "$GATEWAY" runtime-assert-update-safe >/dev/null \+ || fail "selected loopback runtime is active but not safely update-owned; stop it before offline update"+}+update_gateway_quiesce_all() {local url out collectedlocal -a urls=()diff --git a/scripts/mso-gateway b/scripts/mso-gatewayindex a2e4a6c3..d318f19d 100755--- a/scripts/mso-gateway+++ b/scripts/mso-gateway@@ -90,6 +90,7 @@ case "${1:-status}" indomain) shift; gateway_cmd_domain "$@" ;;web) gateway_cmd_web "$@" ;;local-start) gateway_with_lock gateway_with_runtime_shared gateway_cmd_local_start_locked ;; # internal: onboard/web/update fallback+ runtime-assert-update-safe) gateway_with_lock gateway_cmd_runtime_assert_update_safe_locked ;; # internal: read-only offline-build preflightruntime-stop) gateway_with_lock gateway_cmd_runtime_stop_locked ;; # internal: quiesce owned runtime before offline build*) gateway_fail "usage: mso gateway start|stop|status|url|doctor|install|domain ..." ;;esacdiff --git a/scripts/mso-gateway-update-safety.test.ts b/scripts/mso-gateway-update-safety.test.tsnew file mode 100644index 00000000..06c3b1b0--- /dev/null+++ b/scripts/mso-gateway-update-safety.test.ts@@ -0,0 +1,14 @@+import { spawnSync } from "node:child_process";+import { afterEach, describe, expect, it } from "vitest";+import { GATEWAY, cleanupGatewayFixtures, fixture } from "./mso-gateway-test-fixture";++afterEach(cleanupGatewayFixtures);++describe("gateway offline-update safety assertion", () => {+ it("rejects a healthy selected MSO responder that has no gateway ownership state", () => {+ const f = fixture();+ const out = spawnSync(GATEWAY, ["runtime-assert-update-safe"], { env: f.baseEnv, encoding: "utf8" });+ expect(out.status).not.toBe(0);+ expect(out.stderr).toContain("active but is not gateway-owned; stop it before an offline update");+ });+});diff --git a/scripts/mso-update b/scripts/mso-updateindex 8ce9dfc7..1e99ca7f 100755--- a/scripts/mso-update+++ b/scripts/mso-update@@ -65,7 +65,7 @@ require_service_checkout() {|| fail "active mso.service belongs to $canonical_service, not this checkout $canonical_root; run update from the service checkout"}-quiesce_offline_runtime() { update_gateway_quiesce_all; }+quiesce_offline_runtime() { update_gateway_assert_offline_selected_origin_safe; update_gateway_quiesce_all; }restore_offline_runtime() { update_gateway_restore_all; }diff --git a/scripts/mso-update.test.ts b/scripts/mso-update.test.tsindex aea2bc69..4ccf91a9 100644--- a/scripts/mso-update.test.ts+++ b/scripts/mso-update.test.ts@@ -11,7 +11,6 @@ const RUNTIME_EXCLUSION = path.join(process.cwd(), "scripts/lib/runtime-exclusioconst UPDATE_GATEWAYS = path.join(process.cwd(), "scripts/lib/update-gateway-runtimes.sh");const SERVICE_UPDATE = path.join(process.cwd(), "scripts/mso-service-update");const roots: string[] = [];-function git(cwd: string, ...args: string[]) { return execFileSync("git", args, { cwd, encoding: "utf8" }).trim(); }function fixture(options: { failInstallOnce?: boolean; activeService?: "same" | "other"; installDelayMs?: number } = {}) {const root = fs.mkdtempSync(path.join(os.tmpdir(), "mso-update-")); roots.push(root);@@ -27,6 +26,12 @@ function fixture(options: { failInstallOnce?: boolean; activeService?: "same" |fs.writeFileSync(path.join(repo, "scripts/mso-gateway"), `#!/bin/shprintf 'gateway %s %s\\n' "$*" "\${MSO_GATEWAY_LOCAL_URL:-}" >> "${capture}"case "$1" in+ runtime-assert-update-safe)+ if [ "\${MSO_TEST_UNOWNED_RUNTIME:-0}" = 1 ]; then+ echo 'mso gateway: a loopback MSO runtime is active but is not gateway-owned; stop it before an offline update' >&2+ exit 31+ fi+ echo 'runtime: update-safe' ;;runtime-stop)[ -n "\${MSO_GATEWAY_RECOVERY_MARKER:-}" ] || exit 9mkdir -p "$(dirname "\$MSO_GATEWAY_RECOVERY_MARKER")"@@ -112,6 +117,18 @@ describe("mso update without a running web API", () => {expect(status).not.toContain("deployment verification/restart is pending");});+ it("refuses an offline build before dependency or .next mutation when the selected origin is unowned", () => {+ const f = fixture();+ fs.rmSync(path.join(f.home, ".mso/private/gateway"), { recursive: true, force: true });+ const out = spawnSync(SCRIPT, [], { env: { ...f.env, MSO_TEST_UNOWNED_RUNTIME: "1" }, encoding: "utf8" });+ expect(out.status).not.toBe(0);+ expect(out.stderr).toContain("selected loopback runtime is active but not safely update-owned");+ const calls = fs.existsSync(f.capture) ? fs.readFileSync(f.capture, "utf8") : "";+ expect(calls).toContain("runtime-assert-update-safe");+ expect(calls).not.toContain("bun install");+ expect(calls).not.toContain("node node_modules/next/dist/bin/next build");+ });+it("refuses update handoff when the active mso.service belongs to another checkout", () => {const f = fixture({ activeService: "other" });const out = require("node:child_process").spawnSync(SCRIPT, [], { env: f.env, encoding: "utf8" });