8000 fix(startup-commands): clear the line before typing when a DA1 reply was written by stlindenau · Pull Request #467 · amirlehmam/wmux · GitHub
[go: up one dir, main page]

Skip to content

fix(startup-commands): clear the line before typing when a DA1 reply was written - #467

Merged
amirlehmam merged 1 commit into
amirlehmam:masterfrom
stlindenau:fix/da1-reply-startup-command-junk
Nov 21, 2026
Merged

amirlehmam merged 1 commit into
amirlehmam:masterfrom
stlindenau:fix/da1-reply-startup-command-junk

Conversation

@stlindenau
Copy link
Copy Markdown
Contributor

Problem

After a wmux restart, a restored WSL pane can fail to re-run its stored startup command. The shell shows:

$ 62;4;9;22ccd '/path/to/project' && ./launch.sh
bash: 62: command not found
bash: 4: command not found
bash: 9: command not found
bash: 22ccd: command not found

Retyping the command by hand works, so the command itself is fine.

Cause

PtyManager answers a Device Attributes (DA1) probe by writing ESC[?62;4;9;22c to 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 unbound ESC[? and inserts 62;4;9;22c on the line. The startup command is then typed behind it, and bash runs 62, 4, 9 and 22ccd .... With an && chain the cd and 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 -i on a pty: write ESC[?62;4;9;22c, then echo ran-ok && echo second\r. Bash prints the same four command not found lines. Writing Ctrl-U (\x15) first makes the command run.

Fix

When PtyManager has written a DA1 reply to a PTY, typed startup commands go in behind a Ctrl-U (readline unix-line-discard), which empties the line.

  • startup-commands.ts: startupKeystrokes(commands, { discardLine }), ctrlUDiscardsLine(shellType), and an optional discardLine() dep on deliverStartupCommandsWhenReady, asked at send time so a reply that lands during the settle window still counts.
  • pty-manager.ts: PtyEntry.da1Replied, set wherever DA1_REPLY is 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, discardLine read at send time, no prefix when no reply was written). 27/27 pass.
  • npm run typecheck is clean; eslint reports no new warnings.
  • On Windows, tests/unit/pty-manager.test.ts passes 71/72. The failure is skips WindowsApps aliases and finds a real file for pwsh, which needs PowerShell 7 installed and fails the same way on master without it.
  • Manual: restarted wmux several times with a WSL pane holding a stored restore command; the command now runs with nothing in front of it. Before the change it failed intermittently with the output above.
  • No automated test covers PtyManager setting da1Replied; that suite needs ConPTY.

🤖 Generated with Claude Code

…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>
@amirlehmam
amirlehmam merged commit 999d20e into amirlehmam:master Nov 21, 2026
@amirlehmam
Copy link
Copy Markdown
Owner

Merged, and released in 2.64.3. Thanks for this one: the standalone bash -i reproduction made the cause easy to confirm, and asking discardLine at send time covers a reply that lands during the settle window.

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.

@stlindenau
stlindenau deleted the fix/da1-reply-startup-command-junk branch November 21, 2026 13:32
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.

2 participants

0