Skip to content

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

fix(mcp): clamp resize_session width to 250 columns, not 500

Jack Rudenkof67bd3aaa646
diff --git a/ai-docs/architecture/mcp-sessions.md b/ai-docs/architecture/mcp-sessions.md
index 0469972b..1e44ed61 100644
--- a/ai-docs/architecture/mcp-sessions.md
+++ b/ai-docs/architecture/mcp-sessions.md
@@ -330,7 +330,7 @@ what a caller cannot see from the model id.
answers the session's current screen `{seq, cols, rows, cursor, lines, final, spans?}` (160×50 at
launch), or `{unchanged:true, seq, final}` when `since_seq` is still current — a memory read, meant
for polling at about 1 Hz. `resize_session` answers `{session_id, cols, rows, changed, seq,
-pending?}`: the size actually set after clamping to 80–500 × 24–200, and the screen `seq` once the
+pending?}`: the size actually set after clamping to 80–250 × 24–200, and the screen `seq` once the
redraw at that size has landed, so a capture with that `since_seq` already sees it. Their errors
are a JSON `ContractError`; `resize` is the only verb that emits the two codes it added,
`resize_unsupported` (the magmux has no `resize` op) and `delivery_unavailable` (magmux refused, or
diff --git a/ai-docs/architecture/pane-session.md b/ai-docs/architecture/pane-session.md
index ffe53ff3..0d0ce372 100644
--- a/ai-docs/architecture/pane-session.md
+++ b/ai-docs/architecture/pane-session.md
@@ -482,10 +482,12 @@ inline 400 and the slot is FAILED `api_error`.
**The size is the viewer's, not ours.** Every pane used to be born 160×50 and stay there, so a
docked viewer either showed empty rows below the screen or cut every line. 160×50 is now only the
launch default (`pane/pane-size.ts`); `resize_session` and `team(mode:"resize")` set it at any time,
-mid-turn included, clamped to cols 80–500 × rows 24–200. The floor is not arbitrary: at 80 columns
+mid-turn included, clamped to cols 80–250 × rows 24–200. The floor is not arbitrary: at 80 columns
every closed-list dialog marker still fits one row's width, and 24 rows still hold a full permission
or trust dialog, so boot and blocked-screen detection keep working. magmux's own limits (≥ 20 × 3,
-≤ 10000 per side) are wider, so a clamped size can never earn its `too_small`/`too_large`.
+≤ 10000 per side) are wider, so a clamped size can never earn its `too_small`/`too_large`. The
+column cap is where the real classifier fixtures stop: above 250 columns `isBoxRule`'s cols − 1
+rule is unverified, and a box it misses is a screen that never classifies.
**A resize is a real one.** claudish sends magmux's `resize` op (`{type:"resize", pane:0, cols,
rows}` → `{rows, cols, changed, manual}`); magmux sets the PTY winsize, the child gets a genuine
@@ -502,8 +504,12 @@ produces a few requests, not one per intermediate size. The same-size short-circ
no request) applies only when `appliedSize` is known, equal and nothing is in flight; otherwise
magmux's `changed` decides. While the client is disconnected, or the pane is still starting, the
size is stored and the call answers `changed:true, pending:true`; `attach()` re-applies it after
-`capabilities`, and a starting pane launches at it. After every await the phase is re-checked: a
-session that went terminal answers its final capture's size with `changed:false`.
+`capabilities`, and a starting pane launches at it. A size stored while the drain loop sits in its
+post-reply screen wait has no waiter, and the redial's kick finds the loop running, so the loop also
+runs while a size is OWED: connected, not terminal, applied ≠ desired, and desired ≠ the last size
+it sent on this connection. The last clause is what stops a refused size being resent forever; a
+redial resets it, so each connection retries a stored size once. After every await the phase is
+re-checked: a session that went terminal answers its final capture's size with `changed:false`.
**A capture after a resize sees the new size.** On `changed:true`, `resize()` waits up to 1000 ms
for the screen model to reach the set size and returns that screen's `seq`, so a caller passing it
@@ -515,8 +521,11 @@ against box text with row breaks removed, dialog markers match the dialog region
string, and the working row tolerates a wrapped tail. They are validated on real Claude Code screens
captured at 80, 120 and 250 columns. A resize redraw moves the above-box region, which only DELAYS
settle and boot (it restarts their quiet clocks) and never completes them. Two places would have
-read a redraw as evidence and therefore ignore it for `RESIZE_QUIET_MS` (2 s) after a resize:
-degraded admission (`maybeDegradedAccept` counts only the echo there, so an undelivered prompt
+read a redraw as evidence and therefore ignore it inside the quiet window, an interval
+[from, until) opened at the SEND (the SIGWINCH redraw can land before the reply) and extended to
+`RESIZE_QUIET_MS` (2 s) past a `changed:true` or lost (`client_lost`/`client_timeout`) reply. It
+is never retracted: a lost reply may follow an applied resize, and moving the start to the reply
+would push an earlier redraw out of it. Ignored there are degraded admission (`maybeDegradedAccept` counts only the echo there, so an undelivered prompt
still fails `prompt_not_accepted`), and the activity timestamp behind `idle_seconds` and
`last_activity_at` (a separate activity clock; `screen.changedAt` still moves).
diff --git a/docs/usage/magmux.md b/docs/usage/magmux.md
index 80a628c9..54e97262 100644
--- a/docs/usage/magmux.md
+++ b/docs/usage/magmux.md
@@ -81,7 +81,7 @@ has finished, and closes the pane when the slot or session ends.
A capture carries a `seq` that grows with every visible change; pass it back as `since_seq` and an
unchanged screen answers `{unchanged: true}`, so polling about once a second is cheap.
-A pane starts at 160×50. A viewer can resize it at any time (cols 80–500, rows 24–200, clamped);
+A pane starts at 160×50. A viewer can resize it at any time (cols 80–250, rows 24–200, clamped);
the next capture carries the new `cols`/`rows`. Resizing needs a magmux that ships the `resize`
verb (MIN_MAGMUX_VERSION); an older magmux answers `resize_unsupported` and the pane stays 160×50.
See [MCP server](mcp-server.md).
diff --git a/docs/usage/mcp-server.md b/docs/usage/mcp-server.md
index 9d8ddbaa..5a133964 100644
--- a/docs/usage/mcp-server.md
+++ b/docs/usage/mcp-server.md
@@ -447,7 +447,7 @@ scroll region, which garbled Claude Code's input box and stopped its turns from
**Parameters:**
- `session_id` (required) - Session ID from `create_session`
-- `cols` (required) - Columns, an integer; clamped to 80–500
+- `cols` (required) - Columns, an integer; clamped to 80–250
- `rows` (required) - Rows, an integer; clamped to 24–200
**Returns:** `{ session_id, cols, rows, changed, seq, pending? }`. `cols`/`rows` are the size actually
diff --git a/packages/cli/src/mcp-server.ts b/packages/cli/src/mcp-server.ts
index 3ddb8fd4..31e14758 100644
--- a/packages/cli/src/mcp-server.ts
+++ b/packages/cli/src/mcp-server.ts
@@ -1497,7 +1497,7 @@ function defineTools(sessionManager: SessionManager, nested: boolean): ToolDefin
cols: {
type: "integer",
description:
- "For 'resize' (required): the terminal width in columns, clamped to 80–500. The " +
+ "For 'resize' (required): the terminal width in columns, clamped to 80–250. The " +
"answer {run_id, path, slot, cols, rows, changed, seq} reports the size set.",
},
rows: {
@@ -2305,7 +2305,7 @@ function defineTools(sessionManager: SessionManager, nested: boolean): ToolDefin
description:
"Set a session's terminal size: the child gets a real SIGWINCH and Claude Code reflows. " +
"Allowed at any time, mid-turn included; the last call wins. The size is clamped to " +
- "cols 80–500, rows 24–200 and the answer {session_id, cols, rows, changed, seq, pending?} " +
+ "cols 80–250, rows 24–200 and the answer {session_id, cols, rows, changed, seq, pending?} " +
"reports the size set. `seq` is the screen's seq after the resize: the next capture_session " +
"shows the new cols/rows. `changed:false` = already that size. `pending:true` = the pane " +
"is starting or its socket is reconnecting; the size is applied then. A finished session " +
@@ -2315,7 +2315,7 @@ function defineTools(sessionManager: SessionManager, nested: boolean): ToolDefin
type: "object",
properties: {
session_id: { type: "string", description: "Session ID from create_session" },
- cols: { type: "integer", description: "Terminal width in columns (clamped to 80–500)" },
+ cols: { type: "integer", description: "Terminal width in columns (clamped to 80–250)" },
rows: { type: "integer", description: "Terminal height in rows (clamped to 24–200)" },
},
required: ["session_id", "cols", "rows"],
diff --git a/packages/cli/src/pane/contract.ts b/packages/cli/src/pane/contract.ts
index 9868bca6..f1baa1fc 100644
--- a/packages/cli/src/pane/contract.ts
+++ b/packages/cli/src/pane/contract.ts
@@ -262,7 +262,7 @@ export interface CaptureUnchanged {
}
/**
- * F — `resize_session`. `cols`/`rows` are the size SET (the request clamped to cols 80–500,
+ * F — `resize_session`. `cols`/`rows` are the size SET (the request clamped to cols 80–250,
* rows 24–200); `changed` = the pane's size moved; `seq` = the screen's seq after the
* resize (the first capture at the new size once `changed`). `pending: true` = the socket
* is reconnecting (or the pane is still starting): the size is stored and applied on the
diff --git a/packages/cli/src/pane/pane-size.test.ts b/packages/cli/src/pane/pane-size.test.ts
index e48f5f77..abf9f7ab 100644
--- a/packages/cli/src/pane/pane-size.test.ts
+++ b/packages/cli/src/pane/pane-size.test.ts
@@ -1,25 +1,36 @@
import { describe, expect, test } from "bun:test";
-import { clampPaneSize, samePaneSize } from "./pane-size.js";
+import { MAX_PANE_COLS, clampPaneSize, samePaneSize } from "./pane-size.js";
describe("clampPaneSize", () => {
test.each([
[80, 24, 80, 24],
[120, 40, 120, 40],
[250, 60, 250, 60],
- [500, 200, 500, 200],
+ [500, 200, 250, 200],
[1, 1, 80, 24],
- [501, 201, 500, 200],
+ [501, 201, 250, 200],
[79, 60, 80, 60],
- [501, 60, 500, 60],
+ [501, 60, 250, 60],
[250, 23, 250, 24],
[250, 201, 250, 200],
[79, 201, 80, 200],
- [501, 23, 500, 24],
+ [501, 23, 250, 24],
])("%i × %i clamps to %i × %i", (cols, rows, expectedCols, expectedRows) => {
expect(clampPaneSize(cols, rows)).toEqual({ cols: expectedCols, rows: expectedRows });
});
});
+describe("M3: classifier-verified width cap", () => {
+ test("clamps 1000 columns to 250 and preserves 250 columns", () => {
+ expect(clampPaneSize(250, 50).cols).toBe(250);
+ expect(clampPaneSize(1000, 50).cols).toBe(250);
+ });
+
+ test("MAX_PANE_COLS is 250", () => {
+ expect(MAX_PANE_COLS).toBe(250);
+ });
+});
+
describe("samePaneSize", () => {
test("equal dimensions match, each differing axis does not", () => {
const size = { cols: 120, rows: 40 };
diff --git a/packages/cli/src/pane/pane-size.ts b/packages/cli/src/pane/pane-size.ts
index f3df04d0..7ac0c0bb 100644
--- a/packages/cli/src/pane/pane-size.ts
+++ b/packages/cli/src/pane/pane-size.ts
@@ -10,20 +10,21 @@
* The bounds are tighter than magmux's on purpose (plan review H1, L4): at 80 columns every
* closed-list dialog marker the classifier matches still fits one row, and 24 rows hold a
* whole permission or trust dialog. A smaller screen would turn a dialog into "no input box,
- * no dialog" — an honest unknown that never settles.
+ * no dialog" — an honest unknown that never settles. The column cap is 250 because the
+ * real classifier fixtures stop there: above it, `isBoxRule`'s cols − 1 rule is unverified.
*/
export const DEFAULT_PANE_COLS = 160;
export const DEFAULT_PANE_ROWS = 50;
export const MIN_PANE_COLS = 80;
-export const MAX_PANE_COLS = 500;
+export const MAX_PANE_COLS = 250;
export const MIN_PANE_ROWS = 24;
export const MAX_PANE_ROWS = 200;
/**
- * After a resize the child redraws everything it shows (SIGWINCH reflow). For this long
- * that redraw is not evidence: degraded admission ignores a change above the box (H2), and
+ * After a resize the child redraws everything it shows (SIGWINCH reflow). From the send
+ * until this long after the reply (or the lost reply), that redraw is not evidence: degraded admission ignores a change above the box (H2), and
* the activity timestamp behind `idle_seconds` / `last_activity_at` skips its frames (M4).
*/
export const RESIZE_QUIET_MS = 2_000;