mcp-context-forge icon indicating copy to clipboard operation
mcp-context-forge copied to clipboard

[BUG]: A2A invocation records every HTTP 200 as a success

Open a-effort opened this issue 1 month ago • 0 comments

Summary

A2AAgentService.invoke_agent sets success = True for any HTTP 200 and never looks at the response body (mcpgateway/services/a2a_service.py:2409-2411):

if status_code == 200:
    response = response_json if response_json is not None else {"response": response_text}
    success = True

A2A rides on JSON-RPC, so an agent reporting a failure answers with HTTP 200 and an {"error": {...}} member in the body. The caller receives that error, because response is returned verbatim, while the metric records a success.

That flag reaches record_a2a_agent_metric_with_duration at line 2550 and writes an A2AAgentMetric row. aggregate_metrics (line 3041) reads those rows through aggregate_metrics_combined(db, "a2a_agent") and derives success_rate, which GET /v1/metrics returns as a2aAgents.successRate. So every agent-reported error inflates the published success rate.

avg_response_time is not affected, since the duration is recorded on both branches.

Relationship to #4211: #4211 covers tool_service.py:7016-7025 and record_tool_metric, which is the bridged path where an agent is invoked as an MCP tool, and it skews the tool aggregate. This issue is the direct /v1/a2a/{agent_name}/invoke path and the agent aggregate. #4211's body names only tool_service.py, and its closed PR #4238 touched only that file.

Proposed fix Inspect the parsed body before setting success. Treat a JSON-RPC error member as a failure and pass its message through as error_message so the metric row records why. The body is already parsed into response_json at line 2404, so this needs no extra deserialization.

The task-persistence block immediately below already unwraps result from the same payload, so the error case can be told apart in the same place rather than parsing twice.

Leave the return value alone. Callers depend on receiving the JSON-RPC envelope as sent.

Acceptance

  • [ ] A 200 carrying a JSON-RPC error member records success=False
  • [ ] The recorded error_message carries the JSON-RPC error message
  • [ ] a2aAgents.successRate excludes such responses
  • [ ] A unit test mocks a 200 with a JSON-RPC error body and asserts record_a2a_agent_metric_with_duration receives success=False, mirroring the guard proposed on #4211

Consumers:

  • #7324 renders a2aAgents.successRate on the home A2A card
  • #6697 opens the same aggregate to callers without admin.metrics

a-effort avatar Oct 27 '26 19:10 a-effort