Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens the Go SDK’s internal jsonrpc2 stdio transport by introducing dedicated Content-Length framing, simplifying message decoding, and standardizing error handling for JSON-RPC 2.0 interactions with the Copilot CLI.
Changes:
- Introduces
headerReader/headerWriterfor Content-Length framed IO and uses them inClient(plus channel-based write serialization). - Replaces “try request then response” decoding with a single
decodeMessagethat validates thejsonrpcversion and discriminates request vs response. - Updates JSON-RPC error handling (standard error sentinels;
Error.Databecomesjson.RawMessage; removes unusedNotify).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| go/internal/jsonrpc2/jsonrpc2.go | Switches to framed IO + unified decode path, updates error model, and removes Notify/write-mutex usage. |
| go/internal/jsonrpc2/frame.go | Adds Content-Length header framing reader/writer implementation. |
| if len(msg.ID) > 0 { | ||
| return &Response{ | ||
| JSONRPC: msg.JSONRPC, | ||
| ID: msg.ID, | ||
| Result: msg.Result, | ||
| Error: msg.Error, | ||
| }, nil | ||
| } |
There was a problem hiding this comment.
decodeMessage treats any object with a non-empty id and no method as a Response, but it doesn’t validate that a response contains either a result or an error (and not both). As a result, an invalid response with neither field would be accepted and Request() would treat it as a successful call returning a nil result. Consider rejecting responses where (Error == nil && len(Result) == 0) or where both Error and Result are present, and returning an ErrInvalidRequest-style error instead.
This PR hardens the internal jsonrpc2 package: