Skip to content

Conversation

@anthonykim1
Copy link
Contributor

@anthonykim1 anthonykim1 commented Jan 12, 2026

Resolves: microsoft/vscode-python-environments#640
Coming from: microsoft/vscode-python-environments#1093 (comment)

From: microsoft/vscode-python-environments#1093 (comment)


I couldnt seem to repro ^C to show up on Python file run on Mac, but only on Windows.

This is happening because we have some extra polling happening before onCommandStarted event gets fired:

this._tryAdjustCommandStartMarkerScheduler = new RunOnceScheduler(() => this._tryAdjustCommandStartMarker(initialCommandStartMarker), AdjustCommandStartMarkerConstants.Interval);
Which is what leads to resetting the value of promptInputModel:

We need the promptInputModel's value to be empty and state to be not execute in order to not cause ^C upon executeCommand run:

if (shouldExecute && (!commandDetection || commandDetection.promptInputModel.value.length > 0)) {

So in that meantime before we clear the value of promptInput to empty string, the state will be execute and value of it will point to activation script. Which will lead to ^C.


Flow from env extension:
Send activate command -> wait for onDidEndShellExecution -> send file execution.

The ctrl^c came from second arrow.

@anthonykim1 anthonykim1 added this to the January 2026 milestone Jan 12, 2026
@anthonykim1 anthonykim1 self-assigned this Jan 12, 2026
Copilot AI review requested due to automatic review settings January 12, 2026 17:36
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for clearing the prompt input model's value when a command finishes executing. This change prevents the runCommand API from detecting leftover text from a previous command and unnecessarily sending a ^C interrupt signal.

Changes:

  • Added onCommandFinished event subscription to PromptInputModel to clear the input value after command completion
  • Updated the constructor and test setup to wire the new event handler
  • Added test coverage to verify the value is cleared when a command finishes

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
src/vs/platform/terminal/common/capabilities/commandDetection/promptInputModel.ts Added onCommandFinished event parameter and _handleCommandFinished method to clear prompt input value
src/vs/platform/terminal/common/capabilities/commandDetectionCapability.ts Updated PromptInputModel instantiation to pass onCommandFinished event
src/vs/platform/terminal/test/common/capabilities/commandDetection/promptInputModel.test.ts Added test setup for onCommandFinished emitter and test case to verify value clearing behavior

private _handleCommandFinished() {
// Clear the prompt input value when command finishes to prepare for the next command
// This prevents runCommand from detecting leftover text and sending ^C unnecessarily
this._value = '';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if it will be good idea to fire an empty _onDidChangeInput here, because we havent started the "new" input yet.

Copy link
Member

Choose a reason for hiding this comment

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

Since we're changing the value, let's fire it to be consistent and see if there are any problems.

@anthonykim1 anthonykim1 marked this pull request as ready for review January 12, 2026 19:33
@anthonykim1 anthonykim1 marked this pull request as draft January 12, 2026 19:33
@anthonykim1 anthonykim1 requested a review from Tyriar January 12, 2026 19:34
@anthonykim1 anthonykim1 marked this pull request as ready for review January 12, 2026 19:34
@anthonykim1 anthonykim1 marked this pull request as draft January 13, 2026 18:13
@anthonykim1 anthonykim1 marked this pull request as ready for review January 13, 2026 23:37
@anthonykim1 anthonykim1 merged commit ace789b into main Jan 14, 2026
49 checks passed
@anthonykim1 anthonykim1 deleted the anthonykim1/clearCommandOnCommandFinished branch January 14, 2026 19:29
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.

CTRL-C is immediately issued upon run, execution gets cancelled by activation command

3 participants