Claude Code. Any Model. The most powerful AI coding agent now speaks every language.
fix(recovery): drop the retry watchdog in MCP pane children
Jack Rudenkof38c7e94b4b0
diff --git a/packages/cli/src/launcher/magmux-wrapper.ts b/packages/cli/src/launcher/magmux-wrapper.tsindex 5de9eac8..0fd67b60 100644--- a/packages/cli/src/launcher/magmux-wrapper.ts+++ b/packages/cli/src/launcher/magmux-wrapper.ts@@ -47,6 +47,7 @@ import {} from "node:fs";import { type Socket, connect as netConnect } from "node:net";import { join } from "node:path";+import { isPaneChild } from "../pane/child-env.js";import { findMagmuxBinaryOrNull } from "./magmux-binary.js";/**@@ -165,17 +166,26 @@ export function buildLauncherScript(* `ambient` — already inside someone else's magmux (`team --grid`, or a user* who launched claudish in a pane): nothing to wrap, but there IS a* multiplexer to ask for a pane.- * `none` — no surface is reachable from this launch.+ * `none` — no surface is reachable from this launch, or none may be used.*/export type MagmuxPaneCapability =| { kind: "wrap"; magmux: string }| { kind: "ambient"; sock: string }- | { kind: "none"; reason: "not-interactive" | "no-tty" | "no-magmux" };+ | { kind: "none"; reason: "pane-child" | "not-interactive" | "no-tty" | "no-magmux" };export function magmuxPaneCapability(input: Pick<MagmuxWrapInput, "interactive" | "stdoutIsTty" | "parentEnv" | "magmuxBinary">): MagmuxPaneCapability {const parentEnv = input.parentEnv ?? process.env;+ // AN MCP PANE CHILD IS NEVER ELIGIBLE (D22), checked FIRST — above all before+ // the ambient branch, because its pane IS a magmux and exports `MAGMUX_SOCK`.+ // That magmux is headless: nobody sees a banner drawn there, so the reason+ // for holding a request would be legible nowhere, which is the one condition+ // under which `network-recovery.md` accepts the watchdog's ~300 client+ // re-POSTs. The recovery overlay would also paint over the screen the MCP+ // server reads to classify the pane. What remains is tier 1's bounded hold+ // (`TIER1_DEADLINE_MS`) and, with no lease, an inline 400 at exhaustion.+ if (isPaneChild(parentEnv)) return { kind: "none", reason: "pane-child" };if (!input.interactive) return { kind: "none", reason: "not-interactive" };// ALREADY INSIDE A MULTIPLEXER — do not nest one.//diff --git a/packages/cli/src/recovery/settings.test.ts b/packages/cli/src/recovery/settings.test.tsindex 1bcae781..8d373d89 100644--- a/packages/cli/src/recovery/settings.test.ts+++ b/packages/cli/src/recovery/settings.test.ts@@ -19,6 +19,7 @@ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } frimport { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";import { tmpdir } from "node:os";import { join, resolve } from "node:path";+import { magmuxPaneCapability } from "../launcher/magmux-wrapper.js";import { readRecoveryEnabled, readRecoveryUi } from "../profile-config.js";import {CLIENT_CEILING_CLAMP_MS,@@ -26,6 +27,7 @@ import {DEFAULT_API_TIMEOUT_MS,DEFAULT_TIER1_DEADLINE_MS,TIER1_DEADLINE_FLOOR_MS,+ applyRetryWatchdog,logDeadlineIfShortened,recoverySurfaceAllowed,resetDeadlineNotice,@@ -321,6 +323,61 @@ describe("recoverySurfaceAllowed — BOTH switches, because a wrap nothing can u});});+describe("an MCP pane child is never eligible for a recovery surface (D22)", () => {+ // The pane is a headless magmux: it exports MAGMUX_SOCK, so without the+ // pane-child case the child would read as `ambient`, export the ~300-attempt+ // watchdog and install a banner nobody can see, over the screen the MCP+ // server classifies.+ const paneChildEnv = {+ CLAUDISH_PANE_CHILD: "1",+ MAGMUX_SOCK: "/tmp/claudish-mux-501/magmux-c1-t1.sock",+ };++ test("magmuxPaneCapability answers none/pane-child before the ambient branch", () => {+ expect(+ magmuxPaneCapability({+ interactive: true,+ stdoutIsTty: true,+ parentEnv: paneChildEnv,+ magmuxBinary: "/opt/magmux",+ })+ ).toEqual({ kind: "none", reason: "pane-child" });+ });++ test("the same environment without the marker is still ambient", () => {+ expect(+ magmuxPaneCapability({+ interactive: true,+ stdoutIsTty: false,+ parentEnv: { MAGMUX_SOCK: paneChildEnv.MAGMUX_SOCK },+ magmuxBinary: null,+ })+ ).toEqual({ kind: "ambient", sock: paneChildEnv.MAGMUX_SOCK });+ });++ test("a pane child exports no watchdog and drops a claudish-marked inherited one", () => {+ const capability = magmuxPaneCapability({+ interactive: true,+ stdoutIsTty: false,+ parentEnv: paneChildEnv,+ });+ // What an MCP server started by a wrapped claudish session passes down.+ const env: Record<string, string | undefined> = {+ CLAUDE_CODE_RETRY_WATCHDOG: "1",+ CLAUDISH_SET_RETRY_WATCHDOG: "1",+ };+ applyRetryWatchdog(env, { paneEligible: capability.kind !== "none" });+ expect(env.CLAUDE_CODE_RETRY_WATCHDOG).toBeUndefined();+ expect(env.CLAUDISH_SET_RETRY_WATCHDOG).toBeUndefined();+ });++ test("a user's own unmarked watchdog survives in a pane child", () => {+ const env: Record<string, string | undefined> = { CLAUDE_CODE_RETRY_WATCHDOG: "1" };+ applyRetryWatchdog(env, { paneEligible: false });+ expect(env.CLAUDE_CODE_RETRY_WATCHDOG).toBe("1");+ });+});+describe("claude-runner asks that gate, and not the UI switch alone", () => {// A SOURCE GUARD, and it is the only thing that can fail on the defect that// actually shipped. The predicate above was always correct as an expression;