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(agent): make restart process-safe

Rahman8afea89e3198
diff --git a/README.md b/README.md
index 1b066047..741e49e8 100644
--- a/README.md
+++ b/README.md
@@ -215,9 +215,10 @@ selects, and **Esc** cancels. No provider/model number has to be memorized. `/se
as the primary label, and compact `modified …` metadata. Durable session IDs stay hidden in the normal
picker UI but remain accepted by scriptable `--resume`/`/resume` queries. `/new [name]` persists the
current session and switches the same terminal to a fresh durable session. `/restart` is a soft Agent
-runtime reload: it persists the current session, closes the composer, then relaunches the current CLI
-against that same session id. It does **not** restart the MSO service or VPS; it exists so updated CLI
-code plus the latest dynamic skill/tool/plugin catalog are picked up without abandoning the conversation.
+process replacement: it persists the current session, closes the composer, then reloads the latest CLI
+and Agent modules against that exact same durable session id. Repeated restarts keep a constant process
+depth. It does **not** restart the MSO service or VPS; updated code plus the latest dynamic
+skill/tool/plugin catalog are picked up without abandoning the conversation.
In the Agent slash palette, executable skills carry lifecycle markers so their state is visible before and after use:
`◇ ready` → `◆ queued` (selected for the next message) → `✓ invoked` (actually sent with a model turn).
The compact status line mirrors queued/invoked skill state and the current permission mode. MSO defaults
diff --git a/bin/mso b/bin/mso
index f5fc8e5c..ae4058ae 100755
--- a/bin/mso
+++ b/bin/mso
@@ -127,7 +127,7 @@
# Docs: https://github.com/rahmanef63/mso
set -euo pipefail
-VERSION="1.8.1"
+VERSION="1.8.2"
ROOT="$(cd "$(dirname "$(readlink -f "$0")")/.." && pwd)"
die() { echo "mso: $*" >&2; exit 1; }
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index 84bd6677..6fb1e1f5 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -16,6 +16,7 @@ this is the *what*, and it is what Settings → About shows as “What's new”.
**Fixed**
+- `agent` make restart process-safe
- `a2a` harden remote v1 delegation
## 2026-09-01
diff --git a/docs/PROGRESS.md b/docs/PROGRESS.md
index 260c8b59..e52a808f 100644
--- a/docs/PROGRESS.md
+++ b/docs/PROGRESS.md
@@ -2,6 +2,12 @@
Running log of what shipped each phase. Newest at top.
+## 2026-09-02 — MSO 1.8.2 constant-depth Agent restart
+
+- **Restart lifecycle fix:** `/restart` now uses process replacement (`execve`) instead of `spawnSync`. Repeated refreshes no longer leave prior Agent processes blocked behind their children.
+- **Wrapper boundary:** interactive `mso agent` now `exec`s its Node runtime, so the CLI wrapper itself does not remain as an extra waiting parent. A restart replaces the same process chain with the latest `bin/mso` and Agent modules while loading the exact same durable session id through a restart-only path; normal `/resume` continuation semantics remain unchanged.
+- **Fail closed:** runtimes without process replacement support refuse `/restart` rather than silently falling back to a nesting child process. Node 22 on the supported MSO runtime provides `process.execve`.
+
## 2026-09-02 — MSO 1.8.1 Agent soft restart + new session
- **`/restart`:** soft-reloads the interactive Agent process, not the MSO service/VPS. The current durable session is persisted, the composer closes cleanly, then the current CLI is relaunched with `--resume <same-session-id>`, so updated CLI modules plus the latest dynamic tool/skill/plugin catalog are loaded without abandoning conversation history.
diff --git a/scripts/mso-agent-contract.test.ts b/scripts/mso-agent-contract.test.ts
index 849cdf76..992bea94 100644
--- a/scripts/mso-agent-contract.test.ts
+++ b/scripts/mso-agent-contract.test.ts
@@ -68,7 +68,9 @@ describe("MSO terminal agent contract", () => {
expect(src).toContain("syncPromptHistory");
expect(src).toContain("startNewSession");
expect(src).toContain("relaunchAgentSession");
- expect(src).toContain('["agent", "--resume", id]');
+ expect(src).toContain('[command, "agent", "--restart-session", id]');
+ expect(src).toContain("execve(command");
+ expect(src).toContain("restartSessionArg");
expect(src).toContain("permissionCompletionItems");
expect(src).toContain("approvesTool");
expect(src).toContain("--yolo");
diff --git a/scripts/mso-agent-lifecycle.mjs b/scripts/mso-agent-lifecycle.mjs
index 0f88709c..d413b456 100644
--- a/scripts/mso-agent-lifecycle.mjs
+++ b/scripts/mso-agent-lifecycle.mjs
@@ -1,4 +1,3 @@
-import { spawnSync } from "node:child_process";
import process from "node:process";
import { CLI } from "./mso-agent-runtime.mjs";
@@ -18,10 +17,12 @@ export function consumeRestartUiState() {
export function relaunchAgentSession(
{ cli, sessionId, permission = "ask", statusBar = true },
- runner = spawnSync,
+ execve = process.execve,
) {
const id = String(sessionId || "").trim();
if (!id) throw new Error("cannot restart MSO Agent without a durable session id");
+ if (typeof execve !== "function") throw new Error("this Node runtime cannot replace the Agent process safely");
+ const command = String(cli || "mso");
const env = {
...process.env,
[RESTART_PERMISSION_ENV]: ["ask", "auto", "yolo"].includes(permission)
@@ -29,12 +30,11 @@ export function relaunchAgentSession(
: "ask",
[RESTART_STATUSBAR_ENV]: statusBar === false ? "off" : "on",
};
- const result = runner(String(cli || "mso"), ["agent", "--resume", id], {
- stdio: "inherit",
- env,
- });
- if (result?.error) throw result.error;
- return Number.isInteger(result?.status) ? result.status : 1;
+ // execve replaces the current process image instead of spawning a child. Combined
+ // with the CLI wrapper's `exec node`, repeated /restart keeps a constant process
+ // depth and reloads both the current wrapper and Agent modules from disk.
+ execve(command, [command, "agent", "--restart-session", id], env);
+ throw new Error("MSO Agent process replacement unexpectedly returned");
}
export function relaunchCurrentAgentSession(session) {
diff --git a/scripts/mso-agent-lifecycle.test.ts b/scripts/mso-agent-lifecycle.test.ts
index b6a07f80..03513296 100644
--- a/scripts/mso-agent-lifecycle.test.ts
+++ b/scripts/mso-agent-lifecycle.test.ts
@@ -10,27 +10,25 @@ afterEach(() => {
describe("MSO Agent soft restart", () => {
it("relaunches the same durable session in the same inherited terminal", () => {
const calls: unknown[][] = [];
- const runner = (...args: unknown[]) => {
+ const execve = (...args: unknown[]) => {
calls.push(args);
- return { status: 0 };
+ throw new Error("execve sentinel");
};
- const status = relaunchAgentSession(
+ expect(() => relaunchAgentSession(
{
cli: "/opt/mso/bin/mso",
sessionId: "sess_same_123",
permission: "auto",
statusBar: false,
},
- runner as never,
- );
- expect(status).toBe(0);
+ execve as never,
+ )).toThrow(/execve sentinel/);
expect(calls).toHaveLength(1);
- const [command, args, options] = calls[0] as [string, string[], { stdio: string; env: NodeJS.ProcessEnv }];
+ const [command, args, env] = calls[0] as [string, string[], NodeJS.ProcessEnv];
expect(command).toBe("/opt/mso/bin/mso");
- expect(args).toEqual(["agent", "--resume", "sess_same_123"]);
- expect(options.stdio).toBe("inherit");
- expect(options.env.MSO_AGENT_RESTART_PERMISSION).toBe("auto");
- expect(options.env.MSO_AGENT_RESTART_STATUSBAR).toBe("off");
+ expect(args).toEqual(["/opt/mso/bin/mso", "agent", "--restart-session", "sess_same_123"]);
+ expect(env.MSO_AGENT_RESTART_PERMISSION).toBe("auto");
+ expect(env.MSO_AGENT_RESTART_STATUSBAR).toBe("off");
});
it("consumes restart-only UI state so it does not leak into later child processes", () => {
@@ -43,7 +41,13 @@ describe("MSO Agent soft restart", () => {
it("fails closed when no durable session id exists", () => {
expect(() =>
- relaunchAgentSession({ cli: "mso", sessionId: "" }, (() => ({ status: 0 })) as never),
+ relaunchAgentSession({ cli: "mso", sessionId: "" }, (() => undefined) as never),
).toThrow(/durable session id/);
});
+
+ it("fails closed rather than falling back to a nesting child process", () => {
+ expect(() =>
+ relaunchAgentSession({ cli: "mso", sessionId: "sess_1" }, null as never),
+ ).toThrow(/cannot replace the Agent process safely/);
+ });
});
diff --git a/scripts/mso-agent-session-ui-state.test.ts b/scripts/mso-agent-session-ui-state.test.ts
index 751722ef..696615de 100644
--- a/scripts/mso-agent-session-ui-state.test.ts
+++ b/scripts/mso-agent-session-ui-state.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
-import { applyNewSessionState } from "./mso-agent-session-ui.mjs";
+import { applyNewSessionState, restartSessionArg } from "./mso-agent-session-ui.mjs";
describe("MSO Agent /new session transition", () => {
it("switches to a new durable id and clears conversation-local state", () => {
@@ -37,4 +37,10 @@ describe("MSO Agent /new session transition", () => {
);
expect(session.titleOverride).toBe("baco-2");
});
+ it("parses only the restart-only exact session argument", () => {
+ expect(restartSessionArg(["--restart-session", "sess_exact_1"])).toBe("sess_exact_1");
+ expect(restartSessionArg(["--resume", "sess_other"])).toBeNull();
+ expect(() => restartSessionArg(["--restart-session"])).toThrow(/exact durable session id/);
+ });
+
});
diff --git a/scripts/mso-agent-session-ui.mjs b/scripts/mso-agent-session-ui.mjs
index ded571ff..705532a3 100644
--- a/scripts/mso-agent-session-ui.mjs
+++ b/scripts/mso-agent-session-ui.mjs
@@ -1,4 +1,4 @@
-import { C, createCliSession, listCliSessions, renameCliSession, resumeCliSession, saveCliSession } from "./mso-agent-runtime.mjs";
+import { C, createCliSession, listCliSessions, loadCliSession, renameCliSession, resumeCliSession, saveCliSession } from "./mso-agent-runtime.mjs";
import { sessionCompletionItems, sessionPromptHistory, visibleSessionRows } from "./mso-agent-sessions.mjs";
function autoTitle(history) {
@@ -93,6 +93,15 @@ export function resumeArg(argv) {
return value;
}
-export async function startupSession(requested) {
+export function restartSessionArg(argv) {
+ const index = argv.indexOf("--restart-session");
+ if (index < 0) return null;
+ const value = argv[index + 1];
+ if (!value || value.startsWith("-")) throw new Error("--restart-session requires an exact durable session id");
+ return value;
+}
+
+export async function startupSession(requested, restartSessionId = null) {
+ if (restartSessionId) return loadCliSession(restartSessionId);
return requested ? resumeCliSession(requested) : createCliSession();
}
diff --git a/scripts/mso-agent.mjs b/scripts/mso-agent.mjs
index bc08ba29..273d26f0 100644
--- a/scripts/mso-agent.mjs
+++ b/scripts/mso-agent.mjs
@@ -6,7 +6,7 @@ import { AgentComposer } from "./mso-agent-composer.mjs";
import { AgentInterruptManager, isAbortError } from "./mso-agent-interrupt.mjs";
import { slashCompletionItems } from "./mso-agent-slash.mjs";
import { addUsage, renderStatusBar } from "./mso-agent-status.mjs";
-import { persistSession, resumeArg, startupSession, syncPromptHistory } from "./mso-agent-session-ui.mjs";
+import { persistSession, restartSessionArg, resumeArg, startupSession, syncPromptHistory } from "./mso-agent-session-ui.mjs";
import { C, api, printBanner, state, streamTurn } from "./mso-agent-runtime.mjs";
import { handleSlash } from "./mso-agent-commands.mjs";
import { approvesTool, nextPermissionMode, permissionMode, permissionPrompt } from "./mso-agent-permissions.mjs";
@@ -147,14 +147,15 @@ async function main() {
console.error("mso agent needs an interactive terminal. For autonomous one-shot use: mso agent --oneshot \"<prompt>\" [--json]");
process.exit(2);
}
- const requested = resumeArg(argv);
+ const restartSessionId = restartSessionArg(argv);
+ const requested = restartSessionId ? null : resumeArg(argv);
const restartUi = consumeRestartUiState();
const forcedPermission = argv.some((arg) => ["--yolo", "-yolo", "-y"].includes(arg))
? "yolo"
: (permissionMode(restartUi.permission)?.id || "ask");
const [s, agentSession] = await Promise.all([
state(),
- startupSession(requested),
+ startupSession(requested, restartSessionId),
]);
if (!agentSession || agentSession.source !== "cli") throw new Error("could not establish a CLI MSO Agent session");
printBanner(s, agentSession);
@@ -165,7 +166,7 @@ async function main() {
pendingSkill: null,
activeSkill: null,
lastInvokedSkill: null,
- titleOverride: requested ? (agentSession.title || null) : null,
+ titleOverride: (requested || restartSessionId) ? (agentSession.title || null) : null,
usage: { inputTokens: 0, outputTokens: 0, totalTokens: 0 },
lastElapsedMs: 0,
statusBar: restartUi.statusBar ?? true,
@@ -227,8 +228,7 @@ async function main() {
}
if (restartRequested) {
console.log(`${C.dim}↻ refreshing Agent runtime · keeping ${session.agentSession.title || "current session"}${C.reset}`);
- const code = relaunchCurrentAgentSession(session);
- if (code !== 0) process.exitCode = code;
+ relaunchCurrentAgentSession(session);
}
}
diff --git a/scripts/mso-cli-agent.sh b/scripts/mso-cli-agent.sh
index 661acddb..2e3ce912 100755
--- a/scripts/mso-cli-agent.sh
+++ b/scripts/mso-cli-agent.sh
@@ -432,7 +432,7 @@ run_agent() {
cfg=$(jget "/api/config")
printf '%s' "$cfg" | ai_config_ready || die "active model is not usable; run: mso models list && mso model"
fi
- MSO_AGENT_BASE="$B" MSO_AGENT_ORIGIN="$B" MSO_AGENT_JAR="$JAR" \
+ exec env MSO_AGENT_BASE="$B" MSO_AGENT_ORIGIN="$B" MSO_AGENT_JAR="$JAR" \
MSO_AGENT_CLI="$ROOT/bin/mso" MSO_AGENT_VERSION="$VERSION" \
node "$ROOT/scripts/mso-agent.mjs" "$@"
}
diff --git a/scripts/mso-model-dx-contract.test.ts b/scripts/mso-model-dx-contract.test.ts
index bd37d031..57cdf28c 100644
--- a/scripts/mso-model-dx-contract.test.ts
+++ b/scripts/mso-model-dx-contract.test.ts
@@ -29,7 +29,7 @@ const all = [cli, agentCli, configRoute, oauthRoute, slash, picker].join("\n");
describe("MSO model/provider/session CLI contract", () => {
it("keeps provider auth (`models`) separate from active selection (`model`)", () => {
- expect(cli).toContain('VERSION="1.8.1"');
+ expect(cli).toContain('VERSION="1.8.2"');
expect(cli).toContain("models * Configure AI providers/auth");
expect(cli).toContain("model [ref] Select active model");
expect(agentCli).toContain("run_models()");