TDD: A2aLocalFacade.dispatch() raises A2aOperationNotFoundError instead of returning JSON-RPC 2.0 error response #10362

Open
opened 2026-04-18 09:11:15 +00:00 by HAL9000 · 0 comments
Owner

Metadata

Field Value
Branch test/a2a-facade-dispatch-operation-not-found-tdd
Commit Message test(a2a/facade): add @tdd_expected_fail scenario for dispatch() raising instead of returning JSON-RPC 2.0 error response
Milestone v3.5.0
Parent Epic

Background and Context

A2aLocalFacade.dispatch() in src/cleveragents/a2a/facade.py explicitly re-raises A2aOperationNotFoundError instead of converting it to a JSON-RPC 2.0 error response. This breaks the JSON-RPC 2.0 contract, which requires that all errors — including method-not-found — be returned as structured error responses, never as exceptions.

Current code (src/cleveragents/a2a/facade.py, dispatch() method):

def dispatch(self, request: A2aRequest) -> A2aResponse:
    ...
    try:
        data = self._route_operation(request.method, request.params)
        ...
    except A2aOperationNotFoundError:
        raise  # ← re-raises instead of returning error response
    except Exception as exc:
        ...
        return A2aResponse(id=request.id, error=A2aErrorDetail(...))

Per JSON-RPC 2.0 specification (Section 5.1), when a method is not found, the server MUST return an error response with code -32601 (Method not found), not raise an exception. The current implementation forces all callers to handle both exceptions AND error responses, violating the uniform error handling contract.

Expected Behavior

A Behave scenario tagged @tdd_issue @tdd_issue_N @tdd_expected_fail should:

  1. Create an A2aLocalFacade instance
  2. Call dispatch() with an unknown method name (e.g., "unknown/method")
  3. Assert that the call does NOT raise an exception
  4. Assert that the returned A2aResponse has error set (not result)
  5. Assert that response.error.code == -32601 (JSON-RPC 2.0 Method not found)

This test must fail on the current codebase (because dispatch() raises A2aOperationNotFoundError), confirming the bug exists.

Acceptance Criteria

  • A Behave scenario tagged @tdd_issue, @tdd_issue_N, and @tdd_expected_fail exists
  • The scenario calls dispatch() with an unknown method and asserts no exception is raised
  • The scenario asserts response.error.code == -32601
  • The scenario fails on the current codebase (confirming the bug)
  • The scenario passes after the fix is applied
  • Step definitions are implemented for the new scenario steps

Subtasks

  • Create or update a feature file with a scenario tagged @tdd_issue @tdd_issue_N @tdd_expected_fail
  • Write the scenario: given an A2aLocalFacade, when dispatch() is called with an unknown method, then no exception is raised and response.error.code == -32601
  • Implement step definitions
  • Verify the scenario fails on the current codebase (expected — confirms the bug)
  • Run nox -s unit_tests to confirm no regressions in other tests

Definition of Done

This issue is complete when:

  • All subtasks above are completed and checked off.
  • The failing Behave scenario is committed on the branch test/a2a-facade-dispatch-operation-not-found-tdd.
  • The scenario is tagged correctly with @tdd_issue, @tdd_issue_N, and @tdd_expected_fail.
  • The scenario fails before the fix and passes after the fix is applied.

Automated by CleverAgents Bot
Supervisor: Bug Hunt Pool | Agent: bug-hunt-pool-supervisor

## Metadata | Field | Value | |---|---| | **Branch** | `test/a2a-facade-dispatch-operation-not-found-tdd` | | **Commit Message** | `test(a2a/facade): add @tdd_expected_fail scenario for dispatch() raising instead of returning JSON-RPC 2.0 error response` | | **Milestone** | v3.5.0 | | **Parent Epic** | — | ## Background and Context `A2aLocalFacade.dispatch()` in `src/cleveragents/a2a/facade.py` explicitly re-raises `A2aOperationNotFoundError` instead of converting it to a JSON-RPC 2.0 error response. This breaks the JSON-RPC 2.0 contract, which requires that all errors — including method-not-found — be returned as structured error responses, never as exceptions. **Current code** (`src/cleveragents/a2a/facade.py`, `dispatch()` method): ```python def dispatch(self, request: A2aRequest) -> A2aResponse: ... try: data = self._route_operation(request.method, request.params) ... except A2aOperationNotFoundError: raise # ← re-raises instead of returning error response except Exception as exc: ... return A2aResponse(id=request.id, error=A2aErrorDetail(...)) ``` Per JSON-RPC 2.0 specification (Section 5.1), when a method is not found, the server MUST return an error response with code `-32601` (Method not found), not raise an exception. The current implementation forces all callers to handle both exceptions AND error responses, violating the uniform error handling contract. ## Expected Behavior A Behave scenario tagged `@tdd_issue @tdd_issue_N @tdd_expected_fail` should: 1. Create an `A2aLocalFacade` instance 2. Call `dispatch()` with an unknown method name (e.g., `"unknown/method"`) 3. Assert that the call does NOT raise an exception 4. Assert that the returned `A2aResponse` has `error` set (not `result`) 5. Assert that `response.error.code == -32601` (JSON-RPC 2.0 Method not found) This test **must fail** on the current codebase (because `dispatch()` raises `A2aOperationNotFoundError`), confirming the bug exists. ## Acceptance Criteria - [ ] A Behave scenario tagged `@tdd_issue`, `@tdd_issue_N`, and `@tdd_expected_fail` exists - [ ] The scenario calls `dispatch()` with an unknown method and asserts no exception is raised - [ ] The scenario asserts `response.error.code == -32601` - [ ] The scenario **fails** on the current codebase (confirming the bug) - [ ] The scenario **passes** after the fix is applied - [ ] Step definitions are implemented for the new scenario steps ## Subtasks - [ ] Create or update a feature file with a scenario tagged `@tdd_issue @tdd_issue_N @tdd_expected_fail` - [ ] Write the scenario: given an `A2aLocalFacade`, when `dispatch()` is called with an unknown method, then no exception is raised and `response.error.code == -32601` - [ ] Implement step definitions - [ ] Verify the scenario fails on the current codebase (expected — confirms the bug) - [ ] Run `nox -s unit_tests` to confirm no regressions in other tests ## Definition of Done This issue is complete when: - All subtasks above are completed and checked off. - The failing Behave scenario is committed on the branch `test/a2a-facade-dispatch-operation-not-found-tdd`. - The scenario is tagged correctly with `@tdd_issue`, `@tdd_issue_N`, and `@tdd_expected_fail`. - The scenario fails before the fix and passes after the fix is applied. --- Automated by CleverAgents Bot Supervisor: Bug Hunt Pool | Agent: bug-hunt-pool-supervisor
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#10362
No description provided.