Skip to content

armgit / mso

Public Imported from GitHub
0

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.

fix(update): recover no-systemd container installs

Rahman68d981a7b53c
diff --git a/.codex-plugin/plugin.json b/.codex-plugin/plugin.json
index 6f797600..1cabf0fc 100644
--- a/.codex-plugin/plugin.json
+++ b/.codex-plugin/plugin.json
@@ -1,6 +1,6 @@
{
"name": "mso",
- "version": "0.2.18",
+ "version": "0.2.19",
"description": "Operate MSO projects, workflows, VPS resources, integrations, deployments, and MCP capabilities through reusable safety-first skills.",
"author": {
"name": "MSO"
diff --git a/bin/mso b/bin/mso
index 542bcf4e..d866d14b 100755
--- a/bin/mso
+++ b/bin/mso
@@ -96,6 +96,7 @@
# build Compile HEAD out-of-tree (safe against the live checkout)
# deploy Rebuild active service with runtime quiesce/restore
# update [--rebuild] Update from origin/main safely; works even when the web runtime is down
+# update reconcile Preserve a local-only/diverged HEAD, then sync main to origin/main
#
# reset [--scope config|all] Preview local factory reset; explicit token required to apply
# uninstall [--purge] [--remove-code] Preview owned installation removal
@@ -136,7 +137,7 @@
# Docs: https://github.com/rahmanef63/mso
set -euo pipefail
-VERSION="1.13.0"
+VERSION="1.13.1"
ROOT="$(cd "$(dirname "$(readlink -f "$0")")/.." && pwd)"
die() { echo "mso: $*" >&2; exit 1; }
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index 8b3d3470..799e1f35 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -12,6 +12,7 @@ this is the *what*, and it is what Settings → About shows as “What's new”.
**Fixed**
+- `update` recover no-systemd container installs
- `installer` build node-pty reliably on Codespaces
- `managed-apps` support Hermes without systemd
diff --git a/docs/CLI.md b/docs/CLI.md
index 26bb4f49..fb11f2d3 100644
--- a/docs/CLI.md
+++ b/docs/CLI.md
@@ -136,6 +136,7 @@ Commands:
build Compile HEAD out-of-tree (safe against the live checkout)
deploy Rebuild active service with runtime quiesce/restore
update [--rebuild] Update from origin/main safely; works even when the web runtime is down
+ update reconcile Preserve a local-only/diverged HEAD, then sync main to origin/main
reset [--scope config|all] Preview local factory reset; explicit token required to apply
uninstall [--purge] [--remove-code] Preview owned installation removal
diff --git a/docs/INSTALL.md b/docs/INSTALL.md
index 260b120b..1756ca32 100644
--- a/docs/INSTALL.md
+++ b/docs/INSTALL.md
@@ -580,13 +580,14 @@ Use Settings → About or:
```bash
mso update status # fetch + show incoming commits and labeled CLI/build identity
+mso update reconcile # preserve local-only HEAD on rescue/*, then sync main to origin/main
mso update # preferred: update safely even if :4005 is down
mso update log
```
MSO has two explicitly labeled version domains: the app/package version shown in Settings → About and the independently versioned CLI contract shown by `mso --version`. The Git commit/build remains update authority. If commits changed without a CLI bump, status says `N new commits on mso CLI X` rather than rendering `X -> X`.
-The updater verifies the incoming checkout/build before replacing the service. Re-running the installer on an existing checkout acquires the same checkout-scoped transaction lock **before** Git fetch/checkout mutation and hands that open lock FD to the post-checkout runtime lifecycle, so installer, `mso update`, and `mso deploy` cannot mutate one checkout concurrently. The lock primitive is carried by the verified installer payload itself, so older MSO checkouts that predate the current private-state helper remain upgradeable in place. A normal `mso update` treats fetched `origin/main` as the release authority: after any fast-forward, local `main` must equal that remote commit exactly. A clean branch that is locally ahead or diverged is refused before dependency/build mutation instead of deploying unpushed code. `mso update status` reports that state explicitly. `mso update --rebuild` is different by design: it rebuilds the already-selected clean checkout without changing Git history. With an active
+The updater verifies the incoming checkout/build before replacing the service. Re-running the installer on an existing checkout acquires the same checkout-scoped transaction lock **before** Git fetch/checkout mutation and hands that open lock FD to the post-checkout runtime lifecycle, so installer, `mso update`, and `mso deploy` cannot mutate one checkout concurrently. The lock primitive is carried by the verified installer payload itself, so older MSO checkouts that predate the current private-state helper remain upgradeable in place. A normal `mso update` treats fetched `origin/main` as the release authority: after any fast-forward, local `main` must equal that remote commit exactly. A clean branch that is locally ahead or diverged is refused before dependency/build mutation instead of deploying unpushed code. `mso update status` reports that state explicitly; `mso update reconcile` makes recovery explicit and lossless by preserving the previous HEAD on a timestamped local `rescue/mso-update-*` branch before resetting clean `main` to fetched `origin/main`. `mso update --rebuild` is different by design: it rebuilds the already-selected clean checkout without changing Git history. With an active
`mso.service` it first canonicalizes the unit's `WorkingDirectory` and requires it to equal the checkout
that 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 active
diff --git a/docs/TROUBLESHOOTING.md b/docs/TROUBLESHOOTING.md
index c110f0b1..3f45023d 100644
--- a/docs/TROUBLESHOOTING.md
+++ b/docs/TROUBLESHOOTING.md
@@ -3,6 +3,26 @@
> **Current reference.** Symptoms → likely cause → supported recovery. Historical browser
> sidecar and manual deploy instructions are intentionally not used here.
+
+## `mso update` says local `main` diverged from `origin/main`
+
+This is a Git safety stop, not a systemd failure. MSO refuses to overwrite local commits. Use:
+
+```bash
+mso update reconcile
+mso update
+```
+
+`reconcile` requires a clean `main`, fetches `origin/main`, preserves the previous local HEAD on a timestamped `rescue/mso-update-*` branch, then makes local `main` exactly match `origin/main`. It never deletes the preserved commit. On a container/Codespaces host without systemd, the subsequent update uses the loopback fallback runtime; systemd is optional.
+
+If the local web/PTY runtime is down after a container restart, start the loopback runtime directly:
+
+```bash
+mso web --local --print
+```
+
+Then verify `http://127.0.0.1:4005/api/health` (or the configured loopback port). Public HTTPS is a separate layer: Cloudflare is optional; Tailscale Serve, a reverse proxy, or another externally managed HTTPS endpoint can be used instead.
+
## Login & sessions
### Login returns `not_configured` (HTTP 500)
diff --git a/package.json b/package.json
index 3fb104e4..5b882aa0 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "mso",
- "version": "0.2.18",
+ "version": "0.2.19",
"private": true,
"engines": {
"node": ">=20.9",
diff --git a/scripts/cli/commands.sh b/scripts/cli/commands.sh
index 05ab94b8..22893321 100755
--- a/scripts/cli/commands.sh
+++ b/scripts/cli/commands.sh
@@ -37,7 +37,7 @@ U_service="service status|start|stop|restart|logs [n]"
U_unit="unit logs <system|user> <unit> [limit]|start|stop|restart <system|user> <unit>"
U_reset="reset [--scope config|all] [--json] [--apply --confirm <preview-token>]"
U_uninstall="uninstall [--purge] [--remove-code] [--service name.service] [--json] [--apply --confirm <preview-token>]"
-U_update="update [--rebuild] | status | log"
+U_update="update [--rebuild] | status | reconcile | log"
U_cockpit="cockpit [project] | cockpit show [project] | cockpit search <query…>"
U_threads="threads list|show <id>|save <json>|rm <id>"
U_agent_sessions="agent-sessions list [limit]|show <id>|create [title]"
diff --git a/scripts/mso-model-dx-contract.test.ts b/scripts/mso-model-dx-contract.test.ts
index 0159e88e..cdede114 100644
--- a/scripts/mso-model-dx-contract.test.ts
+++ b/scripts/mso-model-dx-contract.test.ts
@@ -34,7 +34,7 @@ const all = [cli, commandOwner, agentCli, providerCatalogCli, configRoute, oauth
describe("MSO model/provider/session CLI contract", () => {
it("keeps provider auth (`models`) separate from active selection (`model`)", () => {
- expect(cli).toContain('VERSION="1.13.0"');
+ expect(cli).toContain('VERSION="1.13.1"');
expect(cli).toContain("models * Configure AI providers/auth");
expect(cli).toContain("model [ref] Select active model");
expect(agentCli).toContain("run_models()");
diff --git a/scripts/mso-update b/scripts/mso-update
index 2b510f50..f4a1e1d2 100755
--- a/scripts/mso-update
+++ b/scripts/mso-update
@@ -28,7 +28,13 @@ require_checkout() {
[ -z "$(git -C "$ROOT" status --porcelain)" ] || fail "checkout has local changes; refusing to overwrite them"
}
fetch_main() { git -C "$ROOT" fetch --quiet origin main || fail "could not reach origin/main"; }
-service_is_active() { command -v systemctl >/dev/null 2>&1 && systemctl is-active --quiet mso.service; }
+service_is_active() {
+ # Containers/Codespaces often ship the systemctl binary without systemd as PID 1.
+ # A read-only probe must classify that as "no active service" without leaking
+ # systemd bus errors into ordinary `mso update` output.
+ command -v systemctl >/dev/null 2>&1 || return 1
+ systemctl is-active --quiet mso.service >/dev/null 2>&1
+}
service_port() {
local raw port
raw="$(systemctl show -p Environment --value mso.service 2>/dev/null || true)"
@@ -64,11 +70,13 @@ print_status() {
read -r relation ahead n < <(update_git_relation "$ROOT") || fail "could not compare HEAD with origin/main"
local_v="$(current_version)"; remote_v="$(remote_version)"; head="$(git -C "$ROOT" rev-parse HEAD)"
if [ "$relation" = ahead ]; then
- printf 'local main is ahead of origin/main by %s commit%s; refusing to deploy unpushed code. push/reset the checkout first.\n' "$ahead" "$([ "$ahead" = 1 ] || printf s)"
+ printf 'local main is ahead of origin/main by %s commit%s; refusing to deploy unpushed code.\n' "$ahead" "$([ "$ahead" = 1 ] || printf s)"
+ printf 'run: mso update reconcile # preserves current HEAD on a rescue branch first\n'
return
fi
if [ "$relation" = diverged ]; then
- printf 'local main has diverged from origin/main (ahead %s, behind %s); refusing update. reconcile the checkout first.\n' "$ahead" "$n"
+ printf 'local main has diverged from origin/main (ahead %s, behind %s); refusing update.\n' "$ahead" "$n"
+ printf 'run: mso update reconcile # preserves current HEAD on a rescue branch first\n'
return
fi
if [ "$n" -gt 0 ]; then
@@ -103,6 +111,43 @@ print_status() {
printf 'mso is up to date (CLI %s, build %s)\n' "${local_v:-unknown}" "${head:0:7}"
fi
}
+reconcile_checkout() {
+ local relation ahead behind rescue stamp head
+ require_checkout
+ fetch_main
+ read -r relation ahead behind < <(update_git_relation "$ROOT") || fail "could not compare HEAD with origin/main"
+ case "$relation" in
+ exact)
+ printf 'checkout already matches origin/main at %s\n' "$(git -C "$ROOT" rev-parse --short HEAD)"
+ return 0
+ ;;
+ behind)
+ git -C "$ROOT" merge --ff-only origin/main >/dev/null \
+ || fail "could not fast-forward local main to origin/main"
+ printf 'checkout fast-forwarded to origin/main at %s\n' "$(git -C "$ROOT" rev-parse --short HEAD)"
+ printf 'run: mso update\n'
+ return 0
+ ;;
+ ahead|diverged)
+ stamp="$(date -u +%Y%m%dT%H%M%SZ)"
+ rescue="rescue/mso-update-$stamp"
+ head="$(git -C "$ROOT" rev-parse HEAD)"
+ git -C "$ROOT" branch "$rescue" "$head" \
+ || fail "could not preserve local HEAD on a rescue branch"
+ git -C "$ROOT" reset --hard origin/main >/dev/null \
+ || fail "rescue branch $rescue was created, but main could not be reset to origin/main"
+ read -r relation ahead behind < <(update_git_relation "$ROOT") || fail "could not verify reconciled checkout"
+ [ "$relation" = exact ] \
+ || fail "rescue branch $rescue preserved the old HEAD, but checkout still does not match origin/main"
+ printf 'preserved previous local HEAD %s on %s\n' "${head:0:7}" "$rescue"
+ printf 'checkout now matches origin/main at %s\n' "$(git -C "$ROOT" rev-parse --short HEAD)"
+ printf 'run: mso update\n'
+ return 0
+ ;;
+ *) fail "unknown Git authority state" ;;
+ esac
+}
+
notice() {
local dir stamp now last=0 relation ahead n local_v remote_v
git_root || return 0
@@ -115,7 +160,7 @@ notice() {
fi
read -r relation ahead n < <(update_git_relation "$ROOT") || return 0
if [ "$relation" = ahead ] || [ "$relation" = diverged ]; then
- printf 'MSO update refused: local main is %s origin/main (ahead %s, behind %s). Reconcile/push the checkout first.\n' \
+ printf 'MSO update refused: local main is %s origin/main (ahead %s, behind %s). Run: mso update reconcile\n' \
"$relation" "$ahead" "$n" >&2
return 0
fi
@@ -159,8 +204,8 @@ offline_build_locked() {
case "$relation" in
exact) ;;
behind) git -C "$ROOT" merge --ff-only origin/main || fail "cannot fast-forward to origin/main" ;;
- ahead) fail "local main is ahead of origin/main by $ahead commit(s); refusing to deploy unpushed code" ;;
- diverged) fail "local main has diverged from origin/main (ahead $ahead, behind $n); reconcile it before update" ;;
+ ahead) fail "local main is ahead of origin/main by $ahead commit(s); run: mso update reconcile" ;;
+ diverged) fail "local main has diverged from origin/main (ahead $ahead, behind $n); run: mso update reconcile" ;;
*) fail "unknown Git authority state" ;;
esac
read -r relation ahead n < <(update_git_relation "$ROOT") || fail "could not re-check origin/main after fast-forward"
@@ -286,12 +331,13 @@ run_update() {
case "${1:-run}" in
notice) notice ;;
status|check) print_status ;;
+ reconcile) reconcile_checkout ;;
log) [ -f "$LOG" ] && tail -n "${2:-80}" "$LOG" || printf 'no update log yet: %s\n' "$LOG" ;;
run) case "${2-}" in
"" ) run_update 0 ;;
--rebuild|--rebuild-only) run_update 1 ;;
- *) fail "usage: mso update [--rebuild] | status | log" ;;
+ *) fail "usage: mso update [--rebuild] | status | reconcile | log" ;;
esac ;;
--rebuild|--rebuild-only) run_update 1 ;;
- *) fail "usage: mso update [--rebuild] | status | log" ;;
+ *) fail "usage: mso update [--rebuild] | status | reconcile | log" ;;
esac
diff --git a/scripts/mso-update-reconcile.test.ts b/scripts/mso-update-reconcile.test.ts
new file mode 100644
index 00000000..47763f5e
--- /dev/null
+++ b/scripts/mso-update-reconcile.test.ts
@@ -0,0 +1,100 @@
+import { execFileSync, spawnSync } from "node:child_process";
+import fs from "node:fs";
+import os from "node:os";
+import path from "node:path";
+import { afterEach, describe, expect, it } from "vitest";
+
+const ROOT = process.cwd();
+const SCRIPT = path.join(ROOT, "scripts/mso-update");
+const roots: string[] = [];
+
+function git(cwd: string, ...args: string[]) {
+ return execFileSync("git", args, { cwd, encoding: "utf8" }).trim();
+}
+
+function copy(repo: string, rel: string) {
+ const dst = path.join(repo, rel);
+ fs.mkdirSync(path.dirname(dst), { recursive: true });
+ fs.copyFileSync(path.join(ROOT, rel), dst);
+}
+
+function fixture() {
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), "mso-update-reconcile-"));
+ roots.push(root);
+ const repo = path.join(root, "repo");
+ const remote = path.join(root, "remote.git");
+ const bin = path.join(root, "bin");
+ fs.mkdirSync(repo, { recursive: true });
+ fs.mkdirSync(bin, { recursive: true });
+ for (const rel of [
+ "scripts/mso-update",
+ "scripts/lib/private-state.sh",
+ "scripts/lib/update-state.sh",
+ "scripts/lib/runtime-exclusion.sh",
+ "scripts/lib/update-gateway-runtimes.sh",
+ "scripts/lib/update-git-authority.sh",
+ ]) copy(repo, rel);
+ fs.mkdirSync(path.join(repo, "bin"), { recursive: true });
+ fs.writeFileSync(path.join(repo, "bin/mso"), '#!/bin/sh\nVERSION="test"\n', { mode: 0o755 });
+ fs.writeFileSync(path.join(repo, "scripts/mso-gateway"), "#!/bin/sh\nexit 0\n", { mode: 0o755 });
+
+ git(repo, "init", "-q", "-b", "main");
+ git(repo, "config", "user.name", "MSO Test");
+ git(repo, "config", "user.email", "[email protected]");
+ git(repo, "add", ".");
+ git(repo, "commit", "-qm", "base");
+ const base = git(repo, "rev-parse", "HEAD");
+ execFileSync("git", ["init", "-q", "--bare", remote]);
+ git(repo, "remote", "add", "origin", remote);
+ git(repo, "push", "-q", "-u", "origin", "main");
+
+ fs.writeFileSync(path.join(repo, "remote.txt"), "remote\n");
+ git(repo, "add", "remote.txt");
+ git(repo, "commit", "-qm", "remote update");
+ const remoteHead = git(repo, "rev-parse", "HEAD");
+ git(repo, "push", "-q", "origin", "main");
+ git(repo, "reset", "--hard", "-q", base);
+
+ const env = {
+ ...process.env,
+ HOME: path.join(root, "home"),
+ PATH: `${bin}:${process.env.PATH ?? ""}`,
+ MSO_UPDATE_ROOT: repo,
+ MSO_UPDATE_STATE_DIR: path.join(root, "update-state"),
+ MSO_RUNTIME_EXCLUSION_DIR: path.join(root, "runtime-exclusion"),
+ };
+ return { repo, bin, remoteHead, env };
+}
+
+afterEach(() => {
+ for (const root of roots.splice(0)) fs.rmSync(root, { recursive: true, force: true });
+});
+
+describe("mso update container recovery", () => {
+ it("silences systemctl bus errors when systemd is not PID 1", () => {
+ const f = fixture();
+ fs.writeFileSync(path.join(f.bin, "systemctl"), `#!/bin/sh
+printf '%s\n' "System has not been booted with systemd as init system (PID 1). Can't operate." >&2
+printf '%s\n' 'Failed to connect to system scope bus via local transport: Host is down' >&2
+exit 3
+`, { mode: 0o755 });
+ git(f.repo, "reset", "--hard", "-q", f.remoteHead);
+ const out = spawnSync(SCRIPT, ["status"], { env: f.env, encoding: "utf8" });
+ expect(out.status).toBe(0);
+ expect(out.stderr).toBe("");
+ expect(out.stdout).toMatch(/up to date|deployment verification\/restart is pending/);
+ });
+
+ it("preserves a diverged local HEAD on a rescue branch before syncing main", () => {
+ const f = fixture();
+ fs.writeFileSync(path.join(f.repo, "local.txt"), "local\n");
+ git(f.repo, "add", "local.txt");
+ git(f.repo, "commit", "-qm", "local update");
+ const localHead = git(f.repo, "rev-parse", "HEAD");
+ const out = execFileSync(SCRIPT, ["reconcile"], { env: f.env, encoding: "utf8" });
+ expect(git(f.repo, "rev-parse", "HEAD")).toBe(f.remoteHead);
+ const rescue = out.match(/on (rescue\/mso-update-[0-9TZ]+)\n/)?.[1];
+ expect(rescue).toBeTruthy();
+ expect(git(f.repo, "rev-parse", rescue!)).toBe(localHead);
+ });
+});