Make Go JSON-RPC requests context-aware#1643
Open
qmuntal wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR propagates context.Context through the Go JSON-RPC client request path and updates generated and hand-written Go API calls to support cancellation/timeouts.
Changes:
- Updated JSON-RPC client APIs (
Request,RequestWithInlineResponse, and send path) to accept acontext.Contextand returnctx.Err()on cancellation. - Updated Go client/session code (and Go codegen output) to pass
ctxinto JSON-RPC requests. - Added unit tests to validate cancellation behavior before send and while awaiting a response.
Show a summary per file
| File | Description |
|---|---|
| scripts/codegen/go.ts | Changes generated code to pass ctx into Request(...) calls. |
| go/internal/jsonrpc2/jsonrpc2.go | Adds context-aware request/send APIs and cancellation checks. |
| go/internal/jsonrpc2/jsonrpc2_test.go | Adds tests covering context cancellation semantics and request cleanup. |
| go/client.go | Updates high-level client APIs to pass ctx into JSON-RPC calls. |
| go/session.go | Updates session APIs to pass ctx into JSON-RPC calls and removes an outdated TODO. |
| go/canvas_test.go | Updates tests to pass a context into Request(...). |
Copilot's findings
Files not reviewed (1)
- go/rpc/zrpc.go: Generated file
- Files reviewed: 6/7 changed files
- Comments generated: 5
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.
Summary
context.Contextthrough the Go internal JSON-RPC request path, includingRequest,RequestWithInlineResponse,sendMessage, and response writes.Note
Context cancellation now returns
ctx.Err()to the caller and cleans up pending request state at the request/wait boundaries. It does not preempt transport I/O that is already executing on the underlying stream, close or reset the connection, or send a JSON-RPC protocol-level cancellation notification.Tests
npm run generate:gogo test ./internal/jsonrpc2 ./rpc .