Skip to content

Terminal shell integration events not firing #248019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Lachann opened this issue May 2, 2025 · 20 comments
Closed

Terminal shell integration events not firing #248019

Lachann opened this issue May 2, 2025 · 20 comments
Assignees

Comments

@Lachann
Copy link

Lachann commented May 2, 2025

Type: Bug

The onDidStartTerminalShellExecution and onDidEndTerminalShellExecution never fire at all in 1.99.3. It works fine in 1.98.2.

Here's a basic Hello World extension executing a terminal command, based on the example from API docs (https://code.visualstudio.com/api/references/vscode-api#TerminalShellIntegration):

// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode';

// This method is called when your extension is activated
// Your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {
	const logger = vscode.window.createOutputChannel("HW", { log: true });
    context.subscriptions.push(logger);

	// Use the console to output diagnostic information (console.log) and errors (console.error)
	// This line of code will only be executed once when your extension is activated
	console.log('Congratulations, your extension "helloworld" is now active!');

	// The command has been defined in the package.json file
	// Now provide the implementation of the command with registerCommand
	// The commandId parameter must match the command field in package.json
	const disposable = vscode.commands.registerCommand('helloworld.helloWorld', () => {
		// The code you place here will be executed every time your command is executed
		// Display a message box to the user
		vscode.window.showInformationMessage('Hello World from Helloworld!');

		logger.trace('Hello World from Helloworld!');

		// Execute a command in a terminal immediately after being created
		const myTerm = vscode.window.createTerminal();
		const handler = vscode.window.onDidChangeTerminalShellIntegration(async ({ terminal, shellIntegration }) => {
			logger.trace("onDidChangeTerminalShellIntegration", shellIntegration);
			if (terminal === myTerm) {
				handler.dispose();
				const execution = shellIntegration.executeCommand('echo "Hello world"');
				logger.trace("Execution started", execution);
				vscode.window.onDidStartTerminalShellExecution(event => {
					logger.trace("onDidStartTerminalShellExecution", event);
				});
				// Wait for the command to finish
				vscode.window.onDidEndTerminalShellExecution(event => {
					logger.trace("onDidEndTerminalShellExecution", event);
					if (event.execution === execution) {
						logger.trace(`Command exited with code ${event.exitCode}`);
					}
				});
			}
		});

	});

	context.subscriptions.push(disposable);
}

// This method is called when your extension is deactivated
export function deactivate() {}

Based on the debug output, the start/end events never fire at all:

2025-05-02 16:52:18.708 [trace] Hello World from Helloworld!
2025-05-02 16:52:19.256 [trace] onDidChangeTerminalShellIntegration {}
2025-05-02 16:52:19.256 [trace] Execution started {"commandLine":{"value":"echo \"Hello world\"","confidence":2,"isTrusted":true}}

Same on insiders.

On 1.98.2 it works as expected:

2025-05-02 16:49:51.119 [trace] Hello World from Helloworld!
2025-05-02 16:49:51.591 [trace] onDidChangeTerminalShellIntegration {}
2025-05-02 16:49:51.592 [trace] Execution started {"commandLine":{"value":"echo \"Hello world\"","confidence":2,"isTrusted":true}}
2025-05-02 16:49:51.592 [trace] onDidStartTerminalShellExecution {"terminal":{"name":"powershell","processId":{},"creationOptions":{},"state":{"isInteractedWith":false},"shellIntegration":{},"dimensions":{"columns":80,"rows":30}},"shellIntegration":{},"execution":{"commandLine":{"value":"echo \"Hello world\"","confidence":2,"isTrusted":true}}}
2025-05-02 16:49:51.670 [trace] onDidEndTerminalShellExecution {"terminal":{"name":"powershell","processId":{},"creationOptions":{},"state":{"isInteractedWith":true},"shellIntegration":{"cwd":{"$mid":1,"path":"/C:/Users/lachann/repos/rrs","scheme":"file"}},"dimensions":{"columns":80,"rows":30}},"shellIntegration":{"cwd":{"$mid":1,"path":"/C:/Users/lachann/repos/rrs","scheme":"file"}},"execution":{"commandLine":{"value":"","confidence":1,"isTrusted":false}},"exitCode":0}
2025-05-02 16:49:51.670 [trace] Command exited with code 0

VS Code version: Code 1.99.3 (17baf84, 2025-04-15T23:18:46.076Z)
OS version: Windows_NT x64 10.0.19045
Modes:

