fix(pty): contain node-pty's deferred Windows resize after pty exit
node-pty's WindowsTerminal queues resize calls that arrive before the ConPTY control socket's first data flush (_deferNoArgs). If the pty exits before the flush, the deferred resize throws 'Cannot resize a pty that has already exited' inside the socket's 'data' handler — uncatchable by any caller and fatal to the host process. The Windows CI lane caught exactly this as an unhandled error while all 1233 tests passed. Park pre-first-output resizes in our own gate (armed at every spawn site) and replay them via setImmediate once output has flushed the deferred list — by then node-pty executes resizes synchronously, so the exited throw lands in tryResizePty's catch instead of the host. POSIX terminals resize synchronously (no deferral), so the gate is armed on Windows only and the other platforms keep their exact behavior. Also route AgentPtyRegistry.resize through tryResizePty: it previously called pty.resize bare, missing the just-exited throw guard the tool and attach-socket paths already had.
This commit is contained in:
1 parent
24db20a796
commit
6d877471d4
2 files changed
+62
-3
No files matched your search
+4
-1
@@ -42,7 +42,7 @@ import { launchExternal } from './open-external.ts'
|
||||
import * as git from './git.ts'
|
||||
import { SettingsConflictError } from '@deepseek-ai/dsh-settings'
|
||||
import { defaultShell, ensureSpawnHelper, PtyManager, shellDisplayName } from './pty-manager.ts'
|
||||
import { AgentPtyRegistry, tryResizePty, type AgentTerminalHandle } from './agent-pty.ts'
|
||||
import { AgentPtyRegistry, armPtyResizeGate, tryResizePty, type AgentTerminalHandle } from './agent-pty.ts'
|
||||
import {
|
||||
DSH_NODE_PTY_RANGE,
|
||||
depsStatus,
|
||||
@@ -1209,6 +1209,9 @@ async function attachTerminal(
|
||||
// terminals opened from now on (existing pty handles keep their shell).
|
||||
const overrides = shellOverridesOf(getSettings)
|
||||
const handle = ptyManager.open(sessionId, tabId, cwd, 80, 24, overrides.shell, overrides.shellArgs)
|
||||
// Windows pre-ready gate for the resize frames this socket may deliver
|
||||
// (see armPtyResizeGate; inert on POSIX).
|
||||
armPtyResizeGate(handle.pty)
|
||||
// Replay the transcript, then follow live output.
|
||||
if (handle.transcript !== '') ws.send(handle.transcript)
|
||||
const onData = (data: string): void => {
|
||||
|
||||
Reference in new issue
Block a user