Claude Code. Any Model. The most powerful AI coding agent now speaks every language.
fix(mcp): run the magmux --version probe without blocking the event loop
Jack Rudenkocab15850bc7b
diff --git a/packages/cli/src/pane/pane-launch.test.ts b/packages/cli/src/pane/pane-launch.test.tsindex 6275f5bd..d2b03baa 100644--- a/packages/cli/src/pane/pane-launch.test.ts+++ b/packages/cli/src/pane/pane-launch.test.ts@@ -1,5 +1,5 @@import { afterEach, describe, expect, test } from "bun:test";-import { chmodSync, mkdirSync, mkdtempSync, rmSync, symlinkSync } from "node:fs";+import { chmodSync, mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from "node:fs";import { tmpdir } from "node:os";import { join } from "node:path";import {@@ -9,6 +9,7 @@ import {PaneEnvTooLargeError,PaneRootError,SHELL_SHIM,+ assertMagmuxAvailable,buildClaudishPaneArgv,buildPaneEnv,createLaunchDirs,@@ -270,6 +271,25 @@ describe("watcher argv and version gate", () => {expect(WATCHER_SCRIPT).not.toContain("u'; rm -rf /");});+ test("the magmux version probe never blocks the event loop; an old version is refused", async () => {+ const dir = tmp();+ const slow = join(dir, "magmux-slow");+ writeFileSync(slow, "#!/bin/sh\nsleep 0.6\necho 'magmux 0.14.0 (fake)'\n");+ chmodSync(slow, 0o755);+ let ticks = 0;+ const timer = setInterval(() => ticks++, 50);+ try {+ expect(await assertMagmuxAvailable(slow)).toEqual({ binary: slow, version: "0.14.0" });+ } finally {+ clearInterval(timer);+ }+ expect(ticks).toBeGreaterThanOrEqual(5); // a synchronous probe would let none run+ const old = join(dir, "magmux-old");+ writeFileSync(old, "#!/bin/sh\necho 'magmux 0.13.9'\n");+ chmodSync(old, 0o755);+ await expect(assertMagmuxAvailable(old)).rejects.toThrow(/panes need >= 0.14.0/);+ });+test("versionAtLeast", () => {expect(versionAtLeast("0.14.0", "0.14.0")).toBe(true);expect(versionAtLeast("0.15.2", "0.14.0")).toBe(true);diff --git a/packages/cli/src/pane/pane-launch.ts b/packages/cli/src/pane/pane-launch.tsindex e4ba93fb..f3b66621 100644--- a/packages/cli/src/pane/pane-launch.ts+++ b/packages/cli/src/pane/pane-launch.ts@@ -15,10 +15,11 @@* the parent's or a sibling's transcript (research-magmux §3).*/-import { type ChildProcess, execFileSync, spawn } from "node:child_process";+import { type ChildProcess, execFile, spawn } from "node:child_process";import { randomBytes } from "node:crypto";import { chmodSync, lstatSync, mkdirSync, mkdtempSync, writeFileSync } from "node:fs";import { join, resolve } from "node:path";+import { promisify } from "node:util";import {CLAUDISH_EXITING_FLAGS,CLAUDISH_FLAG_ARITY,@@ -492,6 +493,7 @@ export function versionAtLeast(v: string, min: string): boolean {}const magmuxCache = new Map<string, { binary: string; version: string }>();+const execFileAsync = promisify(execFile);/** The magmux binary and its version (≥ 0.14.0), cached per process. Never a `-p` fallback. */export async function assertMagmuxAvailable(@@ -506,7 +508,9 @@ export async function assertMagmuxAvailable();let out = "";try {- out = execFileSync(found, ["--version"], { encoding: "utf8", timeout: 5000 });+ // async: the first create_session or team run must not stall the MCP server's event+ // loop for up to 5 s (every other session's frames and socket share it)+ out = (await execFileAsync(found, ["--version"], { encoding: "utf8", timeout: 5000 })).stdout;} catch (e) {throw new MagmuxUnavailableError(`magmux_unavailable: ${found} --version failed: ${e instanceof Error ? e.message : String(e)}`