Skip to content

agentHost: Fix sessions stuck in progress after subagent completion - #334781

Merged
Benjamin Christopher Simmonds (benibenj) merged 2 commits into
mainfrom
benibenj/agents/fix-session-status-regression
Sep 6, 2026
Merged

agentHost: Fix sessions stuck in progress after subagent completion#334781
Benjamin Christopher Simmonds (benibenj) merged 2 commits into
mainfrom
benibenj/agents/fix-session-status-regression

Conversation

@benibenj

Copy link
Copy Markdown
Contributor

Summary

Fix completed Copilot Agent Host sessions remaining In Progress in the Agents window after a subagent follow-up finishes.

The observed SDK sequence supplies the subagent ID in hook.start.data.input.agentId for a subagentStop hook, but omits it from the hook.end envelope. Our handler only completed subagents from agentStop events with an envelope agent ID, leaving the follow-up turn active. #333999 made that stale child status visible on the parent session row.

Fix

  • Remember the subagent ID by hookInvocationId until the matching stop hook ends.
  • Reuse the existing subagent completion path and remove the correlation immediately.
  • Keep the sessions-list behavior unchanged; no polling, timeouts, or forced UI status.
  • Cover follow-up completion without an envelope agent ID, overlapping hooks, and duplicate completions that must not close a later turn.

Validation

  • Both new regression tests failed before the fix.
  • All 430 tests in copilotAgentSession.test.ts passed afterward.
  • npm run transpile-client
  • Targeted ESLint and staged hygiene (npm run precommit)
  • git diff --check

Release cherry-pick requested via ~release-cherry-pick.

Match subagent stop hooks by invocation ID when the SDK provides the agent identity only in the start event input. Reuse the existing completion path so finished follow-up turns do not keep the session in progress.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings September 6, 2026 08:51
@benibenj Benjamin Christopher Simmonds (benibenj) added the ~release-cherry-pick Trigger: cherry-pick this PR to the latest release branch label Sep 6, 2026
@vs-code-engineering

Copy link
Copy Markdown
Contributor

This PR will be automatically cherry-picked to release/1.136 when merged.

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 handles the reported event sequence and includes appropriate regression coverage.

Review tier: Balanced
Findings: None

What changed in this PR

Fixes stale In Progress state by correlating subagent stop hook events.

Changes:

  • Tracks subagent IDs across matching stop hooks.
  • Completes resumed subagent turns without envelope IDs.
  • Adds regression coverage for overlapping and duplicate events.
File Description
copilotAgentSession.ts Correlates stop hooks and completes subagent turns.
copilotAgentSession.test.ts Tests missing IDs, overlapping hooks, and duplicates.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Fix the Compile & Hygiene failure by checking that SDK hook input is a non-null, non-array object before reading agentId. Cover missing, primitive, array, and non-string inputs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@benibenj
Benjamin Christopher Simmonds (benibenj) merged commit 814ab13 into main Sep 6, 2026
50 of 51 checks passed
@benibenj
Benjamin Christopher Simmonds (benibenj) deleted the benibenj/agents/fix-session-status-regression branch September 6, 2026 10:04
@vs-code-engineering vs-code-engineering Bot added this to the 1.136.2 milestone Sep 6, 2026
@vs-code-engineering vs-code-engineering Bot added release-cherry-pick Automated cherry-pick between release and main branches and removed ~release-cherry-pick Trigger: cherry-pick this PR to the latest release branch labels Sep 6, 2026
@benibenj Benjamin Christopher Simmonds (benibenj) added ~release-cherry-pick Trigger: cherry-pick this PR to the latest release branch and removed release-cherry-pick Automated cherry-pick between release and main branches ~release-cherry-pick Trigger: cherry-pick this PR to the latest release branch labels Sep 6, 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.

3 participants