`_onprogress` raises a protocol error for a race servers cannot avoid (progress notification arriving with the response)
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 68/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 静か
- 技術スタック
- typescript
- 領域
- api
調査の方向性
src/shared/protocol.ts で _onresponse と _onprogress を読むことから始め、次に callTool の例と、隣接する進捗メッセージおよびレスポンスメッセージを使って race を再現します。完了条件は、完了済みのリクエストに対する遅れて届いた進捗通知が _onerror を発生させずに破棄され、通常の進捗配信は変更されないことです。終端通知の動作をドキュメント化する必要があるかどうかも検討してください。
索引モデルが issue の本文から書いたものです。
説明
Summary
When a request completes, Protocol._onresponse deletes that request's progress handler. Any progress notification for the token that is processed afterwards falls into _onprogress, finds no handler, and is reported through _onerror:
Received a progress notification for an unknown token: {...}
Discarding the notification is reasonable — once the request is done, progress for it is moot. Raising a protocol error for it is not, because a server has no way to avoid producing that condition.
Why a server cannot avoid it
A server that reports progress for a batch operation naturally emits a terminal progress === total notification just before returning the result. Those two writes are adjacent by construction. Whether the client processes the notification before or after the response is a timing race the server does not control — and on a loaded machine it loses.
Concretely, in src/shared/protocol.ts:
// _onresponse
if (!isTaskResponse) {
this._progressHandlers.delete(messageId);
}
// _onprogress
const handler = this._progressHandlers.get(messageId);
if (!handler) {
this._onerror(new Error(`Received a progress notification for an unknown token: ...`));
return;
}
So any server emitting a terminal progress notification will intermittently cause onerror to fire in every client. For hosts that log or surface protocol errors, a well-behaved server ends up manufacturing spurious error noise on a successful operation.
Attempting to fix it server-side does not work. Awaiting the notification sends before returning the result orders the writes correctly, but cannot prevent the client from tearing down its handler before it dispatches them.
Reproduction
Server emits N progress notifications then the result, with no artificial spacing between them. Client:
const progress: unknown[] = [];
const errors: string[] = [];
client.onerror = (e) => errors.push(e.message);
await client.callTool({ name: "export", arguments: { /* 3 items */ } },
CallToolResultSchema, { onprogress: (p) => progress.push(p) });
Observed (server sent 4 notifications, all before the result):
received=1
errors=[
'Received a progress notification for an unknown token: {"method":"notifications/progress","params":{"progress":1,"total":3,...,"progressToken":1}}',
'...{"progress":2,...}',
'...{"progress":3,...}'
]
One delivered, three discarded with an error each. With ~100ms spacing between notifications the same code delivers all four — i.e. it is purely a timing race, not a protocol violation by either side.
Observed with @modelcontextprotocol/sdk 1.29.0 over stdio.
Suggested change
Treat "progress notification for a request that has just completed" as an expected, benign race rather than an error:
- don't route it to
_onerror; ignore it silently, or log at debug level; or - keep a short grace period after response for recently-completed tokens and drop matching notifications quietly.
Either removes the false error without changing the (sensible) decision not to deliver late progress.
Secondary question
Is there any supported way for a server to deliver a terminal progress notification reliably? If not, that is worth stating in the spec/docs, so server authors know the final progress === total frame is inherently best-effort and clients know not to build completion UI on it. Right now it looks reliable, and fails only under load.
- 主要言語
- TypeScript
- スター
- 13.5k
- フォーク
- 2.3k
- 平均マージ
- 1日 22時間
- マージ済み PR(30日)
- 52
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
modelcontextprotocol/typescript-sdk のほかの issue
-
Stateless 405 response omits the Allow header対応中かも @jstar0 が 2 日前に担当しました。 オープンv2
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
modelcontextprotocol/typescript-sdk#2970 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
[v2] @modelcontextprotocol/server inlines fast-uri 3.1.0, which has 9 published advisories対応中かも @Andiii208 が 1 日前に担当しました。 オープンv2
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
modelcontextprotocol/typescript-sdk#2966 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
v1 v2
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
modelcontextprotocol/typescript-sdk#2946 · コメント 4 件 ·
メンテナーはふだん 1 日以内に返信
-
[v2] URI template reserved expansions encode existing %HH sequences again対応中かも @takagibit18 が 8 日前に担当しました。 オープンv1 v2
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
modelcontextprotocol/typescript-sdk#2920 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
[v2] URI template strict expansions leave !'()* unencoded対応中かも @takagibit18 が 8 日前に担当しました。 オープンv1 v2
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
modelcontextprotocol/typescript-sdk#2919 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
modelcontextprotocol/typescript-sdk の issue をすべて見る
似ている issue
-
area: desktop area: website priority: P2 type: feature
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
appandflow/stim#3411 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
needs triage
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
rjsf-team/react-jsonschema-form#5485 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
難易度 1/5 1時間未満 初心者へのやさしさ 65/100
lingdojo/kana-dojo#32090 · コメント 1 件 · リアクション 5 件 ·
メンテナーはふだん 1 日以内に返信
-
Friction: Org home and org switcher copy still say repositories and connected agents live in the personal account対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンfriction
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
kentcdodds/kody#3265 ·
メンテナーはふだん 1 日以内に返信