Claude Code. Any Model. The most powerful AI coding agent now speaks every language.
fix(pane): keep a socket whose lstat fails for a reason other than ENOENT
Jack Rudenko84e461c1ecc2
diff --git a/packages/cli/src/pane/pane-registry.test.ts b/packages/cli/src/pane/pane-registry.test.tsindex 5896b702..5c1251e4 100644--- a/packages/cli/src/pane/pane-registry.test.ts+++ b/packages/cli/src/pane/pane-registry.test.ts@@ -1012,6 +1012,22 @@ describe("a dial that reports ENOENT is checked against the path (Bun < 1.4 repo});expect(await probeWithEnoent(refused, false)).toEqual({ state: "stale", code: "ECONNREFUSED" });}, 20_000);++ test("an lstat that fails with anything but ENOENT proves nothing: inconclusive, even with magmux dead", async () => {+ const t = env();+ const root = ensureSockRoot(t.sockRoot);+ const hidden = join(root, "hidden");+ mkdirSync(hidden, { mode: 0o700 });+ const sock = join(hidden, "magmux-hidden.sock");+ await staleSocket(sock);+ chmodSync(hidden, 0o000); // lstat of the socket inside now fails with EACCES+ try {+ expect(await probeWithEnoent(sock, false)).toEqual({ state: "inconclusive", code: "EACCES" });+ } finally {+ chmodSync(hidden, 0o700);+ }+ expect(existsSync(sock)).toBe(true);+ }, 20_000);});describe("the pane-socket probe: ENOENT, or ECONNREFUSED with magmux proven dead, is stale", () => {diff --git a/packages/cli/src/pane/pane-registry.ts b/packages/cli/src/pane/pane-registry.tsindex 524f2f74..21df395e 100644--- a/packages/cli/src/pane/pane-registry.ts+++ b/packages/cli/src/pane/pane-registry.ts@@ -578,8 +578,9 @@ export async function probeSocket(sockPath: string, magmuxMayLive: boolean): Pro* A failed dial's errno, with ENOENT checked against the path itself. Bun before 1.4* reports ENOENT for EVERY failed unix connect (measured, 1.3.10 on darwin: a refused* socket, a mode-000 socket and a plain file all answer ENOENT), so ENOENT alone would- * read a live pane's socket as gone. The path decides instead: missing → ENOENT; not a- * socket → ENOTSOCK; not writable → EACCES; any other socket → ECONNREFUSED, which is+ * read a live pane's socket as gone. The path decides instead: missing (lstat's own+ * ENOENT) → ENOENT; lstat failing otherwise → its errno; not a socket → ENOTSOCK; not+ * writable → EACCES; any other socket → ECONNREFUSED, which is* stale only with pid evidence that its magmux is dead (`probeSocket`).*/function dialErrno(reported: string, sockPath: string): string {@@ -587,8 +588,9 @@ function dialErrno(reported: string, sockPath: string): string {let isSocket: boolean;try {isSocket = lstatSync(sockPath).isSocket();- } catch {- return "ENOENT";+ } catch (e) {+ // only lstat's own ENOENT proves the path gone; EACCES, EPERM, EIO prove nothing+ return (e as NodeJS.ErrnoException).code ?? "unknown";}if (!isSocket) return "ENOTSOCK";try {