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): treat a proven service-owned listener as update-safe
Abdurrahman Fakhrulb03afac24dcf
diff --git a/docs/INSTALL.md b/docs/INSTALL.mdindex 2598f20d..aa5e94ef 100644--- a/docs/INSTALL.md+++ b/docs/INSTALL.md@@ -630,7 +630,13 @@ The updater then runs outside that service cgroup so it survives the restart. Wiservice (including WSL without systemd), it performs the clean fast-forward/dependency/verify/buildpath locally. Before an offline build mutates dependencies or `.next`, MSO also verifies the selectedloopback 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+otherwise unowned healthy MSO runtime is refused and must be stopped first. The service-active+quiesce path additionally treats a healthy listener that is *proven* to be this checkout's own active+`mso.service` as update-safe (`runtime: service-owned`): that listener is not a fallback runtime, the+service lifecycle keeps it, and `scripts/self-update.sh` replaces it by signalling its same-UID MainPID,+so there is nothing to quiesce and an interrupted service update can be retried instead of dead-ending on+stale restore inventory. The offline preflight keeps the strict form and still refuses any listener that+is not proven to belong to this checkout's unit. Before either theservice-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 with the exact env-file identity recorded for that fallback. Older owned state that predates env identity is refused before the runtime is stopped; run the same `mso --env ... web`/gateway path once to migrate it safely. 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 beingdiff --git a/scripts/lib/gateway-runtime.sh b/scripts/lib/gateway-runtime.shindex e6fca312..5b9be897 100644--- a/scripts/lib/gateway-runtime.sh+++ b/scripts/lib/gateway-runtime.sh@@ -186,6 +186,13 @@ gateway_cmd_runtime_assert_update_safe_locked() {gateway_info "runtime: update-safe"}+# The proof for a service-owned listener stays strict; this seam exists only so the+# update path can be exercised in tests without owning a real unit.+gateway_service_owned_or_test_allowed() {+ gateway_service_owns_local_listener && return 0+ [ "${NODE_ENV:-}" = test ] && [ -n "${MSO_GATEWAY_TEST_SERVICE_LISTENER:-}" ]+}+gateway_cmd_runtime_stop_locked() {local state runtime ownedgateway_recovery_marker_path >/dev/null@@ -214,6 +221,15 @@ gateway_cmd_runtime_stop_locked() {gateway_fail "recorded runtime ownership no longer matches a safely recoverable MSO instance; refusing offline rebuild"fiif gateway_health_ok; then+ # A healthy loopback listener proven to be THIS checkout's own mso.service is not a+ # fallback runtime: the service lifecycle keeps it through the build and+ # scripts/self-update.sh replaces it by signalling its same-UID MainPID, so there is+ # nothing to quiesce. Any listener not proven to be this checkout's unit still fails+ # closed below, and the offline preflight (runtime-assert-update-safe) stays strict.+ if gateway_service_owned_or_test_allowed; then+ gateway_info "runtime: service-owned"+ return 0+ figateway_fail "a loopback MSO runtime is active but is not gateway-owned; stop it before an offline update"fiif gateway_recovery_pending; then gateway_info "runtime: recovery-pending"; else gateway_info "runtime: already-down"; fidiff --git a/scripts/lib/update-gateway-runtimes.sh b/scripts/lib/update-gateway-runtimes.shindex 052706a8..2bb98140 100755--- a/scripts/lib/update-gateway-runtimes.sh+++ b/scripts/lib/update-gateway-runtimes.sh@@ -115,7 +115,7 @@ update_gateway_quiesce_all() {for entry in "${entries[@]}"; doout="$(update_gateway_entry_call runtime-stop "$entry")" || fail "could not safely quiesce gateway runtime at $(jq -r .url <<<"$entry")"case "$out" in- *'runtime: stopped-owned'*|*'runtime: recovered-stale-owned'*|*'runtime: recovery-pending'*|*'runtime: already-down'*) ;;+ *'runtime: stopped-owned'*|*'runtime: recovered-stale-owned'*|*'runtime: recovery-pending'*|*'runtime: already-down'*|*'runtime: service-owned'*) ;;*) fail "unexpected gateway runtime-stop result for $(jq -r .url <<<"$entry")" ;;esacdonediff --git a/scripts/mso-gateway-service-owned.test.ts b/scripts/mso-gateway-service-owned.test.tsnew file mode 100644index 00000000..9dd7e4d5--- /dev/null+++ b/scripts/mso-gateway-service-owned.test.ts@@ -0,0 +1,45 @@+import { spawnSync } from "node:child_process";+import fs from "node:fs";+import path from "node:path";+import { describe, expect, it } from "vitest";+import { GATEWAY, fixture } from "./mso-gateway-test-fixture";++// `runtime-stop` is the internal quiesce step an in-place update calls for every+// inventoried origin. A healthy loopback listener that is proven to be THIS+// checkout's own mso.service is not a fallback runtime and must not dead-end the+// update; anything unproven must still fail closed.+function stopEnv(f: ReturnType<typeof fixture>, extra: Record<string, string> = {}) {+ const marker = path.join(f.dir, "restart-runtime");+ fs.writeFileSync(marker, "");+ return { ...f.baseEnv, MSO_GATEWAY_RECOVERY_MARKER: marker, ...extra };+}++describe("gateway update quiesce with a service-owned listener", () => {+ it("fails closed when the healthy responder is not proven to be this checkout's unit", () => {+ const f = fixture();+ const out = spawnSync(GATEWAY, ["runtime-stop"], { env: stopEnv(f), encoding: "utf8" });+ expect(out.status).not.toBe(0);+ expect(out.stderr).toContain("active but is not gateway-owned; stop it before an offline update");+ expect(out.stderr).not.toContain("runtime: service-owned");+ });++ it("reports runtime: service-owned and succeeds when the listener is proven to be the checkout's mso.service", () => {+ const f = fixture();+ const out = spawnSync(GATEWAY, ["runtime-stop"], {+ env: stopEnv(f, { NODE_ENV: "test", MSO_GATEWAY_TEST_SERVICE_LISTENER: "1" }),+ encoding: "utf8",+ });+ expect(out.status).toBe(0);+ expect(`${out.stdout}${out.stderr}`).toContain("runtime: service-owned");+ });++ it("keeps the offline preflight strict even when the quiesce seam is enabled", () => {+ const f = fixture();+ const out = spawnSync(GATEWAY, ["runtime-assert-update-safe"], {+ env: stopEnv(f, { NODE_ENV: "test", MSO_GATEWAY_TEST_SERVICE_LISTENER: "1" }),+ 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-service-update.test.ts b/scripts/mso-service-update.test.tsindex a15735e2..284dc9e1 100644--- a/scripts/mso-service-update.test.ts+++ b/scripts/mso-service-update.test.ts@@ -29,7 +29,7 @@ function state(home: string, name: string, root: string, localUrl: string, envFifs.writeFileSync(path.join(dir, "state.json"), `${JSON.stringify({ root, localUrl, runtimeOwned, envFile: envIdentity(envFile) })}\n`, { mode: 0o600 });}-function fixture(delayMs = 0, failRestoreUrl = "") {+function fixture(delayMs = 0, failRestoreUrl = "", stopToken = "runtime: stopped-owned") {const base = fs.mkdtempSync(path.join(os.tmpdir(), "mso-service-update-")); roots.push(base);const repo = path.join(base, "repo"), home = path.join(base, "home"), capture = path.join(base, "capture");fs.mkdirSync(path.join(repo, "scripts/lib"), { recursive: true }); fs.mkdirSync(home);@@ -37,7 +37,7 @@ function fixture(delayMs = 0, failRestoreUrl = "") {copy(repo, "scripts/lib/runtime-exclusion.sh", RUNTIME_EXCLUSION); copy(repo, "scripts/lib/update-gateway-runtimes.sh", UPDATE_GATEWAYS);fs.writeFileSync(path.join(repo, "scripts/mso-gateway"), `#!/bin/shprintf '%s %s env=%s expected=%s\n' "$1" "\${MSO_GATEWAY_LOCAL_URL:-}" "\${MSO_GATEWAY_ENV:-}" "\${MSO_GATEWAY_EXPECT_ENV_IDENTITY:-}" >> ${JSON.stringify(capture)}-if [ "$1" = runtime-stop ]; then printf '1\n' > "$MSO_GATEWAY_RECOVERY_MARKER"; chmod 600 "$MSO_GATEWAY_RECOVERY_MARKER"; echo 'runtime: stopped-owned'; exit 0; fi+if [ "$1" = runtime-stop ]; then printf '1\n' > "$MSO_GATEWAY_RECOVERY_MARKER"; chmod 600 "$MSO_GATEWAY_RECOVERY_MARKER"; echo ${JSON.stringify(stopToken)}; exit 0; fi[ "$1" = local-start ] && { [ "${failRestoreUrl}" = "\${MSO_GATEWAY_LOCAL_URL:-}" ] && exit 31; exit 0; }exit 2`, { mode: 0o755 });@@ -147,6 +147,20 @@ describe("service-active update lifecycle", () => {expect(fs.existsSync(f.capture) ? fs.readFileSync(f.capture, "utf8") : "").not.toContain("self-start");});+ it("accepts a service-owned quiesce result and clears the restore inventory", () => {+ const f = fixture(0, "", "runtime: service-owned");+ const key = createHash("sha256").update(fs.realpathSync(f.repo)).digest("hex");+ const dir = path.join(f.base, "update-state", key); fs.mkdirSync(dir, { recursive: true, mode: 0o700 });+ fs.chmodSync(path.join(f.base, "update-state"), 0o700);+ fs.writeFileSync(path.join(dir, "gateway-runtimes.json"),+ `${JSON.stringify([{ url: "http://127.0.0.1:4999", envFile: envIdentity(f.envOne) }])}\n`, { mode: 0o600 });+ const out = spawnSync(WRAPPER, [], { env: f.env, encoding: "utf8" });+ expect(out.status).toBe(0);+ const calls = fs.readFileSync(f.capture, "utf8");+ expect(calls).toContain("runtime-stop http://127.0.0.1:4999");+ expect(fs.existsSync(path.join(dir, "gateway-runtimes.json"))).toBe(false);+ });+it("serializes two synchronous service updates under the same checkout transaction lock", async () => {const f = fixture(450); const first = runAsync(f.env); await new Promise((r) => setTimeout(r, 60)); const second = runAsync(f.env);const [a, b] = await Promise.all([first, second]); expect(a.code).toBe(0); expect(b.code).toBe(0);