mcp: wrap ErrConnectionClosed for notifications and interrupted calls #1449
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.40) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 308 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.343
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #1449"
general
weight: 0.35
Jackmeson1
Fixes #1448
Client.Connectpromises that calls and notifications wrapErrConnectionClosedwhen the server closes the connection. Notifications after observed closure returned only the internal closing error, while calls interrupted by reader termination returned the raw read error.Translate notification closing errors and mark outstanding calls when the reader retires them. Preserve the underlying cause when adding
ErrConnectionClosed, including for subsequent calls on the closed connection. Classification uses the closing marker, so EOF returned while decoding a result is not mistaken for connection termination.Both closing-error translations now remove the internal
jsonrpc2.ErrClientClosingandErrServerClosingmarkers before addingErrConnectionClosed, preserving any remaining causes. Their codes (-32003/-32004) are therefore absent from these translated errors. With EOF as the cause, a call readsconnection closed: calling "tools/call": EOF, and a notification readsconnection closed: EOF. With no remaining cause, the call retains its method name and the notification returnsErrConnectionCloseddirectly.Tests
For the first commit, I ran
go build ./...,go test -race ./internal/jsonrpc2 ./mcp,go test ./..., andgo vet ./internal/jsonrpc2 ./mcpwith Go 1.27.3 on Ubuntu 22.04.2 LTS. All passed. I rangofmt -lon all changed Go files; it reported no files.The first regression run with the new tests and base production code failed as expected. Tests cover notifications after closure, calls interrupted by a stdio peer exit, the subsequent call, underlying error preservation, and controls for cancellation, ordinary JSON-RPC errors, and result-decoding errors.
The second commit adds assertions for calls and notifications that preserve matching of
ErrConnectionClosedand any remaining causes, reject both internal closing markers witherrors.Is, and reject closing codes exposed througherrors.As. Cases include local close, EOF, read errors, and wrapped and joined closing errors.At
1895f49, with Go 1.27.3 on Ubuntu 24.04.5 LTS,go build ./...,go test -race ./mcp,go test ./...,go vet ./mcp, and the formatting check passed. The regression run with the new tests and the first commit's production code failed as expected.The change was drafted with AI assistance (OpenAI Codex, reviewed with Claude Code).
🤖 Generated with Claude Code