Repository navigation
fix(terminal): keep restored history when ConPTY repaints after a resize - #33577
Conversation
The Windows daemon's emulator grew rows the way a Unix terminal does, pulling scrollback back into the screen. ConPTY then repaints the grid it owns from the top and overwrote those rows, so a relaunched window's first fit lost about a screen of restored history and printed the new shell's prompt onto the restored prompt's row. Give ConPTY-backed daemon sessions (WSL shells included) xterm's windowsPty resize model, as the window already does for native Windows panes.
|
Warning Review limit reachedYou'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 52 seconds. View limit details
Walkthrough
Priority: Merge Risk:
|
There was a problem hiding this comment.
Actionable comments posted: 1

Review info
-
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:
d66e8f82-9716-41f0-a089-a4d828e40bc0
Files selected for processing: 7-
src/main/daemon/headless-emulator.tssrc/main/daemon/session-conpty-resize-history.test.tssrc/main/daemon/session-output-pipeline.tssrc/main/daemon/session-output-plane.tssrc/main/daemon/session.tssrc/renderer/src/lib/pane-manager/windows-pty-compatibility.tssrc/shared/xterm-conpty-options.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.
-
| opts.ownerBackend && opts.ownerBackend !== 'posix-pty' | ||
| ? buildXtermConptyOptions(parseWindowsBuildNumber(release())) |
There was a problem hiding this comment.
🔎 Supported by static analysis
-
Script executed:
#!/bin/bash # Inspect renderer option builders and their call sites for WSL panes. rg -n -C 5 'buildWindowsPtyCompatibilityOptions\s*\(|buildLocalConptyTerminalOptions\s*\(|windowsPty\s*:' src/renderer
Repository: stablyai/orca
Length of output: 19686
Script executed:
rg -n -C 3 -F -e "'windows-wsl'" -e 'ownerBackend' src/main || test "$?" -eq 1
Repository: stablyai/orca
Length of output: 10907
Web query:
xterm.js windowsPty option resize behavior row increase scrollback reflow conpty buildNumberResult:
<source_evidence> <source kind="open_page"> <title>xterm.js/typings/xterm.d.ts at master · xtermjs/xterm.js · GitHub</title> <location>https://github.com/xtermjs/xterm.js/blob/master/typings/xterm.d.ts</location> <excerpt>citeturn1view0 [wordlim: 200] Crawled: yesterday; Content type: text/html; Source: open({"ref_id":"turn0search0","lineno":null}); Total lines: 3925 L2280: * Whether the cursor blinks. The blinking will stop after 5 minutes of idle L2281: L2282: * time (refreshed by clicking, focusing or the cursor moving). The default L2283: L2284: * is false. L2285: L2286: */ L2287: L2288: cursorBlink?: boolean; L2289: L2290: /** L2291: L2292: * The interval in milliseconds for the blink attribute. This is the amount L2293: L2294: * of time text remains visible or hidden before toggling. Set to 0 to L2295: L2296: * disable blinking. The default is 0. L2297: L2298: */ L2299: L2300: blinkIntervalDuration?: number; L2301: L2302: /** L2303: L2304: * The style of the cursor when the terminal is focused. L2305: L2306: */ L2307: cursorStyle?: 'block' | 'underline' | 'bar'; L2308: L2309: /** L2310: L2311: * The width of the cursor in CSS pixels when `cursorStyle` is set to 'bar'. L2312: L2313: */ L2314: L2315: cursorWidth?: number; L2316: L2317: /** L2318: L2319: * The style of the cursor when the terminal is not focused. L2320: L2321: */ L2322: L2323: cursorInactiveStyle?: 'outline' | 'block' | 'bar' | 'underline' | 'none'; L2324: L2325: /** L2326: L2327: * Whether input should be disabled. L2328: L2329: */ L2330: L2331: disableStdin?: boolean; L2332: L2333: /** L2334: L2335: * A {@link Document} to use instead of the one that xterm.js was attached L2336: * to. The purpose of this is to improve support in multi-window L2337: L2338: * applications where HTML elements may be references across multiple L2339: L2340: * windows which can cause problems with `instanceof`. L2341: L2342: * L2343: L2344: * The type is `any` because using `Document` can cause TS to have L2345: L2346: * performance/compiler problems. L2347: L2348: */ L2349: L2350: documentOverride?: any | null; L2351: L2352: /** L2353: L2354: * Whether to draw bold text in bright colors. The default is true. L2355: L2356: */ L2357: L2358: drawBoldTextInBrightColors?: boolean; L2359: L2360: /** L2361: * The scroll speed multiplier used for fast scrolling when `Alt` is held. L2362: L2363: */ L2364: L2365: fastScrollSensitivity?: number; L2366: L2367: /** L2368: L2369: * The font size used to render text. L2370: L2371: */ L2372: L2373: fontSize?: number; L2374: L2375: /** L2376: L2377: * The font family used to render text. L2378: L2379: */ L2380: L2381: fontFamily?: string; L2382: L2383: /** L2384: L2385: * The font weight used to render non-bold text. L2386: L2387: */ L2388: L2389: fontWeight?: FontWeight; L2390: L2391: /** L2392: L2393: * The font weight used to render bold text. L2394: L2395: */ L2396: L2397: fontWeightBold?: FontWeight; L2398: L2399: /** L2400: L2401: * Whether to ignore the bracketed paste mode. When true, this will always L2402: * paste without the `\x1b[200~` and `\x1b[201~` sequences, even when the L2403: L2404: * shell enables bracketed mode. L2405: L2406: */ L2407: L2408: ignoreBracketedPasteMode?: boolean; L2409: L2410: /** L2411: L2412: * The spacing in whole pixels between characters. L2413: L2414: */ L2415: L2416: letterSpacing?: number; L2417: L2418: /** L2419: L2420: * The line height used to render text. L2421: L2422: */ L2423: L2424: lineHeight?: number; L2425: L2426: /** L2427: L2428: * The handler for OSC 8 hyperlinks. Links will use the `confirm` browser L2429: L2430: * API with a strongly worded warning if no link handler is set. L2431: L2432: * L2433: * When setting this, consider the security of users opening these links, L2434: L2435: * at a minimum there should be a tooltip or a prompt when hovering or L2436: L2437: * activating the link respectively. An example of what might be possible is L2438: L2439: * a terminal app writing link in the form `javascript:...` …[truncated]</excerpt> </source> <source kind="search"> <title>xterm.js/typings/xterm.d.ts at master · xtermjs/xterm.js · GitHub</title> <location>https://github.com/xtermjs/xterm.js/blob/master/typings/xterm.d.ts</location> <excerpt>citeturn0search0 [wordlim: 200] Crawled: 2 weeks ago; * Whether to reflow the line containing the cursor when the terminal is ... scrollback?: number; ... backend === 'conpty' && buildNumber >= 21376)` ... windowsPty?: IWindowsPty; ... * [0]: https://github.com/microsoft/terminal/blob/main/doc/specs/%234999%20-%20Improved%20keyboard%20handling%20in%20Conpty.md * in but generally rejected in modern terminals. */ quirks?: ITerminalQuirks; /** * Whether to reflow the line containing the cursor when the terminal is * resized. Defaults to false, because shells usually handle this * themselves. Note that this will not move the cursor position, only the * line contents. */ reflowCursorLine?: boolean; /** * Whether to rescale glyphs horizontally that are a single cell wide but * have glyphs that would overlap following cell(s). This typically happens * for ambiguous width characters (eg. the roman numeral characters U+2160+) * which aren't featured in monospace fonts. This is an important feature * for achieving GB18030 compliance. * * The following glyphs will never be rescaled: * * - Emoji glyphs * - Powerline glyphs * - Nerd font glyphs * * Note that this doesn't work with the DOM renderer. The default is false. */ rescaleOverlappingGlyphs?: boolean; /** * Whether to select the word under the cursor on right click, this is * standard behavior in a lot of macOS applications. */ rightClickSelectsWord?: boolean; /** * Whether screen reader support is enabled. When on this will expose * supporting elements in the DOM to support NVDA on Windows and VoiceOver * on macOS. */ screenReaderMode?: boolean; /** * The amount of scrollback in the terminal. Scrollback is the amount of * rows that are retained when lines are scrolled beyond the initial * viewport. Defaults to 1000. */ scrollback?: number; /** * If enabled the Erase in Display All (ED2) escape sequence will push * erased text to scrollback, instead of clearing only the viewport portion. * This emulates PuTTY's default clear screen behavior. */ scrollOnEraseInDisplay?: boolean; /** * Whether to scroll to the bottom whenever there is some user input. The * default is true. */ scrollOnUserInput?: boolean; /** * The scrolling speed multiplier used for adjusting normal scrolling speed. */ scrollSensitivity?: number; /** * Options for configuring the scrollbar. */ scrollbar?: IScrollbarOptions; /** * The duration to smoothly scroll between the origin and the target in * milliseconds. Set to 0 to disable smooth scrolling and scroll instantly. */ smoothScrollDuration?: number; /** * The size of tab stops in the terminal. */ tabStopWidth?: number; /** * The color theme of the terminal. */ theme?: ITheme; /** * Enable various VT extensions. */ vtExtensions?: IVtExtensions; /** * Compatibility information when the pty is known to be hosted on Windows. * Setting this will turn on certain heuristics/workarounds depending on the * values: * * - `if (backend !== undefined || buildNumber !== undefined)` * - When increasing the rows in the terminal, the amount increased into * the scrollback. This is done because ConPTY does not behave like * expect scrollback to come back into the viewport, instead it makes * empty rows at of the viewport. Not having this behavior can result in * missing data as the rows get replaced. * - `if !(backend === 'conpty' && buildNumber >= 21376)` * - Reflow is disabled * - Lines are assumed to be wrapped if the last character of the line is * not whitespace. */ windowsPty?: IWindowsPty; /** * A string containing all characters that are considered word separated by * the double click to select work logic. */ */ colorSchemeQuery?: boolean; } /** * Pty information for Windows. */ export interface IWindowsPty { /** * What pty emulation backend is being used. */ backend?: 'conpty' | 'winpty…[truncated]</excerpt> </source> <source kind="search"> <title>IWindowsPty</title> <location>https://xtermjs.org/docs/api/terminal/interfaces/iwindowspty/</location> <excerpt>citeturn0search1 [wordlim: 200] Crawled: 6 months ago; # Interface: IWindowsPty ... • backend? : *“conpty” | “winpty”*Defined in xterm.d.ts:425 ... ### `Optional` buildNumber # Interface: IWindowsPty Pty information for Windows. ## Properties ### `Optional` backend • backend? : *“conpty” | “winpty”* Defined in xterm.d.ts:425 What pty emulation backend is being used. * * * ### `Optional` buildNumber • buildNumber? : number Defined in xterm.d.ts:429 The Windows build version (eg. 19045)</excerpt> </source> <source kind="search"> <title>Releases · xtermjs/xterm.js · GitHub</title> <location>https://github.com/xtermjs/xterm.js/releases</location> <excerpt>citeturn0search2 [wordlim: 200] Crawled: 2 days ago; * #5321 Reflow on resize using similar logic to conpty ... * #5130 Remove xterm- prefix from addon mjs output ... This commit was created on GitHub.com and signed with GitHub’s verified signature. ... buildNumber: 19000 ... * `windowsMode` has been deprecated in favor of `windowsPty` ... term.setOption('scrollback', 1000); * #5379 Bump form-data from 4.0.0 to 4.0.4 in /addons/addon-ligatures * #5362 Move copilot steps to correct folder * #5359 Add copilot setup steps * #5358 Revert conpty-specific reflow handling * #5349 Add comprehensive tests for alt+shift+letter keyboard combinations * #5345 Add instructions to help Copilot coding agent * #5329 Update and pin esbuild * #5322 Bump axios from 1.7.4 to 1.8.2 in /addons/addon-ligatures * #5321 Reflow on resize using similar logic to conpty * #5317 docs: added usage tip for registerMarker() * #5313 Revert "Merge pull request #5253 from akphi/patch-1" * #5308 Update AccessibilityManager.ts to use textContent rather than innerText * #5290 Progress polish * #5286 Move WebGL addon-specific code into addon * #5281 Pin Ubuntu 22 to fix playwright GH Actions issue for now ## 5.2.0 5.2.0 Compare # Choose a tag to compare ## Sorry, something went wrong. Filter Loading [Input] ## Sorry, something went wrong. ### Uh oh! There was an error while loading. Please reload this page. ## No results found View all tags Image: @Tyriar Tyriar released this 08 Jun 22:01 5.2.0 `cc1089e` This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired. GPG key ID: 4AEE18F83AFDEB23 Expired Verified Learn about vigilant mode. ## 🚀 Features * Support for the overline attribute SGR 53/55 (#4526, #4532) via @Tyriar ### 📦 API * Improved Windows workarounds with the new windowsPty option (#4539) via @Tyriar const term = new Terminal({ windowsPty: { backend: 'conpty', buildNumber: 19000 } }); ## 🐞 Bug fixes * Update CI containers to use Node 18 (#4542) via @silamon 4542 * Remove unused imports (#4361) via @Eugeny * Replace dom helper with HTMLElement.remove() (#4364) via @Tyriar * Show proper parameter hints when calling createInstance (#4393) via @Tyriar * Correct registerMarker API docs (#4464) via @Tyriar * Add FAQ to new issue report (#4512) via @Tyriar * Fix buffer corruption for utf8 transport in demo (#4527) via @jerch ## ⚠️ Deprecations * `windowsMode` has been deprecated in favor of `windowsPty` // Before 5.2 term = new Terminal({ windowsMode: true }); // After 5.2 term = new Terminal({ windowsPty: { backend: 'conpty', buildNumber: 19000 } }); ## 🎉 New real-world use cases * graSSHopper (#4356) via @Coding-Kiwi * DomTerm (#4456) via @Tyriar </excerpt> </source> <source kind="search"> <title>Scrollback goes missing when resizing a conpty-based terminal · Issue #2459 · xtermjs/xterm.js · GitHub</title> <location>GitHub issue 2459 in xtermjs/xterm.js (link omitted to avoid creating a cross-reference)</location> <excerpt>citeturn0search3 [wordlim: 200] Published: 7.0 years ago; Crawled: 2 weeks ago; 1. xtermjs ... # Scrollback goes missing when resizing a conpty-based terminal #2459 ... * Resize back to 26 rows - the 10 rows get pushed down into the viewport and then immediately get overwritten by conpty reprinting the screen 1. xtermjs 2. xterm.js # Scrollback goes missing when resizing a conpty-based terminal #2459 New issue Copy link New issue Copy link Closed #2476 Closed Scrollback goes missing when resizing a conpty-based terminal#2459 #2476 Copy link Assignees Labels platform/windowstype/bugSomething is misbehavingSomething is misbehaving Milestone 4.2.0 ## Description Tyriar opened on Oct 9, 2019 Issue body actions VS Code issue: microsoft/vscode#78634 I think it's related to how we try to pull scrollback into the viewport when resizing upwards, but then conpty still draws its current state of the work. Maybe we should disable that in windows mode? ## Activity 1. Tyriar added type/bugSomething is misbehavingSomething is misbehaving platform/windows on Oct 9, 2019 2. Tyriar added this to the 4.2.0 milestone on Oct 9, 2019 3. Tyriar self-assigned this on Oct 9, 2019 4. ### Tyriar commented on Oct 16, 2019 Tyriar on Oct 16, 2019 Member Author More actions Repro: * Enable conpty ([email protected]+) * Open demo * Run dir * Resize to 16 rows (everything is fine) * Resize back to 26 rows - the 10 rows get pushed down into the viewport and then immediately get overwritten by conpty reprinting the screen 5. Tyriar added a commit that references this issue on Oct 16, 2019 Fix scrollback going missing when increase size on Windows ... This issue will close once commit 843ea1b is merged into the 'master' branch. 843ea1b 6. Tyriar closed this as completedin #2476on Oct 17, 2019 ## Metadata ## Metadata ### Assignees * Tyriar ### Labels platform/windowstype/bugSomething is misbehavingSomething is misbehaving ### Type No type ### Projects No projects ### Milestone * 4.2.0 ### Relationships None yet ### Development No branches or pull requests</excerpt> </source> <omitted_sources count="26">Additional source records were omitted from this bounded result.</omitted_sources> </source_evidence> Citations: - 1: https://github.com/xtermjs/xterm.js/blob/master/typings/xterm.d.ts - 2: https://github.com/xtermjs/xterm.js/blob/master/typings/xterm.d.ts - 3: https://github.com/xtermjs/xterm.js/blob/master/typings/xterm.d.ts
Resolve the resize model mismatch for WSL panes.
The daemon enables windowsPty for every non-POSIX owner backend, including windows-wsl. The renderer does not enable it for WSL panes. Its buildWindowsPtyCompatibilityOptions returns {} when the cwd is a WSL UNC path or the shell override launches wsl.exe. xterm's windowsPty typing says this option stops ConPTY-backed scrollback from being pulled back into the viewport when rows increase. A renderer without it can pull restored history into the viewport on a row increase, while the daemon snapshot keeps the ConPTY grid. The two views can then diverge for WSL panes, which is the mismatch this PR fixes.
Choose one resize model for WSL panes and apply it in both the daemon and the renderer. The renderer exclusion is covered by tests in windows-pty-compatibility.test.ts, so changing it also changes that contract. Confirm the intended WSL behavior before editing either side.
ConPTY's screen holds only what the shell wrote at its current height, so a shrink drops the rows above the cursor and each resize repaints that screen. Assert every restored and shell row appears once, in order, across shrink, shrink-then-grow and grow-past-original heights.
ELI5
On Windows, if you restart Orca and a restored terminal gets resized, the terminal could lose about a screen of its old output, and the new prompt could end up glued to the old one (
deep$ orca@…deep$). This stops that.What Changed
Before: a Windows terminal restored after Sleep was fine until the app was killed and relaunched. The relaunched window's first fit resizes the terminal smaller and back. The next saved history then had:
That saved history is replayed on every later restore.
After: restored history and its padding survive the resize.
Mechanism: the terminal daemon keeps its own emulator copy of each terminal, and that copy is what gets saved as history.
windowsPty): when the screen grows, it adds blank rows at the bottom instead of pulling scrollback down. The window already uses it for native Windows panes.src/shared/xterm-conpty-options.ts, so the daemon and the window share one copy.Why
The emulator has to model the grid the same way ConPTY does, or ConPTY's repaints land on the wrong rows.
Alternatives considered:
macOS, Linux and SSH daemons are unchanged: they don't use ConPTY.
Linked Issue
N/A (maintainer).
Visual Proof
N/A: Windows/WSL history content; covered by the daemon test and the Windows verify run.
Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
New
src/main/daemon/session-conpty-resize-history.test.tschecks the daemon's teardown snapshot, which is what Sleep saves.pnpm tcpasses, and so doaudit:code-quality:native,audit:code-quality:type-aware,audit:anti-slop, the ratchets and oxlint.src/main/daemonand the window's Windows-PTY tests pass. The exceptions are 20 real-shell tests (shell-ready.test.ts,repro-13767-…), which fail the same way on clean main on macOS.The original failure was seen on Windows + WSL in an internal verify run: a Sleep → Wake → kill and relaunch → Sleep sequence.
Review
Agent skill upstream boundary
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)