You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Debugging to the end of a file causes the debug terminal to be killed #2095
I'm using an Ubuntu WSL instance with pwsh as the default terminal profile.
After I debug a file in Python, I want to see the result of the run, but the debugging terminal tab is killed seconds after the debugger reaches the end of the file.
Edit: I'm unable to reproduce the issue when I switch the default terminal profile to bash.
Hi, I would like to work on this if that is welcome.
What I found so far:
The screenshot shows the debuggee finishing normally, and then pwsh itself crashing with an Input/output error from System.ConsolePal.TryGetCursorPosition, inside a nested prompt input loop. So the tab is not being closed by VS Code; the shell process dies at the end of the run.
In this repo, the pwsh specific part of the flow is the runInTerminal command construction in the launch resolver, which picks the quote character based on the default terminal profile and marks the arguments for shell interpretation.
What I would do:
Reproduce the command shape locally with pwsh on Linux and work through the resolver's quoting and argument handling for the pwsh profile, to pin down whether the trigger sits in this extension's command construction.
Add or adjust unit tests next to the existing launch resolver tests for the pwsh case.
If the trigger turns out to sit in VS Code core or in pwsh itself, I will report the evidence back here instead of forcing a change in this repo.
A follow-up with the results of the local investigation I mentioned above.
Setup: pwsh 7.4.6 on Linux, driven through a pty harness that answers cursor position queries the way a real terminal does. That query is the ESC[6n sequence, and it is the exact call in the crash stack from the screenshot, System.ConsolePal.TryGetCursorPosition.
What I ran: the same command shape the screenshot shows, a cd followed by the quoted launcher invocation, with a short lived Python process as the child. The child output printed, pwsh returned to the prompt, and the shell stayed alive. I saw the same result when the child was interrupted mid run.
One more observation: when the terminal does not answer the cursor position query at all, pwsh blocks inside that call, which lines up with where the reported failure surfaces.
My conclusion: the command construction this extension produces for pwsh does not by itself kill the shell. The crash needs the terminal side to fail that cursor query at the wrong moment, which points at the WSL pty layer in VS Code, or at pwsh's own handling of that failure, rather than at this repo's code.
Happy to test a specific scenario if that would help, and if a repo side change is identified I will build it.
Hi Rich Chiodo (@rchiodo). I have now run this through the debugger itself, in two setups, and the debug terminal is lost with pwsh in both. One of the setups is the reporter's own environment: VS Code connected to a WSL Ubuntu instance, with pwsh as the default terminal profile inside WSL.
TLDR: Through the real debugger, pwsh lost the debug terminal in 9 of 9 connected launches (4 on Windows with WSL, 5 on native Linux), always within about a second of the session ending. Bash kept it in 9 of 9. On Linux the close event shows pwsh itself exiting cleanly (code 0, reason Process). The reporter's crash text did not appear in either setup, and shell integration on or off makes no difference.
Summary (connected launches only)
Setup
Profile
Launches
Terminal after the session ended
Windows + WSL (Ubuntu 26.04)
pwsh 7.6.6
4 (3 run to end, 1 stopped)
Gone within a second, 4 of 4
Windows + WSL (Ubuntu 26.04)
bash
3 (2 run to end, 1 stopped)
Stayed open, 3 of 3
Native Linux
pwsh 7.4.6
5 (3 run to end, 2 stopped)
Closed within about a second, 5 of 5
Native Linux
bash
6 (4 run to end, 2 stopped)
Stayed open, 6 of 6
Notes:
Stopping a session mid run also loses the pwsh terminal; bash keeps it in all cases. On WSL the tab vanished 0.3 to 0.7 s after the session ended, with no crash text in the buffer before it went (those runs were manual, so no exit status there).
In both setups the launcher command sometimes sits typed in the pwsh terminal without executing (on WSL it needed Enter; some headless Linux attempts timed out waiting for the launcher). Those attempts are not in the counts, and it never happened with bash.
WSL setup honesty notes: pwsh was the official 7.6.6 build run through a small local wrapper (the distro had no pwsh, and the package first failed on a missing ICU library), and the workspace sat on the Windows drive mount.
Environments
Item
WSL setup
Linux setup
OS
Windows 10 (26H2, build 26300), WSL 2, Ubuntu 26.04.1
Native Linux
VS Code, Python Debugger, Python ext
1.146.0, 2026.6.0, 2026.10.0
Same
Python / PowerShell
3.14.4 / 7.6.6
3.12.3 / 7.4.6
Steps: set pwsh as the default terminal profile (in the WSL window for the first setup), debug a short Python file with "console": "integratedTerminal", and let it run to the end of the file. Expected: the terminal stays open with the output, as with bash. Actual: the tab is gone within about a second of the session ending.
Screenshots
WSL, pwsh, during a run: the launcher command and the full program output in the Python Debug Console.
Native Linux, pwsh, just after a run to end: only the unrelated warmup terminal is left, the Python Debug Console is gone.
WSL, bash control, after the wait: the debug terminal is still open with the full output and the prompt back.
Commands, timelines, and the launch config
runInTerminal command sent to the pwsh terminal (WSL log):
One question: is pwsh ending when the launcher command finishes expected from how the debug terminal is created, or does this look like the same failure as the reporter's crash, just without the crash in these setups? Happy to collect a trace or test a specific scenario if that helps.
is pwsh ending when the launcher command finishes expected from how the debug terminal is created, or does this look like the same failure as the reporter's crash, just without the crash in these setups? Happy to collect a trace or test a specific scenario if that helps.
No, I don't believe pwsh exiting is expected. That's the whole bug. It's not clear what is causing the pwsh terminal to actually exit.
Rich Chiodo (@rchiodo) I dug into the debug terminal, and I think I found what makes pwsh exit.
TLDR: Found the cause. debugpy makes the debuggee the terminal's foreground process group and never sets it back. bash reclaims it with job control, pwsh cannot, so pwsh's next prompt read fails with the reporter's exact crash. In isolation pwsh crashed 5 of 5 with that preexec, and survived every control, including 3 of 3 when the launcher restores the foreground before exiting.
This extension never creates or closes the terminal. It only passes the console setting on. VS Code core creates the debug terminal, and on session end it only frees it for reuse, it does not dispose it or send it anything.
The one place that changes who owns the terminal is in debugpy. In launcher/debuggee.py, spawn() runs the debuggee with a preexec that does os.setpgrp() and then os.tcsetpgrp() on /dev/tty, so the debuggee becomes the foreground process group of the terminal. Nothing in debugpy ever sets it back.
I tested that in isolation, with no VS Code and no debug session: a plain pwsh in a pty, running a small launcher that spawns a short Python child using that exact preexec, then exits with the child's code, the same shape as the debugpy launcher.
pwsh with that preexec: 5 of 5 runs printed the reporter's exact crash and never came back to a usable prompt: "Process terminated. Input/output error", FailFast, in System.ConsolePal.TryGetCursorPosition, inside EnterNestedPrompt. That is the text from the original screenshot, word for word.
Same child without the tcsetpgrp call: pwsh survived 2 of 2.
Same test in bash: bash survived 3 of 3, because bash does job control and takes the foreground back when the job ends. pwsh has no Unix job control, so once the debuggee group dies, pwsh is left in a background group and its next prompt read fails with that Input/output error.
If the launcher sets the foreground back to its own group before exiting: pwsh survived 3 of 3.
So my read is that the fix sits in the debugpy launcher, restoring the foreground group before it exits, rather than in this repo's command construction. Happy to open an issue in debugpy with the repro script, or to add the script here if you would rather keep it in one place.
Activity
PCTEJA commentedon Nov 16, 2026
Hi, I would like to work on this if that is welcome.
What I found so far:
The screenshot shows the debuggee finishing normally, and then pwsh itself crashing with an Input/output error from System.ConsolePal.TryGetCursorPosition, inside a nested prompt input loop. So the tab is not being closed by VS Code; the shell process dies at the end of the run.
In this repo, the pwsh specific part of the flow is the runInTerminal command construction in the launch resolver, which picks the quote character based on the default terminal profile and marks the arguments for shell interpretation.
What I would do:
Reproduce the command shape locally with pwsh on Linux and work through the resolver's quoting and argument handling for the pwsh profile, to pin down whether the trigger sits in this extension's command construction.
Add or adjust unit tests next to the existing launch resolver tests for the pwsh case.
If the trigger turns out to sit in VS Code core or in pwsh itself, I will report the evidence back here instead of forcing a change in this repo.
Could I take this one?
PCTEJA commentedon Nov 17, 2026
A follow-up with the results of the local investigation I mentioned above.
Setup: pwsh 7.4.6 on Linux, driven through a pty harness that answers cursor position queries the way a real terminal does. That query is the ESC[6n sequence, and it is the exact call in the crash stack from the screenshot, System.ConsolePal.TryGetCursorPosition.
What I ran: the same command shape the screenshot shows, a cd followed by the quoted launcher invocation, with a short lived Python process as the child. The child output printed, pwsh returned to the prompt, and the shell stayed alive. I saw the same result when the child was interrupted mid run.
One more observation: when the terminal does not answer the cursor position query at all, pwsh blocks inside that call, which lines up with where the reported failure surfaces.
My conclusion: the command construction this extension produces for pwsh does not by itself kill the shell. The crash needs the terminal side to fail that cursor query at the wrong moment, which points at the WSL pty layer in VS Code, or at pwsh's own handling of that failure, rather than at this repo's code.
Happy to test a specific scenario if that would help, and if a repo side change is identified I will build it.
rchiodo commentedon Nov 17, 2026
Did you try the same thing using the debugger?
PCTEJA commentedon Nov 17, 2026
Hi Rich Chiodo (@rchiodo), not yet, am working on it now.
PCTEJA commentedon Nov 18, 2026
Hi Rich Chiodo (@rchiodo). I have now run this through the debugger itself, in two setups, and the debug terminal is lost with pwsh in both. One of the setups is the reporter's own environment: VS Code connected to a WSL Ubuntu instance, with pwsh as the default terminal profile inside WSL.
TLDR: Through the real debugger, pwsh lost the debug terminal in 9 of 9 connected launches (4 on Windows with WSL, 5 on native Linux), always within about a second of the session ending. Bash kept it in 9 of 9. On Linux the close event shows pwsh itself exiting cleanly (code 0, reason Process). The reporter's crash text did not appear in either setup, and shell integration on or off makes no difference.
Summary (connected launches only)
Notes:
Environments
Steps: set pwsh as the default terminal profile (in the WSL window for the first setup), debug a short Python file with
"console": "integratedTerminal", and let it run to the end of the file. Expected: the terminal stays open with the output, as with bash. Actual: the tab is gone within about a second of the session ending.Screenshots
Commands, timelines, and the launch config
runInTerminal command sent to the pwsh terminal (WSL log):
Same launch under bash:
Linux timeline, pwsh run to end (UTC):
WSL timeline, pwsh run to end (UTC):
Launch configuration used in both setups:
{ "type": "debugpy", "request": "launch", "program": "${workspaceFolder}/hello.py", "console": "integratedTerminal", "justMyCode": true }One question: is pwsh ending when the launcher command finishes expected from how the debug terminal is created, or does this look like the same failure as the reporter's crash, just without the crash in these setups? Happy to collect a trace or test a specific scenario if that helps.
rchiodo commentedon Nov 19, 2026
No, I don't believe pwsh exiting is expected. That's the whole bug. It's not clear what is causing the pwsh terminal to actually exit.
PCTEJA commentedon Nov 19, 2026
Thank u Rich Chiodo (@rchiodo) , for confirming. I will look more deep into the debug terminal.
PCTEJA commentedon Nov 19, 2026
Rich Chiodo (@rchiodo) I dug into the debug terminal, and I think I found what makes pwsh exit.
TLDR: Found the cause. debugpy makes the debuggee the terminal's foreground process group and never sets it back. bash reclaims it with job control, pwsh cannot, so pwsh's next prompt read fails with the reporter's exact crash. In isolation pwsh crashed 5 of 5 with that preexec, and survived every control, including 3 of 3 when the launcher restores the foreground before exiting.
This extension never creates or closes the terminal. It only passes the console setting on. VS Code core creates the debug terminal, and on session end it only frees it for reuse, it does not dispose it or send it anything.
The one place that changes who owns the terminal is in debugpy. In launcher/debuggee.py, spawn() runs the debuggee with a preexec that does os.setpgrp() and then os.tcsetpgrp() on /dev/tty, so the debuggee becomes the foreground process group of the terminal. Nothing in debugpy ever sets it back.
I tested that in isolation, with no VS Code and no debug session: a plain pwsh in a pty, running a small launcher that spawns a short Python child using that exact preexec, then exits with the child's code, the same shape as the debugpy launcher.
pwsh with that preexec: 5 of 5 runs printed the reporter's exact crash and never came back to a usable prompt: "Process terminated. Input/output error", FailFast, in System.ConsolePal.TryGetCursorPosition, inside EnterNestedPrompt. That is the text from the original screenshot, word for word.
Same child without the tcsetpgrp call: pwsh survived 2 of 2.
Same test in bash: bash survived 3 of 3, because bash does job control and takes the foreground back when the job ends. pwsh has no Unix job control, so once the debuggee group dies, pwsh is left in a background group and its next prompt read fails with that Input/output error.
If the launcher sets the foreground back to its own group before exiting: pwsh survived 3 of 3.
So my read is that the fix sits in the debugpy launcher, restoring the foreground group before it exits, rather than in this repo's command construction. Happy to open an issue in debugpy with the repro script, or to add the script here if you would rather keep it in one place.
rchiodo commentedon Nov 19, 2026
That does sound plausible. We should fix it in debugpy then. Does it do this on attach as well, or just spawn?
PCTEJA commentedon Nov 19, 2026
Thanks Rich Chiodo (@rchiodo), just spawn.
Attach does not go through the launcher spawn, so it never does the
tcsetpgrpcall.rchiodo commentedon Nov 19, 2026
I transferred the issue to debugpy as it should be fixed there.
PCTEJA commentedon Nov 19, 2026
Thanks Rich Chiodo (@rchiodo). Can I start working on the fix here?
rchiodo commentedon Nov 19, 2026
Yeah, please do.
PCTEJA commentedon Nov 19, 2026
I also sent you a connection request on LinkedIn. I’d be happy to stay in touch there if you’re open to it.
My LinkedIn: https://www.linkedin.com/in/tejapc/