System Info
Item Value
CPUs AMD Ryzen 5 3600 6-Core Processor (8 x 3600)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off
Load (avg) undefined
Memory (System) 15.95GB (4.56GB free)
Process Argv --log monk.vscode-monk=trace --log undefined_publisher.helloworld=trace --crash-reporter-id 4e2a1a8f-8388-4dcc-8643-38d9cd1c5def
Screen Reader no
VM 33%
Extensions (10)
Extension Author (truncated) Version
esbuild-problem-matchers con 0.0.3
vscode-eslint dba 3.0.10
vscode-deno den 3.44.0
copilot Git 1.312.0
copilot-chat Git 0.26.7
vscode-mocha-test-adapter hbe 2.14.3
vscode-test-explorer hbe 2.22.1
remote-wsl ms- 0.99.0
test-adapter-converter ms- 0.2.1
vim vsc 1.29.0
A/B Experiments
vsliv368:30146709
vspor879:30202332
vspor708:30202333
vspor363:30204092
vscod805cf:30301675
binariesv615:30325510
vscaac:30438847
c4g48928:30535728
azure-dev_surveyone:30548225
962ge761:30959799
2e7ec940:31000449
pythontbext0:30879054
cppperfnew:31000557
dwnewjupyter:31046869
pythonrstrctxt:31112756
nativeloc1:31192215
5fd0e150:31155592
dwcopilot:31170013
6074i472:31201624
dwoutputs:31242946
customenabled:31248079
9064b325:31222308
copilot_t_ci:31222730
968h8231:31277804
pythoneinst12:31285622
bgtreat:31268568
4gafe986:31271826
31787653:31262186
3e8i5726:31271747
996jf627:31283433
usemplatestapi:31297334
7bj51361:31289155
aj496949:31278748
aj953862:31281341
generatesymbolt:31295002
convertfstringf:31295003
gendocf:31295004

@Lachann
Copy link
Author

Lachann commented May 2, 2025

The command itself is executed just fine btw, it's just that the event that it did finish is not sent.

@bhavyaus bhavyaus assigned meganrogge and unassigned Tyriar May 5, 2025
@meganrogge meganrogge added the info-needed Issue requires more information from poster label May 5, 2025
@meganrogge
Copy link
Contributor

Thanks for the info - If this is a confirmed regression, it would help to know which change caused it. We maintain a node.js based CLI tool vscode-bisect that automatically downloads and runs previous VS Code insiders and asks for each build if the issue reproduces. It takes up to 8 steps to find exactly the build that caused the regression.

Steps:

  • install node.js (if not yet done)
  • npx --yes @vscode/vscode-bisect@latest
  • follow the instructions until you found the offending build (its fine to leave the commit empty)
  • report back the commit range in this issue

Thanks!

@Lachann
Copy link
Author

Lachann commented May 5, 2025

