From a24c91de0d60dc36abc0853e5996a13ba1cd7f24 Mon Sep 17 00:00:00 2001 From: Lesley Murfin Date: Mon, 22 Jun 2026 01:00:44 -0600 Subject: [PATCH] fix(terminal): don't apply native-Windows ConPTY cursor stripping to remote serve PTYs Closes #6008 --- .../terminal-pane/pty-connection.ts | 18 ++++- .../windows-pty-compatibility.test.ts | 74 +++++++++++++++++++ .../pane-manager/windows-pty-compatibility.ts | 19 +++++ 3 files changed, 107 insertions(+), 4 deletions(-) diff --git a/src/renderer/src/components/terminal-pane/pty-connection.ts b/src/renderer/src/components/terminal-pane/pty-connection.ts index 782b46870..70d9edcc3 100644 --- a/src/renderer/src/components/terminal-pane/pty-connection.ts +++ b/src/renderer/src/components/terminal-pane/pty-connection.ts @@ -57,7 +57,7 @@ import { writeTerminalOutput } from '@/lib/pane-manager/pane-terminal-output-scheduler' import { recordAgentHibernationPaneOutput } from '@/lib/agent-hibernation-output-activity' -import { isLocalNativeWindowsPty } from '@/lib/pane-manager/windows-pty-compatibility' +import { isLocalNativeWindowsConpty } from '@/lib/pane-manager/windows-pty-compatibility' import { recordTerminalOutput, restoreScrollStateAfterLayout } from '@/lib/pane-manager/pane-scroll' import type { ScrollState } from '@/lib/pane-manager/pane-manager-types' import { createBrowserUuid } from '@/lib/browser-uuid' @@ -98,7 +98,10 @@ import { cancelScheduledHiddenOutputRestore, scheduleHiddenOutputRestore } from './hidden-output-restore-scheduler' -import { getRuntimeEnvironmentIdForWorktree } from '@/lib/worktree-runtime-owner' +import { + getExecutionHostIdForWorktree, + getRuntimeEnvironmentIdForWorktree +} from '@/lib/worktree-runtime-owner' import { CLIENT_PLATFORM } from '@/lib/new-workspace' import { buildAgentResumeStartupPlan } from '@/lib/tui-agent-startup' import { resolveAgentStatusTerminalTitle } from '@/lib/agent-status-terminal-title' @@ -1736,11 +1739,18 @@ export function connectPanePty( const connectionId = getConnectionId(deps.worktreeId) ?? null const tab = (state.tabsByWorktree[deps.worktreeId] ?? []).find((t) => t.id === deps.tabId) const shellOverride = tab?.shellOverride - const isNativeWindowsConpty = isLocalNativeWindowsPty({ + // Why: a serve/remote-runtime pane has no SSH connectionId and a Linux cwd, so + // the native-Windows ConPTY heuristic misfires on a Windows client and wrongly + // enables ConPTY synchronized-output protection, which strips an agent's + // transient cursor-show (?25h) and leaves the cursor invisible. The execution + // host is the authoritative signal: only a 'local' host is a local native PTY. + const executionHostId = getExecutionHostIdForWorktree(state, deps.worktreeId) + const isNativeWindowsConpty = isLocalNativeWindowsConpty({ userAgent: navigator.userAgent, connectionId, cwd: deps.cwd, - shellOverride + shellOverride, + executionHostId }) const shouldApplyNativeWindowsRewriteRefresh = isNativeWindowsConpty const shouldProtectNativeWindowsSynchronizedOutput = isNativeWindowsConpty diff --git a/src/renderer/src/lib/pane-manager/windows-pty-compatibility.test.ts b/src/renderer/src/lib/pane-manager/windows-pty-compatibility.test.ts index 74eda75c8..b6789ba99 100644 --- a/src/renderer/src/lib/pane-manager/windows-pty-compatibility.test.ts +++ b/src/renderer/src/lib/pane-manager/windows-pty-compatibility.test.ts @@ -1,6 +1,7 @@ import { describe, expect, it } from 'vitest' import { buildWindowsPtyCompatibilityOptions, + isLocalNativeWindowsConpty, isLocalNativeWindowsPty } from './windows-pty-compatibility' @@ -107,3 +108,76 @@ describe('buildWindowsPtyCompatibilityOptions', () => { ).toBe(false) }) }) + +describe('isLocalNativeWindowsConpty', () => { + // A genuine local native Windows ConPTY (Windows UA, no SSH connectionId, + // Windows cwd) on a 'local' execution host must keep the ConPTY workarounds. + const localNativeWindowsContext = { + userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)', + connectionId: null, + cwd: 'C:\\repo', + shellOverride: 'powershell.exe' + } as const + const remoteServePaneOnWindowsClientContext = { + userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)', + connectionId: null, + cwd: '/home/me/repo', + shellOverride: null + } as const + + it('treats a local-execution-host Windows pane as a native ConPTY', () => { + expect( + isLocalNativeWindowsConpty({ ...localNativeWindowsContext, executionHostId: 'local' }) + ).toBe(true) + }) + + it('does NOT treat a remote-runtime (serve) pane as a native ConPTY even when the raw Windows heuristic matches', () => { + // Regression: a serve-hosted pane on a Windows client has no SSH connectionId + // and a Linux cwd, so isLocalNativeWindowsPty returns true. Without the + // execution-host gate, ConPTY transient cursor-show (?25h) stripping is + // wrongly applied and the agent cursor disappears. + expect(isLocalNativeWindowsPty(remoteServePaneOnWindowsClientContext)).toBe(true) + expect( + isLocalNativeWindowsConpty({ + ...remoteServePaneOnWindowsClientContext, + executionHostId: 'runtime:my-serve' + }) + ).toBe(false) + }) + + it('does NOT treat an SSH-runtime pane as a native ConPTY', () => { + expect( + isLocalNativeWindowsConpty({ + ...localNativeWindowsContext, + executionHostId: 'ssh:my-host' + }) + ).toBe(false) + }) + + it('stays false on a local host when the pane is not a native Windows PTY', () => { + // Non-Windows client: the raw heuristic is false, so the gate result is false + // regardless of the local execution host. + expect( + isLocalNativeWindowsConpty({ + userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 14_0)', + connectionId: null, + cwd: '/repo', + shellOverride: null, + executionHostId: 'local' + }) + ).toBe(false) + }) + + it('does not let a local execution host re-enable protection the raw heuristic already suppressed', () => { + // Guards the AND: even on a 'local' host, a Windows pane excluded for a + // non-execution-host reason (here an SSH connectionId) must stay false, so a + // future refactor cannot make the local host bypass the raw checks. + expect( + isLocalNativeWindowsConpty({ + ...localNativeWindowsContext, + connectionId: 'ssh-1', + executionHostId: 'local' + }) + ).toBe(false) + }) +}) diff --git a/src/renderer/src/lib/pane-manager/windows-pty-compatibility.ts b/src/renderer/src/lib/pane-manager/windows-pty-compatibility.ts index 399b60ba4..62f8362d1 100644 --- a/src/renderer/src/lib/pane-manager/windows-pty-compatibility.ts +++ b/src/renderer/src/lib/pane-manager/windows-pty-compatibility.ts @@ -1,5 +1,6 @@ import type { ITerminalOptions } from '@xterm/xterm' import { isWslUncPath } from '../../../../shared/wsl-paths' +import { LOCAL_EXECUTION_HOST_ID, type ExecutionHostId } from '../../../../shared/execution-host' export type WindowsPtyCompatibilityContext = { userAgent?: string @@ -57,3 +58,21 @@ export function isLocalNativeWindowsPty(context: WindowsPtyCompatibilityContext) } return true } + +/** + * Whether a pane is a genuine local native Windows ConPTY that needs the ConPTY + * cursor/synchronized-output workarounds. + * + * Why this is gated on the execution host: a serve/remote-runtime pane on a + * Windows client has no SSH `connectionId` and a Linux `cwd`, so + * `isLocalNativeWindowsPty` misfires and classifies it as local. The execution + * host is the authoritative signal: only a `'local'` host is a real local + * native PTY. Remote panes resolve to `runtime:` (or `ssh:`) and + * must be excluded, otherwise ConPTY transient cursor-show (`?25h`) stripping is + * wrongly applied to them and a repainting agent's cursor disappears. + */ +export function isLocalNativeWindowsConpty( + context: WindowsPtyCompatibilityContext & { executionHostId: ExecutionHostId } +): boolean { + return context.executionHostId === LOCAL_EXECUTION_HOST_ID && isLocalNativeWindowsPty(context) +}