Skip to content

Claude Code. Any Model. The most powerful AI coding agent now speaks every language.

refactor(recovery): read magmuxPaneCapability in the ambient UI branch

Jack Rudenko3863ddf04890
diff --git a/packages/cli/src/claude-runner.ts b/packages/cli/src/claude-runner.ts
index 357cb3c4..d755b0fb 100644
--- a/packages/cli/src/claude-runner.ts
+++ b/packages/cli/src/claude-runner.ts
@@ -2051,7 +2051,7 @@ export async function runClaudeWithProxy(
// after the user had already quit.
void shutdownRecoveryUi();
});
- } else if (recoverySurfaceAllowed() && config.interactive && process.env.MAGMUX_SOCK) {
+ } else if (recoverySurfaceAllowed() && paneCapability.kind === "ambient") {
// Already inside someone else's magmux — `team --grid --mode interactive`,
// or a user who launched claudish in a pane by hand. There is nothing to
// wrap, but there IS a multiplexer to ask for a pane, so the recovery UI
@@ -2060,6 +2060,11 @@ export async function runClaudeWithProxy(
// serves the banner, and the losers still retry and still recover — they
// simply hold no lease and answer inline at exhaustion, which is exactly
// what "a retryable status only while the reason is legible" requires.
+ //
+ // The predicate is `magmuxPaneCapability()`'s, the same one the watchdog
+ // and the wrap above read. It used to be restated here as
+ // `config.interactive && process.env.MAGMUX_SOCK` — two statements of one
+ // rule, which `network-recovery.md` forbids because they drift.
installRecoveryUi(null);
}
diff --git a/packages/cli/src/launcher/magmux-wrapper.ts b/packages/cli/src/launcher/magmux-wrapper.ts
index fcd140d1..5de9eac8 100644
--- a/packages/cli/src/launcher/magmux-wrapper.ts
+++ b/packages/cli/src/launcher/magmux-wrapper.ts
@@ -190,8 +190,10 @@ export function magmuxPaneCapability(
// `O_EXCL` lock in `magmux-ui.ts` is what keeps the grid to ONE banner rather
// than N.
//
- // Checked BEFORE the TTY gate on purpose, to match `claude-runner.ts`'s
- // ambient branch, which asks only for `interactive && MAGMUX_SOCK`.
+ // Checked BEFORE the TTY gate on purpose: the ambient recovery UI has always
+ // installed against an ambient socket without asking for a TTY.
+ // `claude-runner.ts`'s ambient branch reads this result (`kind === "ambient"`)
+ // rather than restating the rule.
const ambient = parentEnv.MAGMUX_SOCK;
if (ambient) return { kind: "ambient", sock: ambient };
if (!input.stdoutIsTty) return { kind: "none", reason: "no-tty" };
diff --git a/packages/cli/src/recovery/settings.test.ts b/packages/cli/src/recovery/settings.test.ts
index 97fdb457..1bcae781 100644
--- a/packages/cli/src/recovery/settings.test.ts
+++ b/packages/cli/src/recovery/settings.test.ts
@@ -349,7 +349,9 @@ describe("claude-runner asks that gate, and not the UI switch alone", () => {
});
test("the ambient-magmux branch consults it too", () => {
- const branch = code.split("\n").find((l) => l.includes("MAGMUX_SOCK") && l.includes("else if"));
+ const branch = code
+ .split("\n")
+ .find((l) => l.includes("else if") && /ambient|MAGMUX_SOCK/.test(l));
expect(branch, "could not find the ambient branch in claude-runner.ts").toBeTruthy();
expect(branch).toContain("recoverySurfaceAllowed()");
expect(
@@ -358,4 +360,17 @@ describe("claude-runner asks that gate, and not the UI switch alone", () => {
: null
).toBeNull();
});
+
+ test("the ambient branch reads magmuxPaneCapability(), not its own MAGMUX_SOCK test (F8)", () => {
+ // `network-recovery.md`: one predicate decides the surface. The ambient branch
+ // used to restate it as `config.interactive && process.env.MAGMUX_SOCK`, so a
+ // case added to `magmuxPaneCapability()` (the pane child, D22) would still
+ // install the recovery UI here.
+ const branch = code
+ .split("\n")
+ .find((l) => l.includes("else if") && /ambient|MAGMUX_SOCK/.test(l));
+ expect(branch, "could not find the ambient branch in claude-runner.ts").toBeTruthy();
+ expect(branch).toContain('paneCapability.kind === "ambient"');
+ expect(branch).not.toContain("MAGMUX_SOCK");
+ });
});