Repository navigation
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
9 tasks done
When RemoteA2aAgent itself failed to talk to its peer it yielded an Event with only an error_message: the agent card or the credential could not be resolved, the request failed, the stream ended before a terminal task state, or a response could not be handled. A task the remote agent reports as failed already carried A2A_TASK_FAILED, so a caller could key off error_code for that one failure and had to match error_message for the rest. These events are now built in one place. They carry the new A2A_REQUEST_FAILED error code and the message under the a2a:error metadata key (before, only the request-failure paths had it), plus the request under a2a:request when one was already built. Closes google#8160
fponsse
force-pushed
the
fix/remote-a2a-agent-error-code
branch
from
November 15, 2026 20:13
1d23d07 to
da2332a
Compare
…r the older handler
Rename the code that RemoteA2aAgent puts on the error events of its own
failures from A2A_REQUEST_FAILED to A2A_CLIENT_ERROR. Those events cover the
agent card, the credential, the request and the stream, so "request" named
only part of them. The new name sits next to A2A_TASK_FAILED as its
counterpart: a failure on the caller's side vs. a failure the peer reported
for its task. The helper that builds the events is renamed to match.
Tests: add the two client-error paths of the older _handle_a2a_response,
which had none (the tests for those paths only called
_handle_a2a_response_v2), and make the two generic send_message failure tests
raise from a real async generator. They used to fail through an AsyncMock
artifact ('coroutine' object has no attribute 'aclose') instead of the
configured exception; they now pin "A2A request failed: Send failed".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
A2A_TASK_FAILEDfor a failed remote task), RemoteA2aAgent ends the invocation silently when the A2A stream stops before a terminal task state #6585, RemoteA2aAgent in task mode hangs Runner.run_async() when the caller stops at its error event #7918Problem:
When
RemoteA2aAgentitself fails to talk to its peer, it yields anEventwith only anerror_message: no content and noerror_code. A task the remote agent reports as failed does carry anerror_code(A2A_TASK_FAILED). So a caller can key offerror_codefor one kind of failure and has to matcherror_messagefor the rest. Thea2a:errormetadata key was also only on the request-failure paths, not on the card/initialization or authentication failures.Solution:
A2A_CLIENT_ERROR_CODE("A2A_CLIENT_ERROR") ina2a/converters/utils.py, next toA2A_TASK_FAILED_ERROR_CODE._create_client_error_event, builds every error event for a failure of the A2A exchange itself:error_code,error_message, no content, the message undera2a:error, and the request undera2a:requestwhen one was already built (a2a:status_codestays on HTTP errors).A2AClientErrorwhile handling a response (both handlers), unknown response type (both handlers).What does not change: the
error_messagetexts, the order of the events, thefinish_taskevents of task mode,_create_task_failure_events(a remote task reported as failed in task mode, which #7251 touches), and the events of a failed remote task (A2A_TASK_FAILED).is_final_response()isTruefor these events before and after.Effects worth a look (from reading the code, and measured where it says so):
_agent_router._event_filteralready skips an event with anerror_codeand no content when it decides which agent owns the conversation ("A node failure is recorded as an error event without content. It is not a reply..."). These events now fall under that rule. I did not test a setup where the remote agent is transferable.In a
Workflow, a node that emits an event with anerror_codeis recovered as a failed node, as for a failed task. A new test covers it.A served agent that contains a failing
RemoteA2aAgent(measured: an agent served withto_a2awhose sub-agent is aRemoteA2aAgentwith an unreachable card, and a secondRemoteA2aAgentas its caller):COMPLETED, no textFAILED, the failure text,A2A_TASK_FAILEDA2aAgentExecutor(force_new_version=True)FAILED, the failure text,A2A_TASK_FAILEDFAILED, the failure text,A2A_CLIENT_ERRORSo with the default executor a failure the caller never heard about now reaches it, and with the new one the code that crosses is the more specific one. The text is the
error_message, which can include the card URL or the exception text; that is already what the new executor forwards for anerror_message-only event, and what a failed remote task does. Sanitizing it is the subject of A2aAgentExecutor sends the raw exception text to the A2A caller when the run fails #7385 and fix(a2a): sanitize error message on executor failure to prevent data leak #7402, not of this PR.Testing Plan
Unit Tests:
pytest tests/unittests/a2a/agent: 373 passed.pytest tests/unittests/{a2a,agents,workflow,flows,events,runners,tools}: 8658 passed, 59 skipped, 6 xfailed, 0 failed.The tests assert
error_code == A2A_CLIENT_ERROR_CODEon the existing failure tests (card/initialization, authentication, HTTP error, other exception, stream ended early,A2AClientError, unknown response type), assert thea2a:errormetadata on the initialization failure, and add oneWorkflowtest modeled ontest_failed_remote_task_in_workflow_is_not_promoted_to_output(node failed, no output, recovered with the new code). Two more cover the client-error paths of the older_handle_a2a_responsehandler, which had none (the existing tests for those paths only called_handle_a2a_response_v2). The two genericsend_messagefailure tests now raise from a real async generator and pinA2A request failed: Send failed: before, theAsyncMockreturned a coroutine, so they failed through'coroutine' object has no attribute 'aclose'instead of the configured exception. With the constant defined but the behavior left as it was, 15 of them fail.pre-commitpasses on the changed files.Manual End-to-End (E2E) Tests:
The repro of #8160 (scripted models, no API key). Before, on
main(d05e482), cases A (card unreachable) and B (HTTP 500) haderror_code=None, and A had nocustom_metadata. After:Checklist
Additional context
The code name is open to change: one code per kind of failure would be a small step from here if the maintainers prefer it.