Skip to content

Conversation

@hdcodedev
Copy link
Contributor

@hdcodedev hdcodedev commented Jan 17, 2026

Context

Fixes #2653

The "Kill Command" button would fail to terminate a process if the user had previously clicked "Proceed While Running". This occurred due to two issues:

  1. TerminalProcess.abort() checked isListening: The termination signal (\x03) was only sent if isListening was true. Clicking "Proceed While Running" calls continue(), which sets isListening to false.

  2. task.terminalProcess was cleared too early: When "Proceed While Running" is clicked, process.continue() emits a "continue" event which resolves the process promise. This triggered the finally block in executeCommandInTerminal() which set task.terminalProcess = undefined, making subsequent kill attempts do nothing.

Implementation

TerminalProcess.ts

  • Removed the if (this.isListening) check from abort(). The termination signal is now sent unconditionally.
  • Implemented safe dereferencing (terminalRef.deref()) to prevent crashes if the terminal has been garbage collected.

ExecuteCommandTool.ts

  • Added if (!runInBackground) check before clearing task.terminalProcess in the finally blocks.
  • This preserves the process reference for background processes, allowing the kill button to still access it.

Tests

  • Added unit test verifying abort() works after continue() is called.
  • Verified that sendText is called exactly once to avoid signal spamming.
  • Added safety test ensuring abort() doesn't throw if terminal is undefined.
  • Added vi.clearAllMocks() to beforeEach to ensure clean state between tests.

How to Test

  1. Start Kilo Code and ask it to run a long-running command that produces output:

    run ping -c 100 localhost

    Note: The "Proceed While Running" button only appears if the command produces visible output. Commands like sleep 60 (without echo) will not trigger the button.

  2. Click "Run" to approve the command.

  3. Wait for output to appear, then click "Proceed While Running".

  4. Click the ⊗ (kill) button next to the PID.

  5. Verify: The terminal process terminates successfully.

    • In a separate terminal, run: ps -p <PID> - should show no process

Demo

Before (Bug)

2653-bug.mp4

After (Fix)

2653-fix.mp4

@changeset-bot
Copy link

changeset-bot bot commented Jan 17, 2026

🦋 Changeset detected

Latest commit: 3d23a26

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
kilo-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@hdcodedev hdcodedev changed the title fix(terminal): allow killing detached processes fix(cli): allow killing detached processes Jan 18, 2026
@marius-kilocode
Copy link
Collaborator

marius-kilocode commented Jan 20, 2026

@hdcodedev I can't really reproduce this with the CLI. Do you have a better example todo so?

@marius-kilocode marius-kilocode self-requested a review January 20, 2026 12:52
@marius-kilocode marius-kilocode enabled auto-merge (squash) January 20, 2026 12:53
@hdcodedev
Copy link
Contributor Author

I'll test more today and update you with the results.

@hdcodedev hdcodedev marked this pull request as draft January 20, 2026 15:52
auto-merge was automatically disabled January 20, 2026 15:52

Pull request was converted to draft

@hdcodedev hdcodedev changed the title fix(cli): allow killing detached processes fix(extension): allow killing detached processes Jan 20, 2026
@hdcodedev hdcodedev marked this pull request as ready for review January 20, 2026 19:03
@hdcodedev
Copy link
Contributor Author

hdcodedev commented Jan 20, 2026

@marius-kilocode You're right, fix(cli) was misleading, I've renamed it to fix(extension).
The "Proceed While Running" button requires command output to appear, which is why sleep didn't trigger it. I've updated the PR description with:

  • Correct title (fix(extension))
  • Reliable reproduction steps (using ping)
  • Full fix details (we found a second root cause where the process ref was cleared too early)
  • Demo videos (Please check PR description)

Update: I verified this fix in the VS Code extension. I haven't checked if a similar issue affects the @kilocode/cli

// Listening state does not reflect process liveness.
const terminal = this.terminalRef.deref()
terminal?.terminal?.sendText("\x03")
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why this change is needed
When a user clicks “Proceed/Continue,” we intentionally stop listening to terminal output so the UI stays quiet. That sets isListening = false and removes the line listeners, but the process is still running.
The kill button calls abort(), and the old guard (if (isListening)) meant we never sent Ctrl‑C after Continue. That’s why the kill button looked like a no‑op.

What this fixes

We now send Ctrl‑C unconditionally on user‑initiated abort. Listening state is about UI streaming, not process liveness. This makes “Kill” work even after “Proceed/Continue,” which matches user intent and doesn’t affect normal execution.

// Don't clear if running in background - user may still want to kill it
if (!runInBackground) {
task.terminalProcess = undefined
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why keep task.terminalProcess when running in background

When the user clicks “Proceed/Continue,” we allow the command to keep running in the terminal. At that point the promise resolves and we enter finally, which used to clear task.terminalProcess.
That wiped the only handle the kill button uses, so later aborts did nothing even though the process was still alive.

By only clearing the reference when not running in background, we keep the handle around so the kill button can still terminate the process after “Proceed/Continue.”

Copy link
Collaborator

@kevinvandijk kevinvandijk left a comment

Choose a reason for hiding this comment

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

Lgtm! Thanks!

@kevinvandijk kevinvandijk merged commit fef31df into Kilo-Org:main Feb 12, 2026
20 of 21 checks passed
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.

Kill Command Button not able to kill

3 participants