← Back to Pull requests

mcp: wrap ErrConnectionClosed for notifications and interrupted calls #1449

Closed
unknown closed this pull request without merging on Oct 26, 2026 13:20 UTC
View on GitHub
unknown unknown commented on Oct 25, 2026 02:31 UTC
Author

Fixes #1448

Client.Connect promises that calls and notifications wrap ErrConnectionClosed when 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.ErrClientClosing and ErrServerClosing markers before adding ErrConnectionClosed, preserving any remaining causes. Their codes (-32003/-32004) are therefore absent from these translated errors. With EOF as the cause, a call reads connection closed: calling "tools/call": EOF, and a notification reads connection closed: EOF. With no remaining cause, the call retains its method name and the notification returns ErrConnectionClosed directly.

Tests

For the first commit, I ran go build ./..., go test -race ./internal/jsonrpc2 ./mcp, go test ./..., and go vet ./internal/jsonrpc2 ./mcp with Go 1.27.3 on Ubuntu 22.04.2 LTS. All passed. I ran gofmt -l on 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 ErrConnectionClosed and any remaining causes, reject both internal closing markers with errors.Is, and reject closing codes exposed through errors.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

Diff: 308 lines (+231 / -77) across 3 files Reviewer: Jackmeson1 Review duration: 2088m
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
0.40
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
56%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
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
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 56.8% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 40.2% (MEDIUM) · Higher = larger blast radius
40.2%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 56.8% · Lower = rushed or shallow review
56.8%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 17.4% · Safe to merge
17.4%