Repository navigation
fix(startup-commands): clear the line before typing when a DA1 reply was written - #467
Conversation
…was written PtyManager answers a Device Attributes probe by writing ESC[?62;4;9;22c to the PTY's stdin whether or not the shell reads it. In a WSL pane, bash's readline drops ESC[? and inserts 62;4;9;22c on the line, so a typed restore command arrived as `62;4;9;22ccd '...' && ...` and bash ran 62, 4, 9 and 22ccd instead. The && chain never ran, so the container was not re-entered after a restart. Type Ctrl-U (readline unix-line-discard) ahead of typed startup commands when a DA1 reply was written to that PTY, for shells other than cmd and PowerShell. The check runs at send time so a reply landing in the settle window counts. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Merged, and released in 2.64.3. Thanks for this one: the standalone I ran the branch on current master before merging: the startup-commands and pty-manager suites pass (99/99, with PowerShell 7 installed here, so the alias test you mentioned passes too), and the full suite is green. One thing I checked and left as is: every shell that isn't cmd or PowerShell gets the Ctrl-U, which includes anything launched as a custom shell. It is only sent after wmux has written a DA1 reply, and on an empty line it does nothing, so I don't see a case where it makes things worse. If you run into one, open an issue and I'll narrow the gate. |
Problem
After a wmux restart, a restored WSL pane can fail to re-run its stored startup command. The shell shows:
Retyping the command by hand works, so the command itself is fine.
Cause
PtyManageranswers a Device Attributes (DA1) probe by writingESC[?62;4;9;22cto the PTY's stdin, whether or not the shell is going to read it. PSReadLine consumes it. A WSL pane's bash does not: readline drops the unboundESC[?and inserts62;4;9;22con the line. The startup command is then typed behind it, and bash runs62,4,9and22ccd .... With an&&chain thecdand the rest never run.The reply lands in stdin as type-ahead while the login rc is still running, so a slow rc makes it more likely. The existing mitigation (
bakeIntoInit) only covers PowerShell with the integration script. WSL, Git Bash and cmd get their commands typed.Reproduced outside wmux with
bash -ion a pty: writeESC[?62;4;9;22c, thenecho ran-ok && echo second\r. Bash prints the same fourcommand not foundlines. Writing Ctrl-U (\x15) first makes the command run.Fix
When
PtyManagerhas written a DA1 reply to a PTY, typed startup commands go in behind a Ctrl-U (readlineunix-line-discard), which empties the line.startup-commands.ts:startupKeystrokes(commands, { discardLine }),ctrlUDiscardsLine(shellType), and an optionaldiscardLine()dep ondeliverStartupCommandsWhenReady, asked at send time so a reply that lands during the settle window still counts.pty-manager.ts:PtyEntry.da1Replied, set whereverDA1_REPLYis written (the direct path and the deferred path behind the inherited-cursor reply). Passed to the delivery for every shell except cmd and PowerShell, where Ctrl-U is not kill-line.Stopping the reply from reaching the shell at all is out of scope: nothing can tell when the probe is seen whether anything will read the answer, and ConPTY needs it.
Testing
tests/unit/startup-commands.test.ts: five new cases (keystroke prefix, shell gating,discardLineread at send time, no prefix when no reply was written). 27/27 pass.npm run typecheckis clean;eslintreports no new warnings.tests/unit/pty-manager.test.tspasses 71/72. The failure isskips WindowsApps aliases and finds a real file for pwsh, which needs PowerShell 7 installed and fails the same way onmasterwithout it.PtyManagersettingda1Replied; that suite needs ConPTY.🤖 Generated with Claude Code