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): close service installer and notice races
Abdurrahman Fakhrul34582137d92e
diff --git a/bin/mso b/bin/msoold mode 100755new mode 100644index 018c4cda..552e19fb--- a/bin/mso+++ b/bin/mso@@ -201,25 +201,75 @@ require_service_checkout_cli() {|| die "mso.service belongs to $canonical_service, not this checkout $canonical_root"}-service_with_runtime_shared() {- local rc=0- runtime_exclusion_acquire_shared \- || die "offline update/deploy is mutating this checkout; retry the service action after it finishes"- "$@" || rc=$?- runtime_exclusion_release- return "$rc"+service_unit_local_url() {+ local raw port+ raw="$(service_manager_read show -p Environment --value mso.service 2>/dev/null || true)"+ port="$(printf '%s\n' "$raw" | tr ' ' '\n' | sed -n 's/^PORT=//p' | head -1)"+ if ! [[ "$port" =~ ^[0-9]+$ ]] || [ "$port" -lt 1 ] || [ "$port" -gt 65535 ]; then port=4005; fi+ printf 'http://127.0.0.1:%s' "$port"}-service_start_safe() {- require_service_checkout_cli- service_with_runtime_shared service_manager_write start mso.service+service_handoff_marker() {+ local canonical base key dir+ canonical="$(realpath -e -- "$ROOT" 2>/dev/null || true)"+ [ -n "$canonical" ] || die "cannot canonicalize checkout for service handoff"+ base="$(mso_private_state_dir "${MSO_SERVICE_HANDOFF_DIR:-$HOME/.mso/private/service-handoff}")" \+ || die "unsafe service handoff state directory"+ key="$(printf '%s' "$canonical" | sha256sum | awk '{print $1}')"+ [[ "$key" =~ ^[0-9a-f]{64}$ ]] || die "cannot derive service handoff scope"+ dir="$(mso_private_state_dir "$base/$key")" || die "unsafe scoped service handoff directory"+ printf '%s/runtime' "$dir"+}++service_handoff_fallback_locked() {+ local gateway local_url marker probe out+ SERVICE_FALLBACK_QUIESCED=0+ gateway="${MSO_GATEWAY_BIN:-$ROOT/scripts/mso-gateway}"+ [ -x "$gateway" ] || die "missing gateway lifecycle helper: $gateway"+ local_url="$(service_unit_local_url)"; marker="$(service_handoff_marker)"+ probe="$(MSO_GATEWAY_ROOT="$ROOT" MSO_GATEWAY_ENV="$ENVF" MSO_GATEWAY_LOCAL_URL="$local_url" \+ "$gateway" runtime-assert-update-safe 2>&1)" || die "cannot hand off service port $local_url: $probe"+ case "$probe" in+ *'runtime: update-owned'*)+ out="$(MSO_GATEWAY_ROOT="$ROOT" MSO_GATEWAY_ENV="$ENVF" MSO_GATEWAY_LOCAL_URL="$local_url" \+ MSO_GATEWAY_RECOVERY_MARKER="$marker" "$gateway" runtime-stop 2>&1)" \+ || die "could not quiesce gateway-owned fallback at $local_url: $out"+ case "$out" in+ *'runtime: stopped-owned'*|*'runtime: recovered-stale-owned'*|*'runtime: already-down'*) SERVICE_FALLBACK_QUIESCED=1 ;;+ *) die "unexpected fallback handoff result at $local_url: $out" ;;+ esac ;;+ *'runtime: update-safe'*) ;;+ *) die "unexpected service handoff probe at $local_url: $probe" ;;+ esac+ SERVICE_HANDOFF_URL="$local_url"; SERVICE_HANDOFF_MARKER="$marker"+}++service_restore_fallback_after_failure() {+ local gateway="${MSO_GATEWAY_BIN:-$ROOT/scripts/mso-gateway}"+ [ "${SERVICE_FALLBACK_QUIESCED:-0}" = 1 ] || return 0+ MSO_GATEWAY_ROOT="$ROOT" MSO_GATEWAY_ENV="$ENVF" MSO_GATEWAY_LOCAL_URL="$SERVICE_HANDOFF_URL" \+ "$gateway" local-start >/dev/null 2>&1 \+ || printf 'mso: service action failed and fallback restore also failed at %s\n' "$SERVICE_HANDOFF_URL" >&2+ mso_private_state_remove_file "$SERVICE_HANDOFF_MARKER" >/dev/null 2>&1 || true}-service_restart_safe() {+service_lifecycle_safe() {+ local verb="$1" rc=0 active=0require_service_checkout_cli- service_with_runtime_shared service_manager_write restart mso.service+ runtime_exclusion_acquire_exclusive \+ || die "offline update/deploy is mutating this checkout or another service handoff is active; retry after it finishes"+ service_manager_read is-active --quiet mso.service && active=1 || true+ SERVICE_FALLBACK_QUIESCED=0; SERVICE_HANDOFF_URL=''; SERVICE_HANDOFF_MARKER=''+ [ "$active" = 1 ] || service_handoff_fallback_locked+ service_manager_write "$verb" mso.service || rc=$?+ runtime_exclusion_release+ if [ "$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 || true}+service_start_safe() { service_lifecycle_safe start; }+service_restart_safe() { service_lifecycle_safe restart; }+deploy_safe() {local local_url helperrequire_service_checkout_clidiff --git a/bin/mso-service-lifecycle.test.ts b/bin/mso-service-lifecycle.test.tsindex 806a4d0b..6e49b0ac 100644--- a/bin/mso-service-lifecycle.test.ts+++ b/bin/mso-service-lifecycle.test.ts@@ -13,12 +13,14 @@ function fixture() {const bin = path.join(root, "bin"), capture = path.join(root, "capture"), home = path.join(root, "home");fs.mkdirSync(bin); fs.mkdirSync(home);const manager = path.join(bin, "manager");- fs.writeFileSync(manager, `#!/bin/sh\nprintf '%s\\n' "$*" >> "${capture}"\ncase "$*" in\n 'show -p WorkingDirectory --value mso.service') printf '%s\\n' "${process.cwd()}" ;;\n 'is-active --quiet mso.service') exit 0 ;;\nesac\n`, { mode: 0o755 });+ 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 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_RUNTIME_EXCLUSION_DIR: exclusion };+ 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") };return { root, capture, env, exclusion };}@@ -53,6 +55,27 @@ describe("mso service/deploy runtime exclusion", () => {expect(fs.readFileSync(f.capture, "utf8")).toContain("helper --rebuild-only");});+ it.each(["start", "restart"])("hands off a gateway-owned fallback before inactive service %s", (verb) => {+ const f = fixture();+ const out = spawnSync(CLI, ["service", verb], { env: { ...f.env, MSO_TEST_SERVICE_ACTIVE: "0", MSO_TEST_FALLBACK: "1" }, encoding: "utf8" });+ expect(out.status).toBe(0);+ const calls = fs.readFileSync(f.capture, "utf8");+ expect(calls.indexOf("gateway runtime-stop")).toBeGreaterThan(-1);+ expect(calls.indexOf(`manager ${verb} mso.service`)).toBeGreaterThan(calls.indexOf("gateway runtime-stop"));+ expect(calls).toContain("local=http://127.0.0.1:4005");+ expect(calls).not.toContain("gateway local-start");+ });++ it("restores the gateway fallback if service start fails after handoff", () => {+ const f = fixture();+ const out = spawnSync(CLI, ["service", "start"], { env: { ...f.env, MSO_TEST_SERVICE_ACTIVE: "0", MSO_TEST_FALLBACK: "1", MSO_TEST_MANAGER_FAIL: "1" }, encoding: "utf8" });+ expect(out.status).not.toBe(0);+ const calls = fs.readFileSync(f.capture, "utf8");+ expect(calls).toContain("gateway runtime-stop");+ expect(calls).toContain("manager start mso.service");+ 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 ab592fec..14bfb207 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**+- `runtime` close service installer and notice races- `install` hold update lock across checkout refresh- `install` restore service after pre-mutation abort- `runtime` close update authority and stop racesdiff --git a/docs/INSTALL.md b/docs/INSTALL.mdindex 7595e79a..9450f1cf 100644--- a/docs/INSTALL.md+++ b/docs/INSTALL.md@@ -452,7 +452,7 @@ mso update # preferred: update safely even if :4005 is downmso update log```-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. 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 --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 checkoutthat 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 activediff --git a/docs/TROUBLESHOOTING.md b/docs/TROUBLESHOOTING.mdindex 145b58a7..d04599ac 100644--- a/docs/TROUBLESHOOTING.md+++ b/docs/TROUBLESHOOTING.md@@ -41,6 +41,13 @@ a gateway-owned runtime is quiesced, so an interrupted state update remains safeWhen `mso.service` is active, status also compares the commit baked into the live loopback `/api/health`response with source `HEAD`; source equality alone is not treated as proof that deployment finished.+### `mso service start` or `restart` while `mso web` is serving locally++MSO takes the checkout runtime exclusion exclusively before service handoff. If the unit is inactive and+its loopback port is occupied by a **gateway-owned** fallback, MSO quiesces only that recorded process,+preserves any public tunnel, then starts the system service on the freed port. If the service action fails,+the fallback is restored. An unowned/manual responder is never killed automatically.+### `mso update` says local main is ahead/diverged from `origin/main`This is an authority refusal, not an updater failure. Normal update may deploy only the fetched `origin/main`diff --git a/scripts/install-core.sh b/scripts/install-core.shindex 77e68fea..f73dd603 100644--- a/scripts/install-core.sh+++ b/scripts/install-core.sh@@ -308,49 +308,58 @@ INSTALL_EARLY_UPDATE_LOCK_FD=''INSTALL_EARLY_UPDATE_LOCK_FILE=''INSTALL_EARLY_UPDATE_CANONICAL_ROOT=''+install_private_state_dir() {+ local requested="${1:-}" created=0 canonical owner mode old_umask+ [ -n "$requested" ] || die "empty installer private-state directory"+ case "$requested" in /*) ;; *) die "installer private-state directory must be absolute: $requested" ;; esac+ [ ! -L "$requested" ] || die "refusing symlink installer private-state directory: $requested"+ if [ ! -e "$requested" ]; then old_umask=$(umask); umask 077; mkdir -p -- "$requested"; umask "$old_umask"; created=1; fi+ [ -d "$requested" ] && [ ! -L "$requested" ] || die "not a real installer private-state directory: $requested"+ canonical="$(realpath -e -- "$requested" 2>/dev/null || true)"; [ -n "$canonical" ] || die "cannot resolve installer private-state directory: $requested"+ owner="$(stat -c '%u' -- "$canonical" 2>/dev/null || true)"; mode="$(stat -c '%a' -- "$canonical" 2>/dev/null || true)"+ [ "$owner" = "$(id -u)" ] || die "installer private-state directory is not owned by current uid: $canonical"+ if [ "$created" = 1 ]; then chmod 700 -- "$canonical"; mode="$(stat -c '%a' -- "$canonical")"; fi+ [ "$mode" = 700 ] || die "installer private-state directory must be mode 0700, got $mode: $canonical"+ printf '%s' "$canonical"+}++install_private_state_ensure_file() {+ local requested="$1" parent name canonical_parent resolved tmp old_umask owner mode+ parent="$(dirname -- "$requested")"; name="$(basename -- "$requested")"+ [ -n "$name" ] && [ "$name" != . ] && [ "$name" != / ] || die "invalid installer private-state file: $requested"+ canonical_parent="$(install_private_state_dir "$parent")"; resolved="$canonical_parent/$name"+ if [ -e "$resolved" ] || [ -L "$resolved" ]; then+ [ ! -L "$resolved" ] && [ -f "$resolved" ] || die "unsafe installer private-state lock: $resolved"+ owner="$(stat -c '%u' -- "$resolved" 2>/dev/null || true)"; mode="$(stat -c '%a' -- "$resolved" 2>/dev/null || true)"+ [ "$owner" = "$(id -u)" ] && [ "$mode" = 600 ] || die "installer private-state lock must be owner mode 0600: $resolved"+ printf '%s' "$resolved"; return 0+ fi+ old_umask=$(umask); umask 077; tmp="$(mktemp "$canonical_parent/.mso-install-lock.XXXXXX")"; umask "$old_umask"; chmod 600 -- "$tmp"+ if ! mv -Tn -- "$tmp" "$resolved"; then rm -f -- "$tmp"; fi+ [ ! -L "$resolved" ] && [ -f "$resolved" ] || die "could not create safe installer private-state lock: $resolved"+ owner="$(stat -c '%u' -- "$resolved" 2>/dev/null || true)"; mode="$(stat -c '%a' -- "$resolved" 2>/dev/null || true)"+ [ "$owner" = "$(id -u)" ] && [ "$mode" = 600 ] || die "installer private-state lock must be owner mode 0600: $resolved"+ printf '%s' "$resolved"+}+install_early_update_lock_release() {[ "$INSTALL_EARLY_UPDATE_LOCK_HELD" = 1 ] || return 0- if [ -n "${INSTALL_EARLY_UPDATE_LOCK_FD:-}" ]; then- flock -u "$INSTALL_EARLY_UPDATE_LOCK_FD" 2>/dev/null || true- exec {INSTALL_EARLY_UPDATE_LOCK_FD}>&- || true- INSTALL_EARLY_UPDATE_LOCK_FD=''- fi+ if [ -n "${INSTALL_EARLY_UPDATE_LOCK_FD:-}" ]; then flock -u "$INSTALL_EARLY_UPDATE_LOCK_FD" 2>/dev/null || true; exec {INSTALL_EARLY_UPDATE_LOCK_FD}>&- || true; INSTALL_EARLY_UPDATE_LOCK_FD=''; fiINSTALL_EARLY_UPDATE_LOCK_HELD=0}install_early_update_lock_acquire() {- local private_helper canonical base key state lock timeout+ local canonical base key state lock timeout[ -d "$DIR/.git" ] || return 0- [ -z "$(git -C "$DIR" status --porcelain)" ] \- || die "checkout has uncommitted changes at $DIR; refusing an unlocked in-place upgrade"- private_helper="$DIR/scripts/lib/private-state.sh"- [ -f "$private_helper" ] && [ ! -L "$private_helper" ] \- || die "existing checkout is missing the secure private-state helper; restore the tracked file or install into another --dir"- [ "$(stat -c '%u' -- "$private_helper" 2>/dev/null || true)" = "$(id -u)" ] \- || die "private-state helper is not owned by the installing user: $private_helper"- # shellcheck source=scripts/lib/private-state.sh- . "$private_helper"- canonical="$(realpath -e -- "$DIR" 2>/dev/null || true)"- [ -n "$canonical" ] || die "cannot canonicalize existing checkout before update lock"- base="$(mso_private_state_dir "${MSO_UPDATE_STATE_DIR:-$HOME/.mso/private/update-state}")" \- || die "unsafe installer update-state directory"- key="$(printf '%s' "$canonical" | sha256sum | awk '{print $1}')"- [[ "$key" =~ ^[0-9a-f]{64}$ ]] || die "cannot derive installer update-lock scope"- state="$(mso_private_state_dir "$base/$key")" || die "unsafe checkout-scoped installer update state"- lock="$state/transaction.lock"- mso_private_state_ensure_file "$lock" >/dev/null || die "unsafe installer update transaction lock"+ [ -z "$(git -C "$DIR" status --porcelain)" ] || die "checkout has uncommitted changes at $DIR; refusing an unlocked in-place upgrade"+ canonical="$(realpath -e -- "$DIR" 2>/dev/null || true)"; [ -n "$canonical" ] || die "cannot canonicalize existing checkout before update lock"+ base="$(install_private_state_dir "${MSO_UPDATE_STATE_DIR:-$HOME/.mso/private/update-state}")"+ key="$(printf '%s' "$canonical" | sha256sum | awk '{print $1}')"; [[ "$key" =~ ^[0-9a-f]{64}$ ]] || die "cannot derive installer update-lock scope"+ state="$(install_private_state_dir "$base/$key")"; lock="$(install_private_state_ensure_file "$state/transaction.lock")"exec {INSTALL_EARLY_UPDATE_LOCK_FD}<>"$lock" || die "cannot open installer update transaction lock"- timeout="${MSO_UPDATE_LOCK_TIMEOUT_SECONDS:-900}"- [[ "$timeout" =~ ^[0-9]+([.][0-9]+)?$ ]] || die "invalid installer update-lock timeout"- if ! flock -x -w "$timeout" "$INSTALL_EARLY_UPDATE_LOCK_FD"; then- exec {INSTALL_EARLY_UPDATE_LOCK_FD}>&- || true- INSTALL_EARLY_UPDATE_LOCK_FD=''- die "another MSO installer/update/deploy transaction is still running for $canonical"- fi- INSTALL_EARLY_UPDATE_LOCK_HELD=1- INSTALL_EARLY_UPDATE_LOCK_FILE="$lock"- INSTALL_EARLY_UPDATE_CANONICAL_ROOT="$canonical"- trap install_early_update_lock_release EXIT+ timeout="${MSO_UPDATE_LOCK_TIMEOUT_SECONDS:-900}"; [[ "$timeout" =~ ^[0-9]+([.][0-9]+)?$ ]] || die "invalid installer update-lock timeout"+ if ! flock -x -w "$timeout" "$INSTALL_EARLY_UPDATE_LOCK_FD"; then exec {INSTALL_EARLY_UPDATE_LOCK_FD}>&- || true; INSTALL_EARLY_UPDATE_LOCK_FD=''; die "another MSO installer/update/deploy transaction is still running for $canonical"; fi+ INSTALL_EARLY_UPDATE_LOCK_HELD=1; INSTALL_EARLY_UPDATE_LOCK_FILE="$lock"; INSTALL_EARLY_UPDATE_CANONICAL_ROOT="$canonical"; trap install_early_update_lock_release EXIT}install_early_update_lock_acquirediff --git a/scripts/install-update-lock-contract.test.ts b/scripts/install-update-lock-contract.test.tsindex 5cd7301f..111f7a51 100644--- a/scripts/install-update-lock-contract.test.ts+++ b/scripts/install-update-lock-contract.test.ts@@ -20,4 +20,11 @@ describe("installer update transaction ordering", () => {expect(helper).toContain('UPDATE_LOCK_FD="$INSTALL_EARLY_UPDATE_LOCK_FD"');expect(helper).toContain('[ "$UPDATE_LOCK_HELD" = 1 ] || update_lock_acquire');});+ it("does not require the private-state helper from the pre-upgrade checkout", () => {+ const core = fs.readFileSync(path.join(ROOT, "scripts/install-core.sh"), "utf8");+ expect(core).not.toContain('$DIR/scripts/lib/private-state.sh');+ expect(core).toContain("install_private_state_dir()");+ expect(core).toContain("install_private_state_ensure_file()");+ });+});diff --git a/scripts/install.sh b/scripts/install.shindex 50fd6d59..b1111075 100644--- a/scripts/install.sh+++ b/scripts/install.sh@@ -12,7 +12,7 @@ set -Eeuo pipefailumask 077CORE_URL="${MSO_INSTALL_CORE_URL:-https://raw.githubusercontent.com/rahmanef63/mso/main/scripts/install-core.sh}"-CORE_SHA256="2eab509ebc3d461495a9e0b54b12ebd5b90e59b64d44ff76888da34d4628b248"+CORE_SHA256="9967738ca845c6ee462d2b98b5bde8bbb1ec79cce99316659d646d70e4fbc319"CORE_EOF='# MSO_INSTALLER_CORE_EOF'TMP_INSTALLER=''diff --git a/scripts/mso-update b/scripts/mso-updateold mode 100755new mode 100644index 420e900e..250266ea--- a/scripts/mso-update+++ b/scripts/mso-update@@ -107,7 +107,7 @@ notice() {if [ -s "$stamp" ] && mso_private_state_validate_file "$stamp" >/dev/null 2>&1; then last="$(cat "$stamp" 2>/dev/null || printf 0)"; fiif ! [[ "$last" =~ ^[0-9]+$ ]] || [ $((now-last)) -ge 21600 ]; thenprintf '%s\n' "$now" | mso_private_state_atomic_write "$stamp" >/dev/null 2>&1 || true- (cd "$ROOT" && nohup git fetch --quiet origin main >/dev/null 2>&1 </dev/null &) || true+ (cd "$ROOT" && nohup git fetch --quiet --no-write-fetch-head origin main >/dev/null 2>&1 </dev/null &) || truefiread -r relation ahead n < <(update_git_relation "$ROOT") || return 0if [ "$relation" = ahead ] || [ "$relation" = diverged ]; thendiff --git a/scripts/mso-update-notice-contract.test.ts b/scripts/mso-update-notice-contract.test.tsnew file mode 100644index 00000000..093c3170--- /dev/null+++ b/scripts/mso-update-notice-contract.test.ts@@ -0,0 +1,11 @@+import fs from "node:fs";+import path from "node:path";+import { describe, expect, it } from "vitest";++describe("background update notice", () => {+ it("fetches origin/main without mutating FETCH_HEAD", () => {+ const src = fs.readFileSync(path.join(process.cwd(), "scripts/mso-update"), "utf8");+ const line = src.split("\n").find((value) => value.includes("nohup git fetch") && value.includes("origin main"));+ expect(line).toContain("--no-write-fetch-head");+ });+});