Skip to content

Make Go JSON-RPC requests context-aware#1643

Open
qmuntal wants to merge 2 commits into
github:mainfrom
qmuntal:jsonrpc2-context-cancellation
Open

Make Go JSON-RPC requests context-aware#1643
qmuntal wants to merge 2 commits into
github:mainfrom
qmuntal:jsonrpc2-context-cancellation

Conversation

@qmuntal

@qmuntal qmuntal commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Thread context.Context through the Go internal JSON-RPC request path, including Request, RequestWithInlineResponse, sendMessage, and response writes.
  • Pass caller contexts through handwritten SDK methods and generated Go RPC wrappers.
  • Add regression tests for cancellation before send, while waiting for a response, and while waiting for the serialized writer slot.

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:go
  • go test ./internal/jsonrpc2 ./rpc .

Copilot AI review requested due to automatic review settings June 12, 2026 12:05
@qmuntal qmuntal requested a review from a team as a code owner June 12, 2026 12:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 a context.Context and return ctx.Err() on cancellation.
  • Updated Go client/session code (and Go codegen output) to pass ctx into 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

Comment thread go/internal/jsonrpc2/jsonrpc2.go
Comment thread go/internal/jsonrpc2/jsonrpc2.go
Comment thread go/internal/jsonrpc2/jsonrpc2_test.go Outdated
Comment thread go/session.go
Comment thread scripts/codegen/go.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants