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:
dispatch_request in incoming_actor.rs
- The main loop of
incoming_protocol_actor
- 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.
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 paramserror response for that request and continue serving the connection.Reproduction
Using
sacp10.1.0, register a handler for a request type (e.g.,PromptRequestwhich expects apromptfield). 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_messagereturnsErr(err)whenReq::parse_messagereturnsSome(Err(..)):This error propagates via
?through:dispatch_requestinincoming_actor.rsincoming_protocol_actorserve(), which returns the errorThe 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.