Skip to content

Simplify background shell reconciliation - #339345

Draft
Anthony Kim (anthonykim1) wants to merge 3 commits into
mainfrom
anthonykim1/background-shell-reconciliation
Draft

Anthony Kim (anthonykim1) wants to merge 3 commits into
mainfrom
anthonykim1/background-shell-reconciliation

Conversation

@anthonykim1

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

Copy link
Copy Markdown
Contributor

Follow-up to #339220.

  • Replace shell task-read counters with a snapshot of shell IDs and their originating tool calls, captured before requesting the task list. Reconcile only the same executions, leaving shells started or replaced during the request untouched.
  • Keep the shared task-list request, SDK task types, and running/idle filtering in the session. The terminal helper reconciles captured executions synchronously, without owning the request or returning unrelated tasks.
  • Preserve reconciliation before the stale-publication guard. Superseded responses can still settle shells without publishing stale background work.
  • Move shell-helper completion handling before result-content construction, outside the PTY-rendering block.
  • Keep this to two implementation files and two test files. Synchronous helper tests cover shell-ID reuse and prior completion; gated session tests cover capture-before-read and running/idle filtering. No UI, SDK, protocol, or settings changes.

Validation

  • npm run transpile-client: passed.
  • npm run typecheck-client: passed.
  • ./scripts/test.sh --run src/vs/platform/agentHost/test/node/copilotNonPtyShellTerminals.test.ts --run src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts --reporter dot: 834 passing.
  • npx --no-install eslint src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts src/vs/platform/agentHost/node/copilot/copilotNonPtyShellTerminals.ts src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts src/vs/platform/agentHost/test/node/copilotNonPtyShellTerminals.test.ts: passed.

Manual smoke test (not run):

  1. In a Copilot Agent Host chat, start an attached async build or test command that emits incremental output. Verify the returned tool call and Background Shells details continue showing its output until completion.
  2. Repeat with read_bash waiting for completion. Verify the terminal exits with the reported exit code and the shell leaves the background list.

Inspirations from:

Replace task-read counters with captured shell execution identities, clarify reconciliation ordering, and cover pending-read races.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 2, 2026 18:11

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

🟢 Approval recommended

The focused implementation correctly handles the identified races and includes targeted regression coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Simplifies background shell reconciliation while preserving execution identity across asynchronous task reads.

Changes:

  • Replaces read counters with shell/tool-call snapshots.
  • Prevents stale reads from settling reused shell IDs.
  • Adds regression coverage for shell replacement and concurrent completion.
File Description
copilotAgentSession.ts Captures and reconciles shell snapshots before stale-publication checks.
copilotNonPtyShellTerminals.ts Implements execution-aware snapshot reconciliation.
copilotNonPtyShellTerminals.test.ts Tests ID reuse and completion during pending reads.

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

@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Screenshot Changes

Base: 868a32d3 Current: 3e592fbb

Changed (2)

sessions/accountMenu/WeeklyAndFiveHourLimits/Light
Before After
before after
chat/aiCustomizations/aiCustomizationManagementEditor/DiscoverPluginsLoadingMore/Light
Before After
before after

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

Replace the public snapshot handshake with one operation that owns task-list reads, execution identity checks, and disposal. Exercise the async boundary with pending-read regression tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@anthonykim1 Anthony Kim (anthonykim1) left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Self-review at 73882d1. No regression found; the open question is the shape of the second commit.

  • The settle rule is unchanged: being in the map captured before the read is the same condition as the old "read started after the shell went to the background", and the toolCallId check covers shell-ID reuse.
  • Superseded reads still settle shells before the revision check.
  • Moving completeBackgroundShellFromHelperResult up is a no-op; only the construction of content sits between the old and new positions.
  • copilotNonPtyShellTerminals.test.ts and copilotAgentSession.test.ts at this commit: 836 passing.

Replacing the read counters with an identity snapshot (c1fd94f) is a real cleanup. Passing the task read through the shell class as a callback (73882d1) is the part to undo; details inline.

The description still describes the first commit's shape ("Name the running-shell set…") and says 832 passing.

Comment thread src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts Outdated
Comment thread src/vs/platform/agentHost/node/copilot/copilotNonPtyShellTerminals.ts Outdated
Comment thread src/vs/platform/agentHost/node/copilot/copilotNonPtyShellTerminals.ts Outdated
Comment thread src/vs/platform/agentHost/node/copilot/copilotNonPtyShellTerminals.ts Outdated
Comment thread src/vs/platform/agentHost/test/node/copilotNonPtyShellTerminals.test.ts Outdated
Restore synchronous shell reconciliation while preserving execution snapshots. Remove callback-only SDK coupling and tests, and cover read ordering and running/idle shells at the session boundary.

Addresses dependent review threads:
#339345 (comment)
#339345 (comment)
#339345 (comment)
#339345 (comment)
#339345 (comment)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

No deployments
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.

2 participants