Skip to content

fix(windows): respawn a ConPTY pane that started without keyboard input - #33423

Merged
nwparker merged 6 commits into
mainfrom
nwparker/conpty-input-readiness
Oct 25, 2026
Merged

nwparker merged 6 commits into
mainfrom
nwparker/conpty-input-readiness

Conversation

@nwparker

@nwparker nwparker commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Very rarely, on Windows, a brand-new terminal comes up looking normal: it shows its banner and prompt. But it ignores everything you type, and the command Orca types to launch an agent never runs. This happens because Windows' console host sometimes starts without the part that reads keyboard input. Orca can now tell when that has happened, before anything has been typed into the pane, and quietly starts the terminal again.

What Changed

  • Before: about 1 in a few thousand new Windows panes, under heavy load, never read any input. The prompt showed, but the agent launch command and all typing were silently dropped, and stayed dropped (shown below).
  • After: the daemon spots such a pane from its first output and replaces it with a fresh one, once. Nothing has been written to the pane at that point. If the replacement is broken too, the pane prints a red "Windows could not start keyboard input for this terminal. Close it and open a new one." instead of silently ignoring keystrokes.

Mechanism, at the one daemon choke point (spawnNativeDaemonPty), Windows only:

  • How a healthy pane is recognized. Bundled ConPTY writes a DA1 query (ESC [ c) right after it starts reading input, and before it relays any shell output. conpty-startup-input-reader.ts buffers a fresh pane's output until the first bytes decide the question. A pane is judged dead only on positive evidence: shell output that arrives with no announcement.
  • The wait. It is capped at 5s, after which the pane is accepted unverified. The verdict normally lands with the pane's first output, the same moment node-pty already waited for before it flushed any write.
  • When there is no respawn. The pane is kept, with the notice, when the shell's argv may itself run a command: an argv startup command, or any user-configured terminalShellArgs such as pwsh -Command or cmd /c. Respawning those could run the command twice.
  • Throwing a broken pane away. The discarded pane is killed through its job, and then through node-pty's agent kill. node-pty's own kill() waits for output that such a pane may never send, so going through the agent avoids leaking the console host, input pipe or output worker.
  • Replay. Buffered output, and an exit that lands during the wait, are replayed into the subprocess handle, so no startup byte or exit is lost.
  • Cancels. A cancel during the wait reports as an attach cancel and kills the pane.
  • Fail-safe. If two panes in a row lack the announcement and no pane has ever shown it, the check turns itself off for the daemon's lifetime. A future ConPTY build that changes its startup sequence therefore costs at most one extra spawn, not a respawn of every pane. A new real-Windows test also asserts that a fresh pane announces, so a ConPTY bump that changes this fails CI.
  • The table stress probe. It now waits for node-pty's own readiness, its first output, rather than typed input, so the probe no longer depends on this ConPTY fault.

Host-side only: there is no wire change, so mixed client and daemon versions are unaffected. This covers local Windows panes, WSL panes (wsl.exe runs inside the same bundled ConPTY), and Windows SSH hosts, whose orcad runs the same daemon spawn path. macOS and Linux run exactly as before.

Why

Evidence, gathered on windows-2022 CI:

  • Real loss, not delay. The failing CI job (package (windows), job 121033873082) had two "prompt shown, input ignored" panes, both missing ConPTY's usual startup sequence. In repeated runs of the Windows boundary step, 2 of about 128 runs reproduced it. When the bad pane was waited on for another 45s and sent a second command, neither command ever ran.
  • ETW confirmed the mechanism. A trace of the console-host provider showed that the bad pane's OpenConsole never wrote the DA1 query, never performed a single input read, and skipped its usual 3s DA1 wait. The other 94 panes in that trace all announced.
  • Not a load or desktop-heap effect. It did not reproduce with CPU burners (1,440 panes), with the stress test run alone (2,880 panes), or with the desktop heap deliberately exhausted. Exhausting the heap only drops the window-visibility report, while input keeps working.
  • Not DA1 answering. An unanswered DA1 costs a fixed 3s delay; answering it cut that to under 0.2s. In either case input is still delivered, so DA1 answering does not cause the loss.

Alternatives considered:

  • Answering DA1 from one place, or gating writes on a reply. This fixes the 3s delay, not this loss, because the broken console host never asks.
  • Marking the pane input-closed. There is no user-visible UI for that, so the agent would still silently never start.
  • Swapping the native pty after the spawn reply. That breaks pid and job identity that is already published to clients.

Deciding before the spawn returns is the only point where nothing can have been typed yet, so a respawn can never repeat a launch.

Linked Issue

Linear STA-11968 (Windows boundary step flakes). Found from CI evidence, not a user report.

Visual Proof

N/A. There is no UI change in the normal case. The only new visible text is the rare red notice in a pane that failed twice.

Testing

  • Unit tests, with fake ConPTY panes in native-pty-spawn-windows.test.ts:

    • a dead pane is respawned once, with its job and agent killed;
    • a second failure prints the notice;
    • a pane whose argv may carry a command is never respawned;
    • the check disables itself when no pane ever announces;
    • a pane that exits before deciding is not respawned;
    • a silent pane is accepted after 5s;
    • a cancel during the wait kills the pane.

    The first case fails on main.

  • Through createPtySubprocess:

    • output and exit landing during the wait are delivered;
    • user terminalShellArgs (cmd /c deploy.cmd) with a dead pane are not respawned.
  • Real Windows tests, in windows-pty-job.win32.test.ts:

    • a fresh bundled-ConPTY pane announces its input reader;
    • a pane killed before its first output dies.
  • Every test file that imports a changed module passes locally: the pty-subprocess suites and the Windows pty job tests. repro-13767 is an exception: it also fails on main on this macOS machine. The full static job also passes locally, with one exception: the process-host smoke needs Node 18, which this machine lacks, so CI covers it. The orcad terminal smoke passes.

  • CI census on the fix: 16 Windows jobs × 4 boundary-suite iterations, against the PR's code. Each iteration also ran 300 launch commands through spawnNativeDaemonPty under the suite's load, with respawn enabled.

    • Result: 19,200 launches, 0 lost and 0 run twice (counted by echoed output lines). The Git Bash, table-stress and new real-ConPTY tests passed in all 64 iterations.
    • Earlier run, with respawn disabled: in an otherwise identical 64-iteration census (18,300 launches), 3 dead panes were detected by the check, and 4 launches were lost overall. All 4 losses fell in a single job, where an unrelated raw-node-pty test also hit a dead pane. Two of those 4 panes were not flagged; I could not tell from the logs whether they hit the 5s cap or a different fault. That is unverified.
    • Latency: the gated spawn resolved at a median of 95–190ms per iteration (p99 under about 440ms). Raw node-pty time to first output in the same runs was 150–310ms median. The gate adds no measurable delay, because it resolves on the same first chunk node-pty already waits for before flushing writes.
    • Limit: the dead-pane case is too rare to hit 100 times on demand (about 1 in 6,000 panes here). The respawn itself is covered by unit tests, plus the trace evidence that identifies the pane.
  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Review

  • Independent review found no P0–P2 issues.
  • Codex findings fixed:
    • deferred kill on silent panes;
    • master retirement during the wait.
  • Left open:
    • ClosePseudoConsole blocking: it can block on the JS thread like upstream kill(), but only for a pane with output that nobody drained, which a silent pane does not have.
    • Garbled notice: the notice can land after a partial escape sequence, which is cosmetic.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Windows only. Other platforms take the unchanged path.
  • Folder workspaces and git worktrees are unaffected, because this is spawn-level.
  • Mobile: no change. The daemon behaviour is shared by every client.
  • Not covered: the degraded local (non-daemon) provider spawns ConPTY synchronously and is not covered; that is a follow-up if wanted.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 3 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f3d73b94-c016-46cc-95d3-10cf56e529a6
Commits

Reviewing files that changed from the base of the PR and between f66c4c0 and ec7896c.

Files selected for processing: 15
  • config/scripts/windows-pty-table-stress.cjs
  • src/main/daemon/pty-subprocess-foreground-degraded-scan.test.ts
  • src/main/daemon/pty-subprocess-foreground-scan-cadence.test.ts
  • src/main/daemon/pty-subprocess-handle-lifecycle.test.ts
  • src/main/daemon/pty-subprocess-test-harness.ts
  • src/main/daemon/pty-subprocess-windows-shell-launch.test.ts
  • src/main/daemon/pty-subprocess.ts
  • src/main/daemon/pty-subprocess/conpty-startup-input-reader.ts
  • src/main/daemon/pty-subprocess/native-pty-spawn-windows.test.ts
  • src/main/daemon/pty-subprocess/native-pty-spawn.ts
  • src/main/daemon/pty-subprocess/subprocess-handle.ts
  • src/main/providers/agent-foreground-process-git-bash.win32.test.ts
  • src/main/windows/windows-pty-job.ts
  • src/main/windows/windows-pty-job.win32.test.ts
  • tests/e2e/terminal-foreground-confirmation.unit.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Bundled ConPTY occasionally starts a pane whose console host never reads
its input pipe: the shell prints its banner and prompt, but every keystroke
and the typed launch command are dropped. Such a pane is identifiable from
its first output, because a healthy one always queries DA1 before relaying
anything else. The daemon now waits for that first output, respawns once
when it is missing, and replays the buffered startup output so no byte is
lost. The table stress probe now waits for node-pty's own readiness rather
than typed input.
- Respawn only when no command rode in the shell's argv; otherwise keep the
  pane and say on screen that it cannot take input.
- Accept the pane unverified after 5s of silence instead of stalling the spawn.
- Distrust the check after two misses with no pane ever announcing, so a
  changed ConPTY build cannot respawn every pane.
- Kill a discarded pane through its job before closing the pseudoconsole.
- Report a cancel during the wait as an attach cancel, not a spawn failure.
- Assert on real Windows ConPTY that a fresh pane announces its input reader.
… pane now

- Treat user shell args like an argv startup command: never respawn, show
  the notice instead, so a command such as pwsh -Command never runs twice.
- Close a discarded pane's pseudoconsole directly; node-pty defers kill()
  until first output, which a silent pane never produces. Kill the shell by
  pid when no job owns it.
- Reconcile a master node-pty retired during the startup wait.
- Drop the test-only respawn counter; the count rides in the daemon log.
…gent

node-pty defers kill() until first output, so closing only the native
pseudoconsole left the input pipe and output worker of a silent discarded
pane alive until daemon exit. The agent's kill closes all three.
…ock prelude

A pid-addressed kill could hit a recycled pid when the shell exited during
startup; the job and the agent's native kill both act on handles. Lifecycle
assertions now expect the replayed DA1 query when the suite runs on Windows.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant