fix(terminal): create PTYs at the client viewport size, not 80x24 (#2023)

New terminals were always spawned by the daemon at the hardcoded 80x24
default and only resized once the client's first resize arrived. On a
slow first mount that leaves a window -- or a stuck state -- where a new
terminal renders far smaller than its pane (e.g. vim in a corner).

Seed the PTY with the client's measured viewport size at creation time
so it is born at the right size and the race window is gone.

- protocol: optional `size` on create_terminal_request. Old daemons
  ignore it and keep 80x24; old clients send nothing. Fully backward
  compatible, no capability gate.
- client: a small last-measured-size cache keyed by serverId+cwd (every
  terminal in a workspace shares the pane) with a most-recent fallback;
  written on fit, read at create.
- server: thread rows/cols through the controller, terminal manager, and
  the worker-thread boundary into the existing size-aware createTerminal.

Tests: cache logic, protocol back-compat parse, controller forwarding.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Christoph Leiter
2026-07-13 03:26:52 +08:00
committed by GitHub
co-authored by Claude Opus 4.8
parent ec93ca866e
commit 2658132384
11 changed files with 232 additions and 1 deletions
@@ -5,6 +5,7 @@ import type { WorkspaceDescriptor } from "@/stores/session-store";
import { useTranslation } from "react-i18next";
import { useReplicaQuery } from "@/data/query";
import { workspaceTerminalsPushRoute } from "@/data/push-router";
import { estimateTerminalViewportSize } from "@/terminal/runtime/terminal-size-cache";
import {
buildTerminalsQueryKey,
canCreateWorkspaceTerminal,
@@ -135,14 +136,20 @@ export function useWorkspaceTerminals(input: UseWorkspaceTerminalsInput) {
if (!client || !workspaceDirectory) {
throw new Error(t("workspace.terminal.hostDisconnected"));
}
// Seed the new PTY with the workspace's measured pane size so it isn't born at 80x24.
const estimatedSize =
estimateTerminalViewportSize({ serverId: normalizedServerId, cwd: workspaceDirectory }) ??
undefined;
const payload = _input?.profile
? await client.createTerminal(workspaceDirectory, _input.profile.name, undefined, {
command: _input.profile.command,
args: _input.profile.args,
workspaceId: normalizedWorkspaceId || undefined,
size: estimatedSize,
})
: await client.createTerminal(workspaceDirectory, undefined, undefined, {
workspaceId: normalizedWorkspaceId || undefined,
size: estimatedSize,
});
// The daemon reports a failed spawn (e.g. a profile command that isn't
// installed) via payload.error with a null terminal. Surface it instead