Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 18, 2025

Description

On Windows 10, the OSC 633;E escape sequence causes a rendering race condition where escaped command text (e.g., \x5c for backslashes) appears in the terminal output, particularly with long commands (>100 characters). This occurs because the terminal incorrectly echoes the escaped content meant for history tracking.

Changes

  • Modified PSConsoleHostReadLine function in shellIntegration.ps1 to conditionally skip OSC 633;E sequence on Windows 10 (build < 22000)
  • Windows 11 and other platforms continue to send the sequence normally
  • OSC 633;C sequence remains active on all platforms, preserving command execution tracking
  • Shell integration features (prompt tracking, CWD detection, environment reporting) unaffected
# Before: Always sent OSC 633;E
$Result = "$([char]0x1b)]633;E;"
$Result += $(__VSCode-Escape-Value $CommandLine)
# ...

# After: Conditional on Windows version
$Result = ""
if ($Global:__VSCodeState.IsWindows10 -eq $false) {
    $Result = "$([char]0x1b)]633;E;"
    $Result += $(__VSCode-Escape-Value $CommandLine)
    # ...
}

Trade-off: Command line content not reported on Windows 10, but eliminates display corruption. Core shell integration functionality preserved via other OSC sequences.

Original prompt

This section details on the original issue you should resolve

<issue_title>shellIntegration.ps1 caused Python Debugger with Garbled Text</issue_title>
<issue_description>

Does this issue occur when all extensions are disabled?: Yes

Local Configuration

Operating System: Windows 10 Pro 22H2 (19045.6093)

VSCode Version: 1.106.3

PowerShell Version: 7.5.2

📋 Table of Contents


Problem Description

Symptoms

When using the integrated terminal in VSCode to run a Python debugging session via F5 or execute a long command, the terminal displays a string of garbled text. For example:

PS C:\Users\SeanL\Desktop> c:; cd 'c:\Users\SeanL\Desktop'; & 'd:\Miniconda3\envs\test\python.exe' 'c:\Users\SeanL\.vscode\extensions\ms-python.debugpy-2025.16.0-win32-x64\bundled\libs\debugpy\launcher' '3729' '--' 'C:\Users\SeanL\Desktop\a.py'

launcher' '3729' '--' 'C:\x5cUsers\x5cSeanL\x5cDesktop\x5ca.py'
Traceback (most recent call last):
  ...

Note the garbled output on the second line: launcher' '3729' '--' 'C:\x5cUsers\x5cSeanL\x5cDesktop\x5ca.py'. This line of garbled text is overlaid on the script's output, obscuring readability during debugging, although it does not affect the script's execution.

It's important to note that this issue is not consistently reproducible with every run of the same file.

Key Characteristics

  • ✅ The garbled content is a part of the command line (the tail end of the command).
  • ✅ The backslash \ is escaped as \x5c.
  • ✅ Only occurs in the VSCode integrated terminal.
  • ✅ Only occurs when executing relatively long commands (typically > 100 characters).
  • ✅ Does not occur when launching PowerShell with the -NoProfile flag.
  • ✅ Using -NoProfile is not a viable workaround as it breaks Conda environment activation and other profile-dependent functionalities.

Problem Analysis

Trigger Conditions

  1. Environment Requirements:
    • VSCode Integrated Terminal is used.
    • PowerShell is set as the default shell.
    • Shell Integration is enabled (default in VSCode).
    • PowerShell Profile is loaded.
  2. Command Characteristics:
    • Command length is relatively long.
    • Command contains path arguments (e.g., Python debugger path).
    • Command includes special characters (e.g., backslashes, quotes).

Why only in VSCode?

VSCode's Shell Integration feature automatically injects a script, shellIntegration.ps1, to enhance the terminal experience (command tracking, output capturing, smart navigation, etc.). This script communicates with VSCode using OSC (Operating System Command) escape sequences.

Other terminals (Windows Terminal, ConEmu, etc.) do not inject this script, hence the problem is specific to the VSCode integrated terminal.


Root Cause

Technical Mechanism

OSC 633 Control Sequence
VSCode Shell Integration uses the OSC 633 series sequences to track command execution:

  • OSC 633;A - Prompt start
  • OSC 633;B - Prompt end / Command input start
  • OSC 633;C - Command execution start
  • OSC 633;D - Command execution finished (with exit code)
  • OSC 633;E - Command line content (for history tracking) ⚠️ Source of the problem

Detailed Explanation

Inside the PSConsoleHostReadLine function of shellIntegration.ps1 (around lines 195-222), the following logic is implemented:

function Global:PSConsoleHostReadLine {
    $CommandLine = $Global:__VSCodeState.OriginalPSConsoleHostReadLine.Invoke()
    $Global:__VSCodeState.IsInExecution = $true

    # Construct OSC 633;E sequence
    $Result = "$([char]0x1b)]633;E;"
    $Result += $(__VSCode-Escape-Value $CommandLine)  # ⚠️ Escape command line
    # ...
    $Result += "`a"

    # Send to terminal
    [Console]::Write($Result)
    
    $CommandLine  # Return original command for PowerShel...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes microsoft/vscode#281461

<!-- START COPILOT CODING AGENT TIPS -->
---

💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey).

Copilot AI self-assigned this Dec 18, 2025
Copilot AI and others added 2 commits December 18, 2025 18:43
Co-authored-by: anthonykim1 <62267334+anthonykim1@users.noreply.github.com>
Co-authored-by: anthonykim1 <62267334+anthonykim1@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix Python debugger garbled text issue in shellIntegration.ps1 Fix garbled text in PowerShell terminal on Windows 10 by disabling OSC 633;E sequence Dec 18, 2025
Copilot AI requested a review from anthonykim1 December 18, 2025 18:50
Copy link

@7011010 7011010 left a comment

Choose a reason for hiding this comment

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

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.

3 participants