C:\Users\lachann>npx --yes @vscode/vscode-bisect@latest
√ Commit or version of released insiders build that reproduces the issue (leave empty to pick the latest build) ...
√ Commit or version of released insiders build that does not reproduce the issue (leave empty to pick the oldest build) ...
[build] fetching all builds from https://update.code.visualstudio.com/api/commits/insider/win32-x64?released=false...
[build] total 170 builds with roughly 7 steps
[build] downloading build from https://vscode.download.prss.microsoft.com/dbazure/download/insider/757405278fac64ad3f5807f86042bc000c291920/VSCode-win32-x64-1.99.0-insider.zip...
[build] ✔︎ expected SHA256 checksum matches with download
[build] unzipping build to C:\Users\lachann\AppData\Local\Temp\vscode-bisect\.builds\757405\VSCode-win32-x64-1.99.0-insider...
[build] starting desktop build 757405278fac64ad3f5807f86042bc000c291920...
√ Is 757405278fac64ad3f5807f86042bc000c291920 good or bad? » Retry
[build] starting desktop build 757405278fac64ad3f5807f86042bc000c291920...
√ Is 757405278fac64ad3f5807f86042bc000c291920 good or bad? » Good
[build] downloading build from https://vscode.download.prss.microsoft.com/dbazure/download/insider/7dbf25d8427b59f519d04587e71a9d3dfb77224c/VSCode-win32-x64-1.100.0-insider.zip...
[build] ✔︎ expected SHA256 checksum matches with download
[build] unzipping build to C:\Users\lachann\AppData\Local\Temp\vscode-bisect\.builds\7dbf25\VSCode-win32-x64-1.100.0-insider...
[build] starting desktop build 7dbf25d8427b59f519d04587e71a9d3dfb77224c...
√ Is 7dbf25d8427b59f519d04587e71a9d3dfb77224c good or bad? » Bad
[build] downloading build from https://vscode.download.prss.microsoft.com/dbazure/download/insider/18c72eee2bbb04545817bbf25de2a42f7ad759ff/VSCode-win32-x64-1.100.0-insider.zip...
[build] ✔︎ expected SHA256 checksum matches with download
[build] unzipping build to C:\Users\lachann\AppData\Local\Temp\vscode-bisect\.builds\18c72e\VSCode-win32-x64-1.100.0-insider...
[build] starting desktop build 18c72eee2bbb04545817bbf25de2a42f7ad759ff...
√ Is 18c72eee2bbb04545817bbf25de2a42f7ad759ff good or bad? » Bad
[build] downloading build from https://vscode.download.prss.microsoft.com/dbazure/download/insider/87a35e10699cb846c2c72eeb3a698bf56dafd701/VSCode-win32-x64-1.99.0-insider.zip...
[build] ✔︎ expected SHA256 checksum matches with download
[build] unzipping build to C:\Users\lachann\AppData\Local\Temp\vscode-bisect\.builds\87a35e\VSCode-win32-x64-1.99.0-insider...
[build] starting desktop build 87a35e10699cb846c2c72eeb3a698bf56dafd701...
√ Is 87a35e10699cb846c2c72eeb3a698bf56dafd701 good or bad? » Bad
[build] downloading build from https://vscode.download.prss.microsoft.com/dbazure/download/insider/b87fa463df1aeec04bf1f56276cc9972bdb14124/VSCode-win32-x64-1.99.0-insider.zip...
[build] ✔︎ expected SHA256 checksum matches with download
[build] unzipping build to C:\Users\lachann\AppData\Local\Temp\vscode-bisect\.builds\b87fa4\VSCode-win32-x64-1.99.0-insider...
[build] starting desktop build b87fa463df1aeec04bf1f56276cc9972bdb14124...
√ Is b87fa463df1aeec04bf1f56276cc9972bdb14124 good or bad? » Good
[build] downloading build from https://vscode.download.prss.microsoft.com/dbazure/download/insider/b47e1fee9e4034b5a569d54f7765e4133bd3f7ed/VSCode-win32-x64-1.99.0-insider.zip...
[build] ✔︎ expected SHA256 checksum matches with download
[build] unzipping build to C:\Users\lachann\AppData\Local\Temp\vscode-bisect\.builds\b47e1f\VSCode-win32-x64-1.99.0-insider...
[build] starting desktop build b47e1fee9e4034b5a569d54f7765e4133bd3f7ed...
√ Is b47e1fee9e4034b5a569d54f7765e4133bd3f7ed good or bad? » Bad
[build] downloading build from https://vscode.download.prss.microsoft.com/dbazure/download/insider/dc289883be5d37d5d2b2f7d30926aa42a3123437/VSCode-win32-x64-1.99.0-insider.zip...
[build] ✔︎ expected SHA256 checksum matches with download
[build] unzipping build to C:\Users\lachann\AppData\Local\Temp\vscode-bisect\.builds\dc2898\VSCode-win32-x64-1.99.0-insider...
[build] starting desktop build dc289883be5d37d5d2b2f7d30926aa42a3123437...
√ Is dc289883be5d37d5d2b2f7d30926aa42a3123437 good or bad? » Bad
[build] starting desktop build b87fa463df1aeec04bf1f56276cc9972bdb14124...
√ Is b87fa463df1aeec04bf1f56276cc9972bdb14124 good or bad? » Good
[build] dc289883be5d37d5d2b2f7d30926aa42a3123437 is the first bad commit after b87fa463df1aeec04bf1f56276cc9972bdb14124.
√ Would you like to open GitHub for the list of changes? ... yes

Run the following commands to continue bisecting via git in a folder where VS Code is checked out to:

git bisect start && git bisect bad dc289883be5d37d5d2b2f7d30926aa42a3123437 && git bisect good b87fa463df1aeec04bf1f56276cc9972bdb14124

@Lachann
Copy link
Author

Lachann commented May 5, 2025

I guess maybe this? 2d24dfa
Or this? 2967810

@meganrogge
Copy link
Contributor

Thanks, I'm suspicious of this a10f30d in that commit range

b87fa46...dc28988

@meganrogge
Copy link
Contributor

which shell are you using?

@meganrogge meganrogge added bug Issue identified by VS Code Team member as probable bug regression Something that used to work is now broken and removed info-needed Issue requires more information from poster labels May 5, 2025
@meganrogge
Copy link
Contributor

Oh, I see pwsh in your logs

@Lachann
Copy link
Author

Lachann commented May 5, 2025

Yeah, powershell, I tried both with 5.1.19041.5737 as well as 7.5.1 from https://github.com/powershell/powershell/releases, same on both.

@meganrogge
Copy link
Contributor

@roblourens this could explain some peoples' issues with the chat agent terminals not working as expected

@meganrogge
Copy link
Contributor

Works on insider's when I use:

context.subscriptions.push(vscode.window.onDidEndTerminalShellExecution(async (e) => {
		console.log('Terminal shell execution ended: ', e.terminal.name);
	}));
	context.subscriptions.push(vscode.window.onDidStartTerminalShellExecution(async (e) => {
		console.log('Terminal shell execution started: ', e.terminal.name);
	}));

@meganrogge
Copy link
Contributor

I used pretty much your exact code and it's working for me in insider's.

Here's what I did in my extension's activate method:

const myTerm = vscode.window.createTerminal();
	const handler = vscode.window.onDidChangeTerminalShellIntegration(async ({ terminal, shellIntegration }) => {
		console.log('onDidChangeTerminalShellIntegration', shellIntegration);
		if (terminal === myTerm) {
			handler.dispose();
			const execution = shellIntegration.executeCommand('echo `Hello world`');
			console.log('Execution started', execution);
			vscode.window.onDidStartTerminalShellExecution(event => {
				console.log('onDidStartTerminalShellExecution', event);
			});
			// Wait for the command to finish
			vscode.window.onDidEndTerminalShellExecution(event => {
				console.log('onDidEndTerminalShellExecution', event);
				if (event.execution === execution) {
					console.log(`Command exited with code ${event.exitCode}`);
				}
			});
		}
	});
Image

@meganrogge meganrogge removed bug Issue identified by VS Code Team member as probable bug regression Something that used to work is now broken labels May 6, 2025
@meganrogge
Copy link
Contributor

I tried this on macOS, not sure why it would be different for windows, will try there too.

@meganrogge
Copy link
Contributor

see the events using the same code on windows, thus closing this.

Image

@Lachann
Copy link
Author

Lachann commented May 6, 2025

Not sure why it doesn't reproduce on your end, but it definitely seems to be caused by a10f30d: I found that file locally at <vscode-install-dir>\resources\app\out\vs\workbench\contrib\terminal\common\scripts and manually reverted the changes from that commit and that fixes it.

@Lachann
Copy link
Author

Lachann commented May 6, 2025

Did some debugging, looks like Get-Module -Name PSReadLine here

is false for me, thus $Global:__VSCodeIsInExecution is never set, and this
if ($Global:__LastHistoryId -ne -1 -and $Global:__VSCodeIsInExecution -eq $true) {
never executes.

@Lachann
Copy link
Author

Lachann commented May 6, 2025

Not an expert in powershell, but if I just open it and check for PSReadLine it looks like it's false unless I explicitly import it:

PS C:\Users\lachann>  if (Get-Module -Name PSReadLine) { echo "got readline" } else { echo "no readline" }
no readline
PS C:\Users\lachann> Import-Module PSReadLine
PS C:\Users\lachann>  if (Get-Module -Name PSReadLine) { echo "got readline" } else { echo "no readline" }
got readline

@meganrogge
Copy link
Contributor

Nice debugging, unless you use a screen reader, that should be enabled by default.

@Lachann
Copy link
Author

Lachann commented May 6, 2025

I don't, no idea why it behaves like that for me, or how widespread that might be for others. Gonna ask some colleagues with Windows to see how it works for them.

@Lachann
Copy link
Author

Lachann commented May 6, 2025

Hah, actually, it does think I'm using a screen reader:

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

Warning: PowerShell detected that you might be using a screen reader and has disabled PSReadLine for compatibility purposes. If you want to re-enable it, run 'Import-Module PSReadLine'.

PS C:\Users\lachann>

Never paid attention to that.

Wonder why it thinks that. But definitely something on my side then.

@Lachann
Copy link
Author

Lachann commented May 6, 2025

I had HKEY_CURRENT_USER\Control Panel\Accessibility\Blind Access\On set to 1 for some reason, turned it off and now it's all good.

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

No branches or pull requests

3 participants