Claude Code. Any Model. The most powerful AI coding agent now speaks every language.
docs(recovery): closing the pane wedges the host TUI, and magmux already had the surface
Jack Rudenko3586b8b6dcf1
diff --git a/ai-docs/reports/network-recovery-pane-close-repro/post-close-render.ts b/ai-docs/reports/network-recovery-pane-close-repro/post-close-render.tsnew file mode 100644index 00000000..28d3f62b--- /dev/null+++ b/ai-docs/reports/network-recovery-pane-close-repro/post-close-render.ts@@ -0,0 +1,160 @@+/**+ * Does the host TUI survive the recovery pane CLOSING?+ *+ * Every Phase-7 capture was taken while the pane was still open — `C-17-final.txt`+ * still has "this pane closes on its own" in it. So the post-close screen was+ * never looked at. This looks at it.+ *+ * Bare PTY, no outer multiplexer, so magmux is the top-level multiplexer exactly+ * as it is for a user who types `claudish` in their own terminal.+ *+ * Usage: bun post-close-render.ts+ */+import { spawn } from "node:child_process";+import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";+import { join } from "node:path";+import { VtScreen } from "/Users/jack/mag/claudish/.claude/worktrees/recover/ai-docs/sessions/dev-feature-network-recovery-20260910-110514-0ad0a5a0/phase3/vt.ts";++const ROOT = "/Users/jack/mag/claudish/.claude/worktrees/recover";+const OUT = "/private/tmp/claude-501/-Users-jack-mag-claudish/5ea44449-884c-45a6-99c5-67b0ee7d3998/scratchpad/postclose";+const WORK = join(OUT, "work");+mkdirSync(WORK, { recursive: true });++const CLAUDISH_BIN = join(ROOT, "packages/cli/bin/claudish.cjs");+const PTY_HOST = join(ROOT, "ai-docs/sessions/dev-feature-network-recovery-20260910-110514-0ad0a5a0/phase3/pty-host.py");+const COLS = 120;+const ROWS = 44;+const UPSTREAM = "http://127.0.0.1:11434/v1/chat/completions";++const t0 = Date.now();+const note = (s: string) => console.log(`[${((Date.now() - t0) / 1000).toFixed(1)}s] ${s}`);+const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));++// ─── a port proven free ─────────────────────────────────────────────────────+const probe = Bun.serve({ port: 0, fetch: () => new Response("x") });+const DEAD_PORT = probe.port as number;+probe.stop(true);+await sleep(250);+note(`dead port ${DEAD_PORT}`);++const CONFIG = join(OUT, "config.json");+writeFileSync(+ CONFIG,+ JSON.stringify({+ version: 1,+ autoApproveConfirmedAt: new Date().toISOString(),+ customEndpoints: {+ recov: {+ kind: "complex",+ displayName: "Recovery Target",+ transport: "openai",+ baseUrl: `http://127.0.0.1:${DEAD_PORT}`,+ apiPath: "/v1/chat/completions",+ apiKey: "sk-recov",+ streamFormat: "openai-sse",+ models: ["recov-model"],+ },+ },+ predefinedEndpoints: { enabled: false },+ })+);++const vt = new VtScreen(COLS, ROWS);+const child = spawn(+ "python3",+ [PTY_HOST, String(COLS), String(ROWS), CLAUDISH_BIN, "-i", "-d", "--model", "recov@recov-model",+ "--dangerously-skip-permissions", "Reply with exactly one word: banana"],+ {+ cwd: WORK,+ stdio: ["pipe", "pipe", "pipe"],+ env: { ...process.env, CLAUDISH_CONFIG: CONFIG, COLUMNS: String(COLS), LINES: String(ROWS), TERM: "xterm-256color" },+ }+);+child.stdout.on("data", (d: Buffer) => vt.write(d.toString("utf-8")));+child.stderr.on("data", () => {});++function debugLog(): string {+ const dir = join(WORK, "logs");+ if (!existsSync(dir)) return "";+ const files = readdirSync(dir).filter((f) => f.endsWith(".log"))+ .map((f) => ({ f, m: Bun.file(join(dir, f)).lastModified })).sort((a, b) => b.m - a.m);+ if (!files[0]) return "";+ try { return readFileSync(join(dir, files[0].f), "utf-8"); } catch { return ""; }+}++// ─── startup prompts ────────────────────────────────────────────────────────+const answered = new Set<string>();+for (let i = 0; i < 60; i++) {+ await sleep(1_000);+ const tail = vt.render().slice(-1200);+ if (!answered.has("update") && /Update now\?/.test(tail)) {+ child.stdin.write("n\n"); answered.add("update"); note("declined update"); continue;+ }+ if (!answered.has("approve") && /Enable auto-approve\?/.test(tail)) {+ child.stdin.write("y\n"); answered.add("approve"); note("accepted auto-approve"); continue;+ }+ if (/Claude Code v|✻|✶|❯ /.test(tail)) { note("Claude Code is up"); break; }+}++// ─── wait for the ladder, then rescue ───────────────────────────────────────+let ladderAt = 0;+for (let i = 0; i < 120; i++) {+ await sleep(1_000);+ if (/\[Recovery\] episode .* opened/.test(debugLog())) { ladderAt = Date.now(); note("ladder opened"); break; }+}+if (!ladderAt) { note("FAIL: ladder never opened"); child.kill("SIGKILL"); process.exit(2); }++await sleep(20_000);+Bun.serve({+ port: DEAD_PORT, hostname: "127.0.0.1", idleTimeout: 240,+ async fetch(req) {+ const body = await req.text();+ return fetch(UPSTREAM, {+ method: "POST", headers: { "content-type": "application/json" },+ body: body.replace(/"model"\s*:\s*"[^"]*"/, '"model":"qwen2.5:0.5b"'),+ });+ },+});+note(`rescue server up on ${DEAD_PORT}`);++// ─── wait for recovery, then for the pane to close ──────────────────────────+let recoveredAt = 0;+for (let i = 0; i < 180; i++) {+ await sleep(1_000);+ if (/\[Recovery\].*recovered after/.test(debugLog())) { recoveredAt = Date.now(); note("recovered"); break; }+}+if (!recoveredAt) { note("FAIL: never recovered"); child.kill("SIGKILL"); process.exit(2); }++writeFileSync(join(OUT, "screen-while-open.txt"), `${vt.render()}\n`);+note("captured screen WHILE the pane is still open");++// PANE_LINGER_MS is 30s. Wait past it, then watch the screen settle.+for (const wait of [32, 36, 42, 50]) {+ while ((Date.now() - recoveredAt) / 1000 < wait) await sleep(500);+ const shot = vt.render();+ writeFileSync(join(OUT, `screen-close+${wait}s.txt`), `${shot}\n`);+ note(`captured at recovered+${wait}s`);+}++// ─── verdict ────────────────────────────────────────────────────────────────+const final = readFileSync(join(OUT, "screen-close+50s.txt"), "utf-8");+const lines = final.split("\n");+const lastContent = lines.map((l, i) => [l.trim(), i] as const).filter(([l]) => l.length > 0).pop();+const bottomRow = lastContent ? lastContent[1] : -1;+const blankBelow = ROWS - 1 - bottomRow;+const hasComposer = /^\s*[❯>]\s*$/m.test(final);++console.log("\n================ VERDICT ================");+console.log(`rows : ${ROWS}`);+console.log(`last painted row : ${bottomRow}`);+console.log(`blank rows below it : ${blankBelow}`);+console.log(`composer (input box) up? : ${hasComposer}`);+console.log(blankBelow > 5 || !hasComposer+ ? "RESULT: BROKEN — chrome stranded / no input box after the pane closed"+ : "RESULT: OK — full-height layout restored after the pane closed");+console.log("=========================================\n");+console.log(final.split("\n").slice(-20).join("\n"));++child.kill("SIGKILL");+await sleep(500);+process.exit(0);diff --git a/ai-docs/reports/network-recovery-pane-close-repro/screen-after-close.txt b/ai-docs/reports/network-recovery-pane-close-repro/screen-after-close.txtnew file mode 100644index 00000000..129ced3e--- /dev/null+++ b/ai-docs/reports/network-recovery-pane-close-repro/screen-after-close.txt@@ -0,0 +1,23 @@++ ▐▛███▛█ Claude Code v2.1.272+▝▜██████▀ recov@recov-model with xhigh effort · API Usage Billing+ ▝▝ ▝▝ /…/tmp/claude-501/-Users-jack-mag-claudish/5ea44449-884c-45a6-99c5-67b0ee7d3998/scratchpad/postclose/work+++❯ 0;38;5;16;48;5;255mReply with exactly one word: banana++⏺ banana++✻ Crunched for 1m 3s · done 11:19 am+++++++++++──⏵⏵ bypass permissions on (shift+tab to cycle) · ← 2 agents Recov • ~$0.028 • 28k tokens───────────────────────────────+diff --git a/ai-docs/reports/network-recovery-pane-close-repro/screen-while-open.txt b/ai-docs/reports/network-recovery-pane-close-repro/screen-while-open.txtnew file mode 100644index 00000000..03836447--- /dev/null+++ b/ai-docs/reports/network-recovery-pane-close-repro/screen-while-open.txt@@ -0,0 +1,30 @@++ ▐▛███▛█ Claude Code v2.1.272+▝▜██████▀ recov@recov-model with xhigh effort · API Usage Billing+ ▝▝ ▝▝ /…/tmp/claude-501/-Users-jack-mag-claudish/5ea44449-884c-45a6-99c5-67b0ee7d3998/scratchpad/postclose/work+++❯ Reply with exactly one word: banana+++++++++✶ Effecting… (48s)+ 0 tokens+────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────+❯+────────���─────────────────────────────────────────────────────────────────────────────────────────────────────────────+ * recov@recov-model | $0.00 | 0s | 280M | ░░░░░░ 0% • $0.000 • N/A+ ⏵⏵ bypass permissions on (shift+tab to cycle) · ← 2 agents+��──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────+ ██ NETWORK · Recov refused+ Cannot connect to Recov at http://127.0.0.1:49208/v1/chat/completions. Make sure the server is running.+ host 127.0.0.1:49208 · ConnectionRefused · local+ connecting to 127.0.0.1:49208… · attempt 7 · 46s in recovery+ last: ok · 1 request held+ click here or Ctrl-G Tab, then [r] try now · [q] give up+diff --git a/ai-docs/reports/network-recovery-pane-close-wedges-host-tui-20260915.md b/ai-docs/reports/network-recovery-pane-close-wedges-host-tui-20260915.mdnew file mode 100644index 00000000..0baa640d--- /dev/null+++ b/ai-docs/reports/network-recovery-pane-close-wedges-host-tui-20260915.md@@ -0,0 +1,202 @@+# Closing the recovery pane wedges Claude Code's renderer++**Found**: 2026-09-15, by the user, looking at a real session after the live demo.+**Status**: OPEN. Blocks the UI half of the network-recovery feature.+**Branch**: `worktree-recover` at `8aaa270`.++---++## 1. The symptom++After a recovery episode ends and the pane closes itself, the host session is left with:++- no visible input box,+- the status line stranded part-way up the screen,+- every row below it dead,+- six rows of bottom chrome collapsed onto one line.++Typing still registers, but the characters are painted **on top of** the status line, so the+session is usable only blind.++---++## 2. Measured, in one 190x64 pane, 27 seconds apart++`tmux capture-pane -p` with row numbers, same pane, before and after the pane closed itself.++**Before (01:23:44) — correct:**++```+27 27650 tokens+28 ──────────────────────────────────────────────────────────────────+29 ❯+30 ──────────────────────────────────────────────────────────────────+31 * recov@recov-model | $0.14 | 2m2s | 400M | ░░░░░░ 14% • Recov • ~$0.028 • 27k tokens+32 ⏵⏵ bypass permissions on (shift+tab to cycle) · ← 2 agents+33 ──────────────────────────────────────────────────────────────────+34 ██ NETWORK · Recov recovered+35 9 attempts over 2m 11s+36 this pane closes on its own+```++**After (01:24:11) — wedged:**++```+32 ──⏵⏵ bypass permissions on (shift+tab to cycle) · ← 2 agents Recov • ~$0.028 • 27k tokens────+```++Rows 24-31 blank. Rows 33-64 blank. The composer, both separator rules and the model status+line are gone; what is left is one line carrying fragments of three of them.++---++## 3. It is NOT a missing resize++Measured immediately after the close:++```+Claude Code pty (ttys020): 64 190+tmux pane %347: 190x64+```++magmux handed pane 0 the entire terminal and resized its PTY, which delivers SIGWINCH. Claude+Code has all 64 rows and paints its chrome at row 32 anyway.++---++## 4. It is NOT an artifact of a nested multiplexer++Reproduced on a bare PTY with no outer tmux — a user's own terminal — via+`post-close-render.ts` (§8), which drives the real branch build behind+`phase3/pty-host.py` and models the screen with `phase3/vt.ts`:++```+rows : 44+last painted row : 21+blank rows below it : 22+composer (input box) up? : false+RESULT: BROKEN — chrome stranded / no input box after the pane closed+```++Final screen, same merged line as the user's own screenshot:++```+──⏵⏵ bypass permissions on (shift+tab to cycle) · ← 2 agents Recov • ~$0.028 • 28k tokens──────+```++---++## 5. It cannot be repaired from outside++Each tried against the wedged session, each measured:++| Attempt | Result |+|---|---|+| `Escape` | no change |+| a printable keystroke | registers, but paints **over** the status line |+| `Ctrl-L` | clears the transcript, chrome stays stranded at the same row |+| `kill -WINCH` at the same size | no change (dimensions unchanged, so it is a no-op) |+| a real shrink-then-grow resize cycle | merged line moves one row; composer does **not** come back |++Once wedged, the session stays wedged until it is restarted.++---++## 6. Where it comes from++`recovery/magmux-ui.ts:428`:++```ts+async function closePane(): Promise<void> {+ if (state.control && state.paneIndex !== null) {+ await request(state.control, { type: "close_pane", pane: state.paneIndex, force: true }, 1_000);+ }+ await teardown();+}+```++`close_pane`, then claudish tears down its own socket state. Nothing else. It trusts magmux to+give the rows back — which magmux does, correctly (§3) — and trusts the host to repaint.++**Inference, not measurement:** the defect is in Claude Code's renderer handling a *grow*.+On shrink (the pane opening) it re-lays out correctly — every capture in §2 "before" and every+Phase-7 capture proves that. On grow it keeps the old anchor. claudish does not cause it, but+claudish is what triggers it, twice per outage, and claudish is what has to work around it.++---++## 7. Why eight phases of validation missed it++Every Phase-7 capture was taken while the pane was still **open**. `validation/c17/C-17-final.txt`+— the file named "final" — still contains:++```+ ██ NETWORK · Ollama recovered+ 8 attempts over 1m 59s+ this pane closes on its own+```++The pane had not closed yet. C-1 checked continuously that `API Error: 400` never appeared, C-6+that the turn completed, C-3/C-4/C-5 that the banner painted — and all of them are satisfied by a+screen captured before `PANE_LINGER_MS` (30 s) expired. **No criterion looked at the screen after+the pane closed**, so the last state the user is actually left in was never observed.++This is the same shape as the Phase-6 finding that black-box tests caught what 3396+implementation-side tests missed: the tests all stopped at the moment the feature declared+success.++---++## 8. Repro++`post-close-render.ts`, kept alongside this report. Bare PTY, no outer multiplexer, real branch+build, real ollama answer, fault is F-REFUSED on a verified-free port. It captures the screen+while the pane is open, then again past the 30 s linger, and prints a verdict.++```+bun post-close-render.ts+```++---++## 9. The fix: magmux already has all of this, and we did not use it++The pane was never needed. magmux ships three primitives for exactly this display role, and+**none of them changes the layout**, so the trigger in §6 cannot occur:++| Need | magmux verb | Source |+|---|---|---|+| Banner box with reason, styled red | `{"type":"overlay","pane":0,"text":"…","style":"error"}` — centred box, border, drop shadow, `\n` for multi-line | `main.go:5736`, `main.go:1578`, `main.go:2395` |+| Live countdown / attempt counters | `{"type":"status","text":"…"}` — arbitrary status-bar text, and it force-redraws every pane | `main.go:5697` |+| Colour the session during an outage | `{"type":"tint","pane":"*","color":"red"}`, `"reset"` on recovery | `main.go:5709` |+| Dismiss | set the overlay text to `""` | `main.go:1867` |++Cost: the status bar is **1 row**, decided once by `statusRowsLocked` (`main.go:3145`); the overlay+costs **zero** rows — it is drawn over the pane. Claudish currently passes `--no-status`+(`launcher/magmux-wrapper.ts:276`), which switches the status bar off. That flag is the only one in+that argument list with no comment explaining it.++What claudish built instead: a second pane, an NDJSON socket server and client, a wire protocol, a+renderer process (`recovery/pane-app.ts`), and a lease/heartbeat scheme — reached through+`open_pane`/`close_pane`, which is what reflows the layout and wedges the host.++**Is it a magmux bug?** Examined and: no, not for this. `sockClosePane` (`sockrpc.go:579`) resizes+correctly — §3 measures the survivor's PTY as exactly the full terminal — and magmux cannot repaint+a child's content for it; only Claude Code can. magmux's own chrome toggles are safe, measured:+showing and hiding the control panel on a healthy session left the composer and both status lines+intact (`126 → 63 → 126` cols). The defect is Claude Code's repaint on a height grow, and the+remedy available to us is to stop causing a reflow at all.++Superseded: an earlier draft of this section proposed reserving rows up front or never closing the+pane. Both are workarounds for a pane that should not exist.++---++## 10. Impact++The retry engine is untouched — the turn still recovers, and §2's "before" capture shows a real+answer delivered. What is damaged is the session the user is handed back afterwards: on every+successful recovery with the pane enabled, they lose their input box and have to restart.++For a feature whose purpose is "do not make the user restart after a network error", that is a+blocker, not a cosmetic issue.