Skip to content

Improve Copilot Cloud Sessions error handling and messaging#325196

Draft
osortega wants to merge 1 commit into
mainfrom
osortega/agents/copilot-cloud-sessions-v2-backend
Draft

Improve Copilot Cloud Sessions error handling and messaging#325196
osortega wants to merge 1 commit into
mainfrom
osortega/agents/copilot-cloud-sessions-v2-backend

Conversation

@osortega

@osortega osortega commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

This pull request enhances the error handling and messaging for the Copilot Cloud Sessions feature, specifically addressing how task states are communicated to users.

Changes Made:

  • Unified the error message format to Copilot stopped: <reason>, where <reason> is derived from the task state (e.g., "cancelled", "timed out", or specific error details).
  • Updated the formatTaskStoppedMessage function to reflect the new messaging format.
  • Cleaned up verbose diagnostic logging in the extractTaskErrorDetail function, removing unnecessary parameters and logs.
  • Restored assertions in the test for synthesizing a single turn that were accidentally removed in a previous edit.
  • Updated tests to match the new message format and ensure all scenarios are covered.

Rationale:

These changes improve user experience by providing clearer and more accurate feedback regarding task states, particularly distinguishing between cancellation and failure. The logging cleanup also enhances maintainability by reducing noise in the logs. All tests have been updated and pass successfully, ensuring the reliability of the new implementation.

Copilot AI review requested due to automatic review settings July 9, 2026 21:40

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.

Pull request overview

This PR improves error handling and messaging for the Copilot Cloud Sessions (Task API v2) feature. Previously, a task that terminally failed while its latest session state stayed in_progress/queued (e.g. "Failed to launch agent") would render a perpetual "Session is in progress…" spinner and cause the live streamer to poll forever. The change keys "is the task still running?" off the task-level state and surfaces a unified Copilot stopped: <reason> notice, where the reason is a concrete error detail when available, otherwise a state-derived word ("cancelled" / "timed out" / "an error occurred").

Changes:

  • Adds shared isActiveTaskState / isFailedTaskState helpers as the single source of truth for task-lifecycle state, replacing the local ACTIVE_STATES set in the streamer.
  • Introduces extractTaskErrorDetail and formatTaskStoppedMessage, and wires a terminal-stop notice into both the history builder and the live TaskTurnStreamer (with renderedError de-duplication).
  • Gates activeResponseCallback on the task-level active state so terminally-failed tasks don't stream/poll forever; updates and expands tests.
Show a summary per file
File Description
extensions/copilot/src/extension/chatSessions/vscode/copilotCodingAgentUtils.ts Adds isActiveTaskState/isFailedTaskState shared helpers for task-state classification.
extensions/copilot/src/extension/chatSessions/vscode-node/copilotCloudSessionContentBuilder.ts Adds extractTaskErrorDetail/formatTaskStoppedMessage; renders a stop notice instead of a stuck spinner in history.
extensions/copilot/src/extension/chatSessions/vscode-node/taskTurnStreamer.ts Settles the live stream on terminal task state and emits the stop notice; tracks renderedError to avoid duplicate detail.
extensions/copilot/src/extension/chatSessions/vscode-node/copilotCloudSessionsProvider.ts Gates the active-response streaming callback on isActiveTaskState(task.state).
extensions/copilot/src/extension/chatSessions/vscode-node/test/copilotCloudSessionsProvider.spec.ts Adds/updates tests for the new stopped-notice behavior and helper functions.

Review details

  • Files reviewed: 5/5 changed files
  • Comments generated: 2
  • Review effort level: Medium

Comment on lines +294 to +304
// Only the latest turn can still be in-progress. When the task itself terminally
// failed, surface a failure notice (with any available error detail) instead of a
// stuck progress spinner — the latest session state can still read as active (e.g.
// "Failed to launch agent"). Detail is extracted from the full event list because a
// bootstrap `session.error` is suppressed from the rendered turns above.
// Only the latest turn can still be in-progress. When the task terminally stopped,
// surface a "Copilot stopped: <reason>" notice instead of a stuck progress spinner —
// the latest session state can still read as active (e.g. "Failed to launch agent"
// or a cancelled turn). Detail is extracted from the full event list because a
// bootstrap `session.error` is suppressed from the rendered turns above; a cancelled
// or timed-out task emits no error event, so the reason falls back to the task state.
Comment on lines +20 to +31
switch (state) {
case 'queued':
case 'in_progress':
case 'idle':
case 'waiting_for_user':
return true;
case 'completed':
case 'failed':
case 'timed_out':
case 'cancelled':
return false;
}
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