Skip to content

Publish chat background work and show background shells above the chat input - #338723

Merged
Anthony Kim (anthonykim1) merged 22 commits into
mainfrom
anthonykim1/chat-background-work
Oct 1, 2026
Merged

Anthony Kim (anthonykim1) merged 22 commits into
mainfrom
anthonykim1/chat-background-work

Conversation

@anthonykim1

@anthonykim1 Anthony Kim (anthonykim1) commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Depends on: microsoft/agent-host-protocol#482
Replaces: #338713
Related: #336348, #337684

  • Publish Copilot's background work into AHP chat state with chat/backgroundWorkSet and chat/backgroundWorkRemoved: shells that keep running after their tool call returns (attached or detached), and running background subagents with their chat. Copilot only for now; Claude and Codex can follow.
  • Keep the list out of ChatSummary, so it isn't broadcast to every session subscriber. Both pills read ChatState.backgroundWork: the Agents window through the chat subscription it opens while the session is active, and the editor window from the chat it shows.
  • Read session.rpc.tasks.list() on session.background_tasks_changed and when a client starts watching the chat, and poll tasks.refresh() every 5 seconds while a watched chat has detached shells.
  • Keep the list independent of turns, reconcile it when a replacement session starts, and read again after an abort so finished shells don't linger.
  • Show shells in a new Background Shells pill above the chat input, in both the Agents window and the editor window, with elapsed time and the shell ID from _meta. Only detached shells carry a Detached label, so an unlabeled shell is attached, matching the GitHub app. Rows are keyed by the protocol id, and other kinds, subagents included, aren't shown yet.
  • Leave terminal unset until shell output streaming lands, and leave turn completion and Stop unchanged.
  • Sync the protocol with scripts/sync-agent-host-protocol.ts at dc9ff6b0, the head of Add background work to chat state for shells and subagents agent-host-protocol#482, so the two PRs can merge back to back. main already has chat: Add durable chat move and reorder contracts agent-host-protocol#484 from agentHost: Sync durable chat move and reorder protocol #339007, so the only protocol changes here are Run tests in Electron #482's background work. Once Run tests in Electron #482 merges, .ahp-version should point at its merged commit.

Still to do: clear a chat's background work when its session is disposed.

How to test:

  1. Ask Copilot to run sleep 120 with its shell tool in async mode.
  2. A 1 Background Shell pill appears above the input. Its details show the shell ID and elapsed time, with no Attached label.
  3. Ask for another sleep 120 with detach: true: the pill reads 2 Background Shells, and only the new row shows Detached.
  4. Send another message or press Stop: the shells stay listed until their commands exit. Repeat in an editor-window Agent Host chat.
Validation
  • After merging main in fa17532f: npm run typecheck-client, npm run valid-layers-check, and ESLint on the 37 changed .ts files passed. npm run test-node on the Agent Host session, service, state manager, and agent tests: 2022 passing; on the protocol server handler: 164 passing; on the Agent Host common tests: 931 passing. ./scripts/test.sh on the pill, accessibility help, and sessions provider tests: 584 passing. The full Copilot E2E suite passed in replay mode with main's Copilot SDK 1.0.16: 233 passing.
  • The protocol folder is synced from Add background work to chat state for shells and subagents agent-host-protocol#482 at dc9ff6b0; compared with main, it only adds background work types, actions, and reducer cases.

Inspirations from

Publish Copilot's running and waiting shells and running background subagents as AHP chat background work, and project the shells onto the Agents window's Background Shells pill.

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.

Copilot review overview

🟡 Changes recommended

The abort-refresh race and protocol projection issues can leave stale or misidentified background work.

Review effort: Balanced
Findings: 1 High severity · 1 Medium severity

Open (2)
What changed in this PR

Publishes chat-owned background work through AHP and presents active shells in the Agents window.

Changes:

  • Adds AHP background-work state, actions, reducers, metadata, and synchronization.
  • Watches Copilot tasks and publishes shells and subagents independently of turns.
  • Adds the Background Shells pill, live details, keyboard handling, accessibility help, and tests.
File Description
src/​vs/​platform/​actionWidget/​browser/​actionList.ts Supports activatable, bottom-aligned detail panels.
src/​vs/​platform/​actionWidget/​test/​browser/​actionList.test.ts Tests detail activation and layout.
src/​vs/​platform/​agentHost/​common/​agent.ts Adds the background-work watch contract.
src/​vs/​platform/​agentHost/​common/​meta/​copilotBackgroundWorkMeta.ts Reads and writes Copilot shell metadata.
src/​vs/​platform/​agentHost/​common/​state/​protocol/​action-origin.generated.ts Registers generated action origins.
src/​vs/​platform/​agentHost/​common/​state/​protocol/​channels-chat/​actions.ts Defines background-work actions.
src/​vs/​platform/​agentHost/​common/​state/​protocol/​channels-chat/​reducer.ts Reduces background-work updates.
src/​vs/​platform/​agentHost/​common/​state/​protocol/​channels-chat/​state.ts Defines background-work protocol state.
src/​vs/​platform/​agentHost/​common/​state/​protocol/​common/​actions.ts Exports the new action types.
src/​vs/​platform/​agentHost/​common/​state/​protocol/​version/​registry.ts Registers action protocol versions.
src/​vs/​platform/​agentHost/​common/​state/​sessionState.ts Projects background work between chat state and summaries.
src/​vs/​platform/​agentHost/​node/​agentHostStateManager.ts Mirrors background work into session catalogs.
src/​vs/​platform/​agentHost/​node/​agentService.ts Manages watches across chat subscribers.
src/​vs/​platform/​agentHost/​node/​copilot/​copilotAgent.ts Connects chat watches to live Copilot sessions.
src/​vs/​platform/​agentHost/​node/​copilot/​copilotAgentSession.ts Reconciles and publishes Copilot background tasks.
src/​vs/​platform/​agentHost/​test/​node/​agentHostStateManager.test.ts Tests catalog mirroring and turn independence.
src/​vs/​platform/​agentHost/​test/​node/​agentService.test.ts Tests subscriber watch lifecycle.
src/​vs/​platform/​agentHost/​test/​node/​copilotAgentSession.test.ts Tests task publication, refresh, and reconciliation.
src/​vs/​sessions/​contrib/​chat/​browser/​sessionBackgroundShellsControl.ts Builds shell pill rows and live details.
src/​vs/​sessions/​contrib/​chat/​browser/​sessionChatInputToolbar.ts Adds the shell source to Agents input pills.
src/​vs/​sessions/​contrib/​chat/​browser/​sessionsChatAccessibilityHelp.ts Documents shell picker accessibility.
src/​vs/​sessions/​contrib/​chat/​test/​browser/​sessionBackgroundShellsControl.test.ts Tests shell presentation and updates.
src/​vs/​sessions/​contrib/​providers/​agentHost/​browser/​baseAgentHostSessionsProvider.ts Projects AHP shells into Sessions state.
src/​vs/​sessions/​contrib/​providers/​agentHost/​test/​browser/​localAgentHostSessionsProvider.test.ts Tests per-chat shell projection.
src/​vs/​sessions/​services/​sessions/​common/​session.ts Adds provider-neutral shell state.
src/​vs/​workbench/​browser/​chatDropdownPill.ts Routes row activation to details.
src/​vs/​workbench/​contrib/​chat/​browser/​chatInputPills.ts Adds the standard shell pill source.
src/​vs/​workbench/​contrib/​chat/​browser/​sessionChatPillOptions.ts Defines shell pill labels and behavior.
src/​vs/​workbench/​contrib/​chat/​common/​sessionChatPills.ts Registers the shell pill kind.
src/​vs/​workbench/​contrib/​chat/​test/​browser/​chatInputPills.test.ts Tests shell pill visibility and placement.
src/​vs/​workbench/​contrib/​chat/​test/​common/​sessionChatPills.test.ts Tests shell visibility configuration.
src/​vs/​workbench/​test/​browser/​chatPills.test.ts Tests dropdown activation options.

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

Comment thread src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts
@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Screenshot Changes

Base: 4fefd4cb Current: 9aac8fe5

Changed (3)

sessions/connectionDiagnostics/connectionDiagnostics/DesktopDismissedDiscovery/Light
Before After
before after
chat/aiCustomizations/aiCustomizationManagementEditor/McpMigration/Light
Before After
before after
chat/aiCustomizations/aiCustomizationManagementEditor/DiscoverPluginsLoadingMore/Light
Before After
before after

2 insignificant change(s) omitted (≤20 px, Δ≤2). See CI logs for details.

Follow the protocol change that starts background work with shells only. The provider still skips kinds it doesn't render, since newer hosts can send more.
Follow the protocol change that drops status from background work. Every listed shell is unfinished, and Copilot never reports a shell as idle. The pill now shows the attached or detached mode and elapsed time.
The async shell is now published as background work from a separate task-list read, so its timing against the tool calls isn't part of this scenario.
@anthonykim1 Anthony Kim (anthonykim1) changed the title Publish chat background work and show background shells Publish chat background work and show background shells in the Agents window Sep 29, 2026
Follow the protocol change that removes the unused terminal field. Nothing in VS Code set or read it.
Move the Background Shells pill control and the background work projection into the workbench so the editor window's Agent Host chat input can show the same pill as the Agents window. Share the pill's accessibility help between both windows.
@anthonykim1 Anthony Kim (anthonykim1) changed the title Publish chat background work and show background shells in the Agents window Publish chat background work and show background shells above the chat input Sep 29, 2026
Addresses review feedback on stale shells after a client restart or crash. A session that replaced another started with an empty baseline, so shells the new runtime no longer reported stayed listed. The host now passes the chat's current background work when a watch attaches, and the session removes entries missing from its first read.
Addresses review feedback on the abort race. Aborting a turn bumped the task status revision without queuing a read, so a read in flight was discarded and the detached shell poll could stop for good, since detached shells report no exit on their own. The session now reads again once the abort settles.
Match microsoft/agent-host-protocol#482: background shells can link their terminal, and background subagents are their own kind that points at the subagent's chat. The Background Shells pill still shows shells only.
Running background agents are published with their chat. Idle ones have already reported back, so they're left out. Shells don't set a terminal yet; that waits for output streaming.
Addresses review thread #338723 (comment).
Rows used Copilot's shell ID from _meta as their identity, which the protocol doesn't guarantee is unique. Key rows by the entry id instead, and show Copilot's shell ID separately, only when the agent reports one.
Running background subagents are now published as background work. Those actions come from a separate task-list read, so their timing against the subagent's tool calls isn't part of this scenario, and CI's snapshot comparison failed on every platform. Ignore them here, as the read-shell scenario already does.
A failing local run left this .actual file next to the retained background subagent snapshot, and it was committed by mistake. Hygiene rejects it, and the test runner logs when it deletes it, which fails the no-console-output check.
Match microsoft/agent-host-protocol#482 at d513c6fb, which says background work lists only active work.
Keep both sides where main and this branch added to the same spots: main's chat canvases next to background shells in the sessions model and provider, main's canvas test next to the background shell projection test, and the combined imports. Take main's move of gitHubMcpServerUrl to platform/github.
@anthonykim1

Anthony Kim (anthonykim1) commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor Author
vscodeSample (Perhaps we dont show attached, but show detached when it's detached)? So if you dont see detached, it's attached (similar to github app).

@anthonykim1

Copy link
Copy Markdown
Contributor Author

Updated screenshot:

DemoShell Screenshot 2026-09-30 at 12 33 53 PM

@anthonykim1 Anthony Kim (anthonykim1) added this to the 1.141.0 milestone Sep 30, 2026
@anthonykim1
Anthony Kim (anthonykim1) marked this pull request as ready for review September 30, 2026 22:20
@vs-code-engineering

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

Sandeep Somavarapu (@sandy081)

Matched files:

  • src/vs/sessions/services/sessions/common/session.ts

Ladislau Szomoru (@lszomoru)

Matched files:

  • src/vs/sessions/services/sessions/common/session.ts

@anthonykim1
Anthony Kim (anthonykim1) marked this pull request as draft September 30, 2026 22:23
Attached is the common case, so an unlabeled shell reads as attached and only detached shells carry a label, matching the GitHub app.
Mirror modifiedAt alongside status, activity, and backgroundWork when forwarding a chat's summary to its session, and set both the default chat's background shells and its modified time.
Take agent-host-protocol at c53aef24, the head of #482 after merging main, so this PR and #482 can merge back to back. That also brings in chat move and reorder from #484: reject moveChat with InvalidParams, since clients may only move chats that advertise movable: true and this host never does.
@anthonykim1
Anthony Kim (anthonykim1) marked this pull request as ready for review September 30, 2026 22:52
@anthonykim1
Anthony Kim (anthonykim1) marked this pull request as draft September 30, 2026 23:08
Take agent-host-protocol at ab694bfd, the head of microsoft/agent-host-protocol#482. The only change is the shortened backgroundWork doc text from its review.
Take #339007's chat move and reorder sync, including its moveChat stub, and drop this branch's duplicate stub and test. Re-sync the protocol from agent-host-protocol ab694bfd, so the only protocol changes left on this branch are #482's background work.
@anthonykim1
Anthony Kim (anthonykim1) marked this pull request as ready for review October 1, 2026 00:23
@anthonykim1
Anthony Kim (anthonykim1) marked this pull request as draft October 1, 2026 00:42
microsoft/agent-host-protocol#482 dropped ChatSummary.backgroundWork, so
session subscribers no longer receive every chat's background work. The
Agents window pill now reads ChatState.backgroundWork through the active
session's chat subscription, like the editor window already did, and the
state manager no longer mirrors the list into chat summaries.

Syncs the protocol to microsoft/agent-host-protocol@dc9ff6b0.
@anthonykim1
Anthony Kim (anthonykim1) marked this pull request as ready for review October 1, 2026 03:06
roblourens
roblourens previously approved these changes Oct 1, 2026
@anthonykim1
Anthony Kim (anthonykim1) marked this pull request as draft October 1, 2026 14:54
Main now offers every pill kind in both windows through SESSION_CHAT_PILL_KINDS, which already includes Background Shells, so the editor window's offeredPillKinds list goes away and the background shells source sits next to main's new Subagents pill. Keep both sides' accessibility help, imports, and tests, and pass main's new ICommandService argument in the editor window's background shells test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants