Skip to content

[BUG] Prevent inconsistent CommandResponse status and failure telemetry #3504

Description

Describe the bug

CommandResponse can represent contradictory state because its status, results, and TelemetryFailureMessage are independently mutable. The telemetry pipeline currently records TelemetryFailureMessage only when response.Status is outside the 2xx range.

If command code catches an exception or encounters another failure, populates TelemetryFailureMessage, but accidentally leaves the default success status, the response becomes a "task failed successfully": the failure is reported as success and the diagnostic telemetry message is silently ignored.

This was identified in the review of #3426: #3426 (comment)

Expected behavior

Contradictory CommandResponse state should be prevented or detected. A command should not be able to return a successful status together with failure-only telemetry without a clear signal.

Consider introducing construction APIs that encode valid outcomes, such as CommandResponse.FromSuccess(...), CommandResponse.FromException(...), and CommandResponse.FromNonExceptionFailure(...), and/or validation that rejects inconsistent combinations. If compatibility prevents enforcing invariants immediately, emitting TelemetryFailureMessage regardless of status could provide interim detection for incorrectly classified failures.

Actual behavior

CommandResponse defaults to HTTP 200 and exposes mutable properties. A command can set TelemetryFailureMessage while leaving Status successful. The response is treated as successful and the telemetry failure message is not emitted.

Reproduction Steps

  1. Implement a command that returns its default CommandResponse.
  2. Simulate a failure path that sets context.Response.TelemetryFailureMessage but does not update context.Response.Status.
  3. Return the response.
  4. Observe that the command result has a successful status and ToolFailureMessage is absent from telemetry.

Environment

Shared Microsoft.Mcp.Core command response and telemetry pipeline. Observed while reviewing PR #3426.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Azure.Mcp.Serverneeds-team-attentionWorkflow: This issue needs attention from Azure service team or MCP team.server-Azure.McpAzure.Mcp.Servertools-CoreAZMCP Core functionality that all other tools build on top of

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions