[PR #19425] fix(conpty): detect WSL switch when entered via command (fix #19420) #31837

Open
opened 2026-01-31 09:49:52 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/19425

State: closed
Merged: No


Summary

Fixes #19420 — Terminal Chat did not detect WSL when launched by running wsl inside an existing Windows shell.

Root cause

When a user launches wsl from an existing PowerShell/CMD session, the new WSL process runs as a child of the shell. Terminal previously only relied on the launched process at tab-creation to determine the environment and thus missed the manual wsl case.

Fix

  • Added WSL detection and environment-change notification to ConptyConnection::Start(). After launching the attached client, we check the commandline and set a _isWSLConnection flag and raise an _environmentChangedEventHandlers event when wsl is detected.
  • Declared the _isWSLConnection flag and _environmentChangedEventHandlers in ConptyConnection so other components (e.g., Terminal Chat) can subscribe and update context.

Files changed

  • src/cascadia/TerminalConnection/ConptyConnection.h (added _isWSLConnection flag and event)
  • src/cascadia/TerminalConnection/ConptyConnection.cpp (added detection logic after launching client)

Testing

  • Manual:

    1. Build and run local Windows Terminal.
    2. Open PowerShell tab, run wsl, open Terminal Chat — chat should now detect WSL (or logs show ConPtyDetectedWSLCommand event).
    3. Confirm launching WSL from the dropdown still behaves correctly.
  • CI: Unit tests touched are logic-only; no new flaky tests added.

Notes

  • The detection is a lightweight check of the commandline and raises an event for listeners; if maintainers prefer a different event system or WSL-detection utility, happy to adjust.
**Original Pull Request:** https://github.com/microsoft/terminal/pull/19425 **State:** closed **Merged:** No --- ## Summary Fixes #19420 — Terminal Chat did not detect WSL when launched by running `wsl` inside an existing Windows shell. ### Root cause When a user launches `wsl` from an existing PowerShell/CMD session, the new WSL process runs as a child of the shell. Terminal previously only relied on the launched process at tab-creation to determine the environment and thus missed the manual `wsl` case. ### Fix - Added WSL detection and environment-change notification to `ConptyConnection::Start()`. After launching the attached client, we check the commandline and set a `_isWSLConnection` flag and raise an `_environmentChangedEventHandlers` event when `wsl` is detected. - Declared the `_isWSLConnection` flag and `_environmentChangedEventHandlers` in `ConptyConnection` so other components (e.g., Terminal Chat) can subscribe and update context. ### Files changed - `src/cascadia/TerminalConnection/ConptyConnection.h` (added _isWSLConnection flag and event) - `src/cascadia/TerminalConnection/ConptyConnection.cpp` (added detection logic after launching client) ### Testing - Manual: 1. Build and run local Windows Terminal. 2. Open PowerShell tab, run `wsl`, open Terminal Chat — chat should now detect WSL (or logs show `ConPtyDetectedWSLCommand` event). 3. Confirm launching WSL from the dropdown still behaves correctly. - CI: Unit tests touched are logic-only; no new flaky tests added. ### Notes - The detection is a lightweight check of the commandline and raises an event for listeners; if maintainers prefer a different event system or WSL-detection utility, happy to adjust.
claunia added the pull-request label 2026-01-31 09:49:52 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#31837