Skip to content

Request deserialization errors kill the connection instead of returning JSON-RPC error #131

@TrevorBurnham

Description

@TrevorBurnham

Summary

When a JSON-RPC request matches a registered method but fails to deserialize its params (e.g., a missing or misspelled field), the error propagates through the handler chain and kills the entire connection. The client receives no response and hangs indefinitely.

The expected behavior is to send a JSON-RPC -32602 Invalid params error response for that request and continue serving the connection.

Reproduction

Using sacp 10.1.0, register a handler for a request type (e.g., PromptRequest which expects a prompt field). Send a request with the correct method but a wrong field name:

{
  "jsonrpc": "2.0",
  "id": 3,
  "method": "session/prompt",
  "params": {
    "sessionId": "sess_abc123",
    "content": [{"type": "text", "text": "hello"}]
  }
}

The server logs a parse error and the connection dies. The client never receives a response.

Root cause

In jsonrpc/handlers.rs, RequestHandler::handle_message returns Err(err) when Req::parse_message returns Some(Err(..)):

Some(Err(err)) => {
    tracing::trace!(?err, "RequestHandler::handle_request: parse errored");
    Err(err)
}

This error propagates via ? through:

  1. dispatch_request in incoming_actor.rs
  2. The main loop of incoming_protocol_actor
  3. Up to serve(), which returns the error

The connection is then torn down.

Suggested fix

When a request has an ID and its params fail to deserialize, send a JSON-RPC error response (e.g., -32602 Invalid params) to the client for that specific request, rather than propagating the error and killing the connection.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions