Skip to content

agentHost: fix background subagent lifecycle and recipient labels - #337620

Merged
Justin Chen (justschen) merged 8 commits into
mainfrom
agents/investigate-persistent-issue-fixes
Sep 24, 2026
Merged

Justin Chen (justschen) merged 8 commits into
mainfrom
agents/investigate-persistent-issue-fixes

Conversation

@justschen

@justschen Justin Chen (justschen) commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #337339
Refs #335292

Summary

  • Preserve reusable child routing when a parent turn is cancelled, while keeping final chat/session disposal destructive and scoped to the correct parent.
  • Retire execution-scoped Copilot child state through the existing completion cleanup so reuse works without a child-completed event and cannot inherit cancelled usage or Auto routing.
  • Settle orphaned approvals rather than buffering indefinitely. Bound startup buffers to 1,000 signals or 30 seconds, keep failed-route suppression in a separate 1,000-entry LRU, and surface failed routing on the active parent. Correctly routed, displayed approvals are not timed out.
  • Preserve reordered child signals when a background launch returns before child startup.
  • Restore normal inline subagent pills with live observation: resumed activity, new tools and approvals stay attached to the original parent response after reopening the chat. Adopt existing tool snapshots without duplication and keep settled child history lazy until activity resumes.
  • Show readable write-agent recipient names, including multi-recipient writes. Reuse names from lifecycle events, completion notifications and runtime task metadata in live/restored chats. Preserve raw routing IDs and the unknown-ID fallback.

The optional Subagents summary above the prompt and approval policy are unchanged.

Why

Parent cancellation removed the host's routing identity while the SDK retained the reusable agent, stranding later progress and approvals. Restored inline pills also did not reactivate idle children or append newly emitted tools. The recipient-name lookup only learned names from start events, and multi-recipient writes had no targeted display label.

Focused regressions reproduced these failures before the corresponding fixes. The inline change targets the restored/reused cases of #335292 rather than introducing another surface.

Live Copilot / AHP validation

Built with npm run build-fast and launched through ./scripts/code.sh on macOS arm64 using Code OSS 1.140.0 dev, the real Copilot harness, GPT-5.4 mini, and AHP 0.9.0. No model or protocol responses were mocked.

  • Created Label Alpha and Label Beta using task with mode: "background".
  • Verified Write to agent Label Alpha and Write to agents Label Alpha, Label Beta in both AHP ready/completed actions and the rendered accessible chat buttons.
  • Verified write arguments still contain the exact SDK-generated IDs.
  • Verified readable labels and both ordinary inline subagent links remain correct after renderer reload.
  • The inline pill's Validate Alpha label is the task description of the background agent named Label Alpha; this was not a foreground-only test.

Screenshot caption: Real background agents shown as ordinary inline subagent pills, with readable single- and multi-recipient write labels.

Automated validation

  • Core lifecycle follow-up: 909 host/provider tests and 242 focused Chromium history/rendering/reconnect tests passed after syncing main.
  • Recipient-label update: 880 focused display, history-mapper and provider tests passed. These counts overlap and should not be summed.
  • Current development build, changed-file ESLint, commit hygiene and git diff --check passed.
  • The latest full client type-check reports two existing SinonFakeTimersConfig errors in unchanged MCP/sticky-scroll test files; no changed-file diagnostics.
  • Earlier CI failures were stabilized with a test-only pet-frame assertion matching elapsed-time frame skipping and the existing deferPaint option on the MCP provenance fixture. Code OSS and Component Fixtures passed at 68b72bf3de1; CI for the new recipient-label commit is pending.

Validation limits

The successful live scenario was submitted through the normal authenticated AHP endpoint and verified in the actual rendered window. An additional direct UI-send attempt was blocked by GitHub Copilot sign-in in the cloned test profile. Renderer reload was tested, not an Agent Host process restart. Notification-only name recovery is covered by automated tests.

This PR remains a draft.

Preserve reusable child routing on cancellation and settle unroutable approval requests instead of buffering indefinitely. Restore live inline subagent observations across history hydration, including reused turns and new tool approvals.

Fixes #337339. Refs #335292.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings September 24, 2026 04:46

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

Two moderate cleanup issues can retain stale child state and accumulate failed routing markers indefinitely.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 2 Medium severity

Open (2)
What changed in this PR

Fixes background subagent reuse after cancellation and restores live inline progress when reopening chats.

Changes:

  • Preserves reusable child routing while cleaning up execution state.
  • Bounds orphaned startup signals and settles approvals.
  • Restores live inline child tools, approvals, and resumed activity.
File Review
src/​vs/​workbench/​contrib/​chat/​test/​browser/​agentSessions/​agentHostChatContribution.test.ts Tests restored inline child activity and tools.
src/​vs/​workbench/​contrib/​chat/​browser/​agentSessions/​agentHost/​agentHostSessionHandler.ts Restores live subagent observation and snapshot adoption.
src/​vs/​platform/​agentHost/​test/​node/​copilotAgentSession.test.ts Tests child reuse after cancellation.
src/​vs/​platform/​agentHost/​test/​node/​agentSideEffects.test.ts Tests routing, buffering, approvals, and cleanup.
src/​vs/​platform/​agentHost/​node/​copilot/​copilotAgentSession.ts Moderate (2 votes): Abort cleanup bypasses _completeSubagentTurn, retaining stale usage, model, and routing state that may be republished on reuse.
src/​vs/​platform/​agentHost/​node/​agentSideEffects.ts Moderate (2 votes): Failed pending-buffer markers remain indefinitely, allowing unbounded map growth across unique orphan routes.

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

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

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Screenshot Changes

Base: 80ef4c61 Current: 4b39c19b

Changed (2)

chat/aiCustomizations/aiCustomizationManagementEditor/McpServersProvenance/Dark
Before After
before after
chat/aiCustomizations/aiCustomizationManagementEditor/McpServersProvenance/Light
Before After
before after

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

Retire cancelled child execution state through the existing completion cleanup so reuse cannot inherit usage or Auto routing. Bound failed routing suppression separately and release disposed signal buffers immediately.

Add regression coverage for cancelled usage, late completion, failed-route eviction, scoped cleanup, and reentrant permission denial.

Addresses review feedback on #337620.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Accept the CI-generated light-theme baseline for the MCP provenance fixture. The recorded difference is limited to insignificant border antialiasing.

Refs #337620.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Bring in the upstream pet transition test that is failing on the PR merge before applying the focused CI stabilization.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The sprite player advances from elapsed time, so busy CI runners can legitimately skip intermediate frames. Verify both phase endpoints and reverse/forward ordering while retaining geometry, visibility, landing and focus assertions.

Refs #337620.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Defer painting until the fixture is ready to avoid intermediate-paint antialiasing noise, and restore the latest CI baseline. Repeated targeted captures were stable in both themes.

Refs #337620.

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

Justin Chen (justschen) commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator Author

Addressed both selected review threads in e7fb135 (cancelled-child accounting cleanup and bounded failed-route suppression); both are resolved.

Follow-up CI stabilization is pushed through 68b72bf:

  • The inherited ChatPetWidget teleport test passed on an isolated rerun, then failed on all three platforms by skipping different intermediate sprite frames. Synced main and changed only the test to require exact phase endpoints and correct reverse/forward ordering, matching the production elapsed-time frame-skipping contract. Position, visibility, landing and focus checks are unchanged. Full pet suite: 97 passing; targeted teleport test: 10/10 repeated passes.
  • The MCP provenance Light baseline oscillated between two images differing by eight antialiasing pixels (maximum channel delta 1). Rather than continue flipping hashes, enabled the existing deferPaint fixture option and restored the CI baseline. Three independent local captures per theme were byte-identical, with no render errors. There is no net baseline change versus current main.

Post-sync subagent validation: 909 host/provider tests and 242 focused browser tests passed; changed-file lint and commit hygiene passed.

Fresh CI is green for both repaired failures:

Resolve agent names from lifecycle events, completion notifications and runtime task metadata in live and restored chats. Name each recipient for multi-agent writes while preserving raw routing IDs and the existing unknown-ID fallback.

Validated with 880 focused tests and a live Code OSS/AHP scenario covering single-recipient writes, broadcasts and renderer reload.

Refs #337620.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@justschen Justin Chen (justschen) changed the title agentHost: fix background subagent reuse and inline progress agentHost: fix background subagent lifecycle and recipient labels Sep 24, 2026
Keep upstream's redesigned fixture CI gating while retaining deferred painting. Preserve the subagent lifecycle and readable recipient-label changes against current upstream.

Validated with client transpilation, 1,314 focused Electron tests, and targeted ESLint.

Refs #337620.

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

Copy link
Copy Markdown
Collaborator Author

Resolved the merge conflict and pushed signed merge commit 6600c55. Kept upstream’s redesigned MCP fixture gating (blocksCi: false) while retaining deferred painting; the subagent lifecycle and readable recipient-label changes remain intact. GitHub now reports MERGEABLE and new CI runs have started.

Validation: client transpilation, 1,314 focused Electron tests, targeted ESLint, and commit hygiene passed. The full client type-check still reports only the two previously noted unrelated SinonFakeTimersConfig errors in unchanged test files.

@justschen
Justin Chen (justschen) marked this pull request as ready for review September 24, 2026 19:44
@justschen
Justin Chen (justschen) merged commit d86a5bc into main Sep 24, 2026
75 of 77 checks passed
@justschen
Justin Chen (justschen) deleted the agents/investigate-persistent-issue-fixes branch September 24, 2026 19:48
@vs-code-engineering vs-code-engineering Bot added this to the 1.140.0 milestone Sep 24, 2026
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.

Agent Host: reused background subagent approval is orphaned after parent cancellation, leaving chat at Analyzing

3 participants