Skip to content

Provide Assistant with the ability to cancel pending code - #17230

Open
jmcphers wants to merge 3 commits into
mainfrom
feature/cancel-pending-execution
Open

jmcphers wants to merge 3 commits into
mainfrom
feature/cancel-pending-execution

Conversation

@jmcphers

Copy link
Copy Markdown
Collaborator

Fixes #16089

Summary

When an extension runs code in a console that is already busy, the code waits in the console's queue. Until now, cancelling that execution did nothing while it was queued: the extension kept waiting for a result that might never come (for example, behind a running Shiny app), and the queued code still ran later once the console was free.

This PR lets an extension cancel a queued execution through the cancellation token it passes to positron.runtime.executeCode:

  • If the code is still queued, it is removed from the console queue and never runs. The execution promise rejects with a cancellation error, so the caller is no longer stuck.
  • If the code is already running, the session is interrupted as before.
  • The code that was already running (usually the user's own) is left alone.
  • If the queued code turned out to be incomplete and was moved into the console input for the user to finish, cancelling detaches it from the extension but leaves the user's input in place.

This is motivated by Assistant, whose Stop button now actually stops queued code. But the fix is in the core execution API, so it helps any extension that runs code in the console and passes a cancellation token.

Release Notes

New Features

  • N/A

Bug Fixes

Validation Steps

@:console @:assistant

  1. In an R console, run Sys.sleep(60) (or start a Shiny app).
  2. While it is running, ask Assistant to run some R code in the console. The code shows up as pending in the console.
  3. Click Stop in the chat pane.
  4. Verify the pending code disappears from the console, Assistant stops waiting right away, and Sys.sleep(60) keeps running.
  5. When Sys.sleep(60) finishes, verify Assistant's code does not run.

Unit tests cover the queue removal in the console service and the cancellation flow in the extension host.

@jmcphers
jmcphers requested a review from seeM November 10, 2026 01:06
@github-actions

Copy link
Copy Markdown
Contributor

E2E Tests 🚀
This PR will run tests tagged with: @:critical @:console @:assistant

Why these tags?
Tag Source
@:critical Always runs (required)
@:console PR description
@:assistant PR description

More on automatic tags from changed files.

Test count: Linux: 201 tests across 2 shards.

readme  valid tags

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.

Assistant: Pending console executions can't be stopped

1 participant