Skip to content

Offer Stop for copilot detached background shells - #341310

Merged
Anthony Kim (anthonykim1) merged 4 commits into
mainfrom
anthonykim1/stop-detached-shell
Oct 13, 2026
Merged

Anthony Kim (anthonykim1) merged 4 commits into
mainfrom
anthonykim1/stop-detached-shell

Conversation

@anthonykim1

@anthonykim1 Anthony Kim (anthonykim1) commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Resolves: #341329

Follows #340097. Replaces #340514, which was stacked on #340097 and conflicts now that it has merged.

  • Offer Stop Shell for detached background shells as well as attached ones.
  • Mark a detached shell stoppable when session.rpc.tasks.list reports its process ID (TaskShellInfo.pid). A detached shell started in the session always has one. Only a detached shell restored without a recorded ID lacks one, and session.rpc.tasks.cancel can't stop it, so the button stays hidden there.
  • Show a shell without live output, such as a detached one, with the same card as a shell with output: the command, its running status, and Stop in the card's action bar, without the terminal.
  • Stop repeating the elapsed time, shell ID, and start time as text in those details. The row's badge and description keep them, as they already did for shells with output.
  • Color Stop Shell red in both the editor window and the Agents window. It had been red only in the editor window, through the debug feature's theme rule. The Agents window doesn't load the debug feature, so the rule falls back to errorForeground there, which shares debugIcon.stopForeground's defaults.
  • Reuse the stop path from Add Stop for attached background shells in Agent Host chats #340097 unchanged: the vscode/stopBackgroundWork request and the SDK's session.rpc.tasks.cancel.
  • Needs no new SDK API. A detached shell never holds session.idle, so stopping one doesn't affect the turn.
How to test

Use a local Agent Host Copilot session with chat.agentHost.customTerminalTool.enabled set to false.

  1. Ask Copilot: "Use your shell tool to run for i in $(seq 1 300); do echo tick $i; sleep 1; done in async mode with detach set to true. Don't read its output."
  2. Open the Background Shells pill. The row is marked Detached. Its details show the command card with the running status and a red Stop Shell, and no terminal.
  3. Select Stop Shell. The shell leaves the list, its process exits, and no new turn starts.
  4. Attached shells still show the card above their live output, as in Add Stop for attached background shells in Agent Host chats #340097.
  5. Repeat in the Agents window. Stop Shell is red there too.

Ran locally:

  • npm run transpile-client: passed.
  • npm run test-node -- --run src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts: 1038 passing. With the copilotAgentSession.ts change reverted, the two updated tests fail.
  • ./scripts/test.sh --run src/vs/workbench/contrib/chat/test/browser/sessionBackgroundShellsControl.test.ts --run src/vs/workbench/contrib/chat/test/browser/accessibility/chatBackgroundShellOutputAccessibleView.test.ts --run src/vs/workbench/contrib/chat/test/browser/accessibility/chatAccessibilityHelp.test.ts --run src/vs/workbench/contrib/chat/test/browser/agentHost/agentHostSessionInputPills.test.ts: 96 passing. Against the previous details code, three of the updated control tests fail.
  • npm run eslint on the changed TypeScript files and npm run stylelint on the changed CSS: passed.
  • The Stop color, checked in the running editor window with the new rule placed first in the cascade: it resolves to debugIcon.stopForeground when that variable is defined, and to errorForeground when it isn't, as in the Agents window.
  • npm run typecheck-client: no errors in the changed files. The errors it does report are all in Electron main-process files, from other outdated packages in my local install.
  • A script against the public SDK started a detached sleep shell, using my local @github/copilot-sdk 1.0.17-preview.5 install and the binary it bundles:
    • session.rpc.tasks.list reported the shell with attachmentMode: "detached" and a pid, and session.idle arrived before any cancel.
    • session.rpc.tasks.cancel returned { cancelled: true }, the task became cancelled, and the process exited within about 130 ms.
  • Code OSS from this branch starts with @github/copilot-sdk 1.0.20-preview.2, the version main pins, and no Agent Host errors. I haven't driven the Stop flow end to end myself.

Inspirations from:

Detached shells now show the same Stop Shell button as attached ones,
but only when the SDK's `tasks.list` reports the shell's process ID.
Without one `tasks.cancel` has no process to stop, so the button stays
hidden.
Copilot AI balanced review requested due to automatic review settings October 13, 2026 15:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The implementation is narrowly scoped, consistent with the existing cancellation path, and adequately tested.

0 open findings

What changed in this PR

Extends Agent Host background-shell cancellation to detached shells when the runtime provides a process ID.

Changes:

  • Marks eligible detached shells as stoppable.
  • Tests detached shells with and without process IDs.
  • Updates Agent Host documentation.
File Description
src/​vs/​platform/​agentHost/​node/​copilot/​copilotAgentSession.ts Enables stopping detached shells with known PIDs.
src/​vs/​platform/​agentHost/​test/​node/​copilotAgentSession.test.ts Covers publication and cancellation behavior.
src/​vs/​platform/​agentHost/​AGENTS.md Documents detached-shell stopping semantics.

🧠 Review effort: Balanced


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Background shells without live output, such as detached ones, now show
the same card as shells with output: the command, its running status,
and Stop in the card's action bar. The terminal appears only when output
is available. The details no longer repeat the elapsed time, shell ID,
and start time as text; the row's badge and description keep them, as
they already did for shells with output.
@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Base: d93a3848 Current: d9fd11d9

No screenshot changes.

@anthonykim1 Anthony Kim (anthonykim1) changed the title Offer Stop for detached background shells in Agent Host chats Offer Stop for copilot detached background shells Oct 13, 2026
@anthonykim1
Anthony Kim (anthonykim1) marked this pull request as ready for review October 13, 2026 16:42
@anthonykim1 Anthony Kim (anthonykim1) added this to the 1.143.0 milestone Oct 13, 2026
@anthonykim1
Anthony Kim (anthonykim1) merged commit 18ab3d9 into main Oct 13, 2026
35 checks passed
@anthonykim1
Anthony Kim (anthonykim1) deleted the anthonykim1/stop-detached-shell branch October 13, 2026 17:08
Don Jayamanne (DonJayamanne) added a commit that referenced this pull request Oct 13, 2026
…xploration-vscode

* origin/main: (40 commits)
  MSRC fixes (#341342)
  chat: render input attachments for the input model's session (#341350)
  chat: center subagent tool activity hooks (#341258)
  Manage Copilot plugin marketplaces through Agent Host (#341301)
  fix: linux setuid sandbox helper permissions (#341292)
  agentHost: resolve #chat chips on the host of the chat that shows them (#341332)
  [Perf] agentHost: limit archived sessions over Mission Control (#341327)
  Remember expanded state for "Other Models" in model picker (#341335)
  Offer Stop for copilot detached background shells  (#341310)
  agentHost: allow inherited peer chats to move workspaces (#341317)
  [Perf] agentHost: reduce Mission Control relay overhead (#341223)
  Fix Customizations modal spacing (#341144)
  Fix dependency cycle in QuickInputService and EditorResolverService (#341321)
  Fix Explorer refresh on restoring deleted workspace root folder (#341323)
  chat: Share and rate-limit core utility model requests (#340100)
  agentHost: open #chat chips on the connection that owns the chat (#341313)
  Fix flaky StorageMainService tests by awaiting storage warm-up (#341305)
  agentHost: record the default chat role instead of reading the default chat URI shape (#341293)
  welcome: preserve tab icon color with Modern Icons
  Fix flaky test in diskFileSystemProvider.test.ts (#341304)
  ...

# Conflicts:
#	src/vs/platform/agentHost/node/agentService.ts
#	src/vs/platform/agentHost/node/protocolServerHandler.ts
#	src/vs/platform/agentHost/test/node/protocolServerHandler.test.ts
#	src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostSessionHandler.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

Offer Stop for detached background shells in Agent Host chats

3 participants