Skip to content

Find dev-server ports in Git Bash and WSL panes on Windows - #1348

Merged
nedtwigg merged 2 commits into
mainfrom
fix/port-detection-wsl-gitbash
Oct 21, 2026
Merged

nedtwigg merged 2 commits into
mainfrom
fix/port-detection-wsl-gitbash

Conversation

@nedtwigg

Copy link
Copy Markdown
Member

Dev-server port detection (Dev-Server Chip, dor agent-browser open surface:N, dor list --ports) worked for cmd and PowerShell panes on Windows but not for Git Bash or WSL.

Git Bash. Ports come from walking the Windows process tree down from the pane's shell. An MSYS exec replaces the Windows process, so node (which Git runs as winpty node.exe under TERM=xterm*) hung off a winpty.exe whose Windows parent had already exited, and the walk never reached it. For a root whose shell is Git Bash, the scan now also reads MSYS's own ps -a (which keeps the parent links and names each Windows pid). Each owned set then grows from its MSYS processes to their MSYS descendants, and from those to their Windows descendants. ps runs beside the process-table read.

WSL. With mirrored networking, a Linux listener on 127.0.0.1 is reachable from Windows but appears in neither Get-NetTCPConnection nor netstat, so no Windows-side walk can find it. For a root with wsl.exe anywhere beneath it (a WSL pane, or wsl typed into PowerShell), the scan lists running distros and runs one sh script in each. The script finds processes whose environment carries the pane's DORMOUSE_SURFACE_ID (which already crosses in through WSLENV) with a single grep -z over /proc/*/environ, lists their sockets, and reads /proc/net/tcp{,6}. That runs beside the Windows socket scan, within its allowance. Surface ids are validated before they reach the script.

Specs: docs/specs/transport.md → "Message protocol" (pty:getOpenPorts) and "Port scan deadlines", with the measurements in the rationale.

Testing

  • Unit: a Windows scan whose node.exe hangs off an orphaned winpty.exe (found through MSYS ps) and whose WSL listener is found in the distro, attributed only to its Surface. A cmd-only scan runs neither extra read.
  • Real panes through create() on Windows 11 with mirrored networking: Git Bash running node -e "...listen(43123)" reports 43123 (node.exe); a WSL pane running python3 -m http.server 43124 reports 43124 (python3); wsl typed into a PowerShell pane does too. One getOpenPortsMany for both took ~0.9 s.

Limits: bash typed inside a PowerShell or cmd pane gets no MSYS read (the trigger is the pane's own shell). A Linux process that drops its environment, or a daemon outside the pane's tree, isn't found.

🤖 Generated with Claude Code

Git Bash: an MSYS exec replaces the Windows process, so a program like
`winpty node.exe` named a parent that had exited and the walk from the pane
never reached it. MSYS ps keeps those links; a Git Bash root's owned set now
grows through them.

WSL: a Linux listener is no Windows process, and with mirrored networking
not even a Windows socket. A root running wsl.exe now has its listeners read
inside each running distro, from the processes whose environment carries
the pane's DORMOUSE_SURFACE_ID.

Each read runs beside a step the scan already waits for, within its budget.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Deploying mouseterm with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8454f3a
Status: ✅  Deploy successful!
Preview URL: https://65939c22.mouseterm.pages.dev
Branch Preview URL: https://fix-port-detection-wsl-gitba.mouseterm.pages.dev

View logs

@dormouse-bot dormouse-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ptySurfaces stores a value that is always the PTY id. spawn calls resolveSpawnConfig({ ...options, id, surfaceId: id }, …), which sets DORMOUSE_SURFACE_ID: surfaceId || options?.id || '', so the map's value always equals its key. surfaceOf can return idAtPid(pid) directly. That drops the map and its three cleanup sites, which would otherwise need to stay in step with ptyShells. The suggestions below make that change.

Comment thread standalone/sidecar/pty-core.js Outdated
Comment thread standalone/sidecar/pty-core.js Outdated
Comment thread standalone/sidecar/pty-core.js Outdated
Comment thread standalone/sidecar/pty-core.js Outdated
Comment thread standalone/sidecar/pty-core.js Outdated
Comment thread standalone/sidecar/pty-core.js Outdated
…SURFACE_ID

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nedtwigg
nedtwigg merged commit 8f12aac into main Oct 21, 2026
20 checks passed
@nedtwigg
nedtwigg deleted the fix/port-detection-wsl-gitbash branch October 21, 2026 21:46
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