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(runtime): verify service readiness before handoff
Rahman712ab5408dc8
diff --git a/bin/mso b/bin/msoindex 3a338195..114e0e75 100755--- a/bin/mso+++ b/bin/mso@@ -209,6 +209,24 @@ service_unit_local_url() {printf 'http://127.0.0.1:%s' "$port"}+service_wait_ready() {+ local base="$1" attempts="${MSO_SERVICE_HEALTH_ATTEMPTS:-40}" expected_version body i curl_bin="${MSO_CURL_BIN:-curl}"+ [[ "$attempts" =~ ^[0-9]+$ ]] && [ "$attempts" -ge 1 ] && [ "$attempts" -le 120 ] || attempts=40+ expected_version="$(jq -r '.version // empty' "$ROOT/package.json" 2>/dev/null || true)"+ [ -n "$expected_version" ] || return 1+ for ((i = 1; i <= attempts; i++)); do+ body="$("$curl_bin" --noproxy '*' -fsS --max-time 1 "$base/api/health" 2>/dev/null || true)"+ if jq -e --arg version "$expected_version" '+ type == "object" and .status == "ok" and .version == $version and+ (.buildId | type == "string") and (.buildId | length > 0) and has("runtimeInstanceId")+ ' <<<"$body" >/dev/null 2>&1; then+ return 0+ fi+ [ "$i" -ge "$attempts" ] || sleep 0.25+ done+ return 1+}+service_handoff_marker() {local canonical base key dircanonical="$(realpath -e -- "$ROOT" 2>/dev/null || true)"@@ -254,7 +272,7 @@ service_restore_fallback_after_failure() {}service_lifecycle_safe() {- local verb="$1" rc=0 active=0+ local verb="$1" rc=0 active=0 service_urlrequire_service_checkout_cliruntime_exclusion_acquire_shared \|| die "offline update/deploy is mutating this checkout or another service handoff is active; retry after it finishes"@@ -262,6 +280,13 @@ service_lifecycle_safe() {SERVICE_FALLBACK_QUIESCED=0; SERVICE_HANDOFF_URL=''; SERVICE_HANDOFF_MARKER=''[ "$active" = 1 ] || service_handoff_fallback_lockedservice_manager_write "$verb" mso.service || rc=$?+ if [ "$rc" -eq 0 ]; then+ service_url="$(service_unit_local_url)"+ if ! service_wait_ready "$service_url"; then+ printf 'mso: %s mso.service returned success but MSO did not become healthy at %s\n' "$verb" "$service_url" >&2+ rc=24+ fi+ firuntime_exclusion_releaseif [ "$rc" -ne 0 ]; then service_restore_fallback_after_failure; return "$rc"; fi[ -z "${SERVICE_HANDOFF_MARKER:-}" ] || mso_private_state_remove_file "$SERVICE_HANDOFF_MARKER" >/dev/null 2>&1 || truediff --git a/bin/mso-service-lifecycle.test.ts b/bin/mso-service-lifecycle.test.tsindex 6e49b0ac..683ab50a 100644--- a/bin/mso-service-lifecycle.test.ts+++ b/bin/mso-service-lifecycle.test.ts@@ -6,6 +6,7 @@ import crypto from "node:crypto";import { afterEach, describe, expect, it } from "vitest";const CLI = path.join(process.cwd(), "bin/mso");+const VERSION = JSON.parse(fs.readFileSync(path.join(process.cwd(), "package.json"), "utf8")).version as string;const roots: string[] = [];function fixture() {@@ -14,13 +15,15 @@ function fixture() {fs.mkdirSync(bin); fs.mkdirSync(home);const manager = path.join(bin, "manager");fs.writeFileSync(manager, `#!/bin/sh\nprintf 'manager %s\\n' "$*" >> "${capture}"\ncase "$*" in\n 'show -p WorkingDirectory --value mso.service') printf '%s\\n' "${process.cwd()}" ;;\n 'show -p Environment --value mso.service') printf 'PORT=4005\\n' ;;\n 'is-active --quiet mso.service') [ "\${MSO_TEST_SERVICE_ACTIVE:-1}" = 1 ] && exit 0; exit 3 ;;\n 'start mso.service'|'restart mso.service') [ "\${MSO_TEST_MANAGER_FAIL:-0}" = 1 ] && exit 23; exit 0 ;;\nesac\n`, { mode: 0o755 });+ const curl = path.join(bin, "curl");+ fs.writeFileSync(curl, `#!/bin/sh\nprintf 'curl %s\\n' "$*" >> "${capture}"\n[ "\${MSO_TEST_SERVICE_HEALTHY:-1}" = 1 ] || exit 22\nprintf '%s\\n' '{"status":"ok","version":"${VERSION}","buildId":"fixture","runtimeInstanceId":"service-fixture"}'\n`, { mode: 0o755 });const helper = path.join(root, "service-update");fs.writeFileSync(helper, `#!/bin/sh\nprintf 'helper %s\\n' "$*" >> "${capture}"\n`, { mode: 0o755 });const gateway = path.join(root, "gateway");fs.writeFileSync(gateway, `#!/bin/sh\nprintf 'gateway %s marker=%s local=%s\\n' "$*" "\${MSO_GATEWAY_RECOVERY_MARKER:-}" "\${MSO_GATEWAY_LOCAL_URL:-}" >> "${capture}"\ncase "$1" in\n runtime-assert-update-safe) [ "\${MSO_TEST_FALLBACK:-0}" = 1 ] && echo 'runtime: update-owned' || echo 'runtime: update-safe' ;;\n runtime-stop) [ -n "\${MSO_GATEWAY_RECOVERY_MARKER:-}" ] || exit 9; printf '1\\n' > "\$MSO_GATEWAY_RECOVERY_MARKER"; chmod 600 "\$MSO_GATEWAY_RECOVERY_MARKER"; echo 'runtime: stopped-owned' ;;\n local-start) echo 'runtime: healthy MSO at fixture' ;;\n *) exit 2 ;;\nesac\n`, { mode: 0o755 });const exclusion = path.join(root, "runtime-exclusion");const env = { ...process.env, HOME: home, MSO_ENV: "/dev/null", MSO_GATEWAY_LOCAL_URL: "http://127.0.0.1:4005",- MSO_SYSTEMCTL_BIN: manager, MSO_SERVICE_UPDATE_BIN: helper, MSO_GATEWAY_BIN: gateway, MSO_RUNTIME_EXCLUSION_DIR: exclusion, MSO_SERVICE_HANDOFF_DIR: path.join(root, "handoff") };+ MSO_SYSTEMCTL_BIN: manager, MSO_CURL_BIN: curl, MSO_SERVICE_UPDATE_BIN: helper, MSO_GATEWAY_BIN: gateway, MSO_RUNTIME_EXCLUSION_DIR: exclusion, MSO_SERVICE_HANDOFF_DIR: path.join(root, "handoff") };return { root, capture, env, exclusion };}@@ -76,6 +79,21 @@ describe("mso service/deploy runtime exclusion", () => {expect(calls).toContain("gateway local-start");});++ it("restores the gateway fallback if systemd starts but MSO never becomes healthy", () => {+ const f = fixture();+ const out = spawnSync(CLI, ["service", "start"], {+ env: { ...f.env, MSO_TEST_SERVICE_ACTIVE: "0", MSO_TEST_FALLBACK: "1", MSO_TEST_SERVICE_HEALTHY: "0", MSO_SERVICE_HEALTH_ATTEMPTS: "1" }, encoding: "utf8",+ });+ expect(out.status).not.toBe(0);+ expect(out.stderr).toContain("did not become healthy");+ const calls = fs.readFileSync(f.capture, "utf8");+ expect(calls).toContain("gateway runtime-stop");+ expect(calls).toContain("manager start mso.service");+ expect(calls).toContain("curl --noproxy * -fsS --max-time 1 http://127.0.0.1:4005/api/health");+ expect(calls).toContain("gateway local-start");+ });+it("refuses lifecycle actions from a checkout that does not own the service", () => {const f = fixture(), other = path.join(f.root, "other"); fs.mkdirSync(other);const manager = path.join(f.root, "wrong-manager");diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.mdindex 7d109020..b38a06d9 100644--- a/docs/CHANGELOG.md+++ b/docs/CHANGELOG.md@@ -8,6 +8,7 @@ this is the *what*, and it is what Settings → About shows as “What's new”.**Fixed**+- `runtime` verify service readiness before handoff- `runtime` keep service starts on shared exclusion- `settings` hide premature update warning- `update` enforce main and raise MCP daily limitdiff --git a/lib/managed-apps/jobs.test.ts b/lib/managed-apps/jobs.test.tsindex 55fd1e45..cdc3441e 100644--- a/lib/managed-apps/jobs.test.ts+++ b/lib/managed-apps/jobs.test.ts@@ -9,7 +9,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";vi.mock("server-only", () => ({}));const { startManagedAppJob, readManagedAppJob, listManagedAppJobs } = await import("./jobs");-const { MANAGED_APP_JOB_LOG_CAP } = await import("./job-runner");+const { MANAGED_APP_JOB_LOG_CAP, liveRecord } = await import("./job-runner");const { performManagedAppAction } = await import("./manager");import type { ManagedAppJob } from "./types";@@ -36,7 +36,17 @@ async function stub(name: string, body: string): Promise<string> {async function settle(jobId: string): Promise<ManagedAppJob> {for (let i = 0; i < 400; i += 1) {const job = await readManagedAppJob(jobId);- if (job && job.status !== "queued" && job.status !== "running") return job;+ if (job && job.status !== "queued" && job.status !== "running") {+ // `finish()` intentionally publishes the terminal status and releases the+ // per-app lock before the final durable flush completes. Tests must wait+ // for that background finalizer before deleting their temporary $HOME, or+ // fs.rm can race writeJobRecord() and intermittently fail with ENOTEMPTY.+ for (let finalize = 0; finalize < 200 && liveRecord(jobId); finalize += 1) {+ await new Promise((resolve) => setTimeout(resolve, 5));+ }+ if (liveRecord(jobId)) throw new Error("job reached terminal status but finalization did not complete");+ return (await readManagedAppJob(jobId)) ?? job;+ }await new Promise((resolve) => setTimeout(resolve, 20));}throw new Error("job never reached a terminal status");