Client returns a call's result before handling notifications that preceded it
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 48/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- go
調査の方向性
Start in internal/jsonrpc2/conn.go, tracing readIncoming, acceptRequest, handlerQueue, and handleAsync to compare response retirement with queued notification handling. Run go test -count=1 -v ./... in the reproduction repository and inspect order_test.go and wire_test.go. Done means notifications received before a response are handled before CallTool returns, or a documented wait mechanism is covered by passing tests.
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
When a server sends notifications during a request and then its response, the go-sdk client can return from CallTool before it has run the handlers for those notifications. Over in-memory transports the wire order is correct and the client reorders delivery; over Streamable HTTP the symptom is the same, but the wire order was not measured.
In internal/jsonrpc2/conn.go, readIncoming retires a *Response immediately, which wakes the Call waiting on it, while an incoming *Request (a notification included) goes through acceptRequest onto handlerQueue and is handled later by handleAsync on another goroutine. Notifications read before a response can therefore be handled after CallTool has returned.
For a plain client this means a ProgressNotificationHandler may still be running for a call that has already returned. LoggingMessageHandler should be affected the same way, since log messages take the same path through jsonrpc2.Connection, but the tests measure progress only.
For anything built on both halves of the SDK -- a gateway or proxy that forwards an upstream's progress to its own caller (the client calling the proxy) -- there is no correct way to forward. The proxy has to stop forwarding a call's progress at some point, and the only moment the SDK gives it is the upstream CallTool returning, when progress the upstream sent before its response may not have been handled yet. If it stops there, that progress is lost. If it keeps forwarding, the progress reaches its caller after the proxy has answered, which 2025-11-25 basic/utilities/progress forbids: "Progress notifications MUST only reference tokens that ... were provided in an active request", and "Progress notifications MUST stop after completion."
Nothing in the API says how many notifications preceded a response, or when they have been handled, so neither a client nor a proxy can wait for them.
To Reproduce
Four tests, each asserting the property that should hold, so a failing run is the reproduction: https://github.com/serverplumber/go-sdk-notify-order/tree/6230dcf2db9d0588ac9252a04d420f4c5f83db3a (order_test.go, wire_test.go; RESULTS.md has the per-run counts). Run go test -count=1 -v ./....
A tool reports progress three times and returns at once. No handler sleeps. The test clients' handlers only count, under a mutex; the proxy's forwards each notification, which is what a proxy is for. Three runs of 1000 calls each, at v1.8.0 and at main (25a53e3), Go 1.26.7 on linux/amd64:
| Test | v1.8.0 | main |
|---|---|---|
In-memory transports: calls whose CallTool returned before all 3 progress handlers ran |
69–80 | 43–58 |
| Streamable HTTP: the same | 342–373 | 374–399 |
| Proxy that stops forwarding when the upstream call returns: progress lost, of 3000 | 472–488 | 460–472 |
| Proxy that keeps forwarding: progress its caller read after the response, of 3000 | 579–591 | 575–608 |
The in-memory test also records the order the client's transport delivers messages in: every call's progress arrives before its response, in every run, so the reordering happens after Read, in jsonrpc2.Connection. The last proxy figure is counted at the transport of the proxy's caller for the same reason -- it is what the proxy sent, not the caller's own reordering.
Expected behavior
Handlers for notifications received before a response have run by the time the call that response settles returns -- or, failing that, the client offers a way to wait for them. Either lets a proxy forward progress before its own response.
Possible directions (for discussion, not a patch)
- Deliver a response through the same ordered path as incoming notifications, so retiring it waits for the handlers queued ahead of it.
- Or expose a barrier: something the code that called
CallToolcan wait on that completes when everything read before the response has been handled.
Additional context
Found building an MCP gateway on go-sdk for fault-injection testing. The gateway works around it by counting notifications/progress for a call's token on the HTTP event stream ahead of the response, and waiting until that many are forwarded -- which needs an http.RoundTripper that parses SSE, because the SDK gives no other handle on it. Before the workaround, the gateway's own test saw 1 of 3 progress notifications downstream: the other two were handled after the upstream call returned, by which time the gateway had answered and stopped forwarding for that call.
- 主要言語
- Go
- スター
- 5.2k
- フォーク
- 568
- 平均マージ
- 1日 15時間
- マージ済み PR(30日)
- 39
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
modelcontextprotocol/go-sdk のほかの issue
-
Session-lifecycle bookkeeping logs at info, spamming multiple log lines per request on stateless streamable HTTP対応中かも @anneheartrecord が 42 日前に担当しました。 オープンP3
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
modelcontextprotocol/go-sdk#1204 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Expose generic `SendNotification` on `ServerSession` for custom protocol extensions対応中かも @ajuijas が 208 日前に担当しました。 オープンneeds investigation
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
modelcontextprotocol/go-sdk#745 · コメント 13 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
mcp: client returns an input_required result that has only requestState instead of retrying対応中かも @SergeevDmitry が今日担当しました。 オープン
難易度 3/5 半日 初心者へのやさしさ 62/100
modelcontextprotocol/go-sdk#1364 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 18/100
modelcontextprotocol/go-sdk#1359 ·
メンテナーはふだん 1 日以内に返信
-
Streamable HTTP: a tool result that fails to marshal leaves the POST hanging (no JSON-RPC error)オープン
難易度 4/5 1〜2日 初心者へのやさしさ 45/100
modelcontextprotocol/go-sdk#1358 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
modelcontextprotocol/go-sdk の issue をすべて見る
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信
-
agent-research agent-review-finding chore
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
jordansmall/spindrift#4922 ·
メンテナーはふだん 1 日以内に返信
-
gcsartifact: deleting a missing version returns an error対応中かも @ktsoator が今日担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 2 日以内に返信
-
govulncheck
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
Change wording for init command success message対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信