Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

`_onprogress` raises a protocol error for a race servers cannot avoid (progress notification arriving with the response)

オープン 初心者向け
#2,580 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@qiushui7 がすでに取り組んでいます。

2026年7月30日 から。

  • #2967 @feniix による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
68/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
typescript
領域
api

調査の方向性

src/shared/protocol.ts で _onresponse と _onprogress を読むことから始め、次に callTool の例と、隣接する進捗メッセージおよびレスポンスメッセージを使って race を再現します。完了条件は、完了済みのリクエストに対する遅れて届いた進捗通知が _onerror を発生させずに破棄され、通常の進捗配信は変更されないことです。終端通知の動作をドキュメント化する必要があるかどうかも検討してください。

索引モデルが issue の本文から書いたものです。

説明

bug P2 ready for work v1 v2
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

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

modelcontextprotocol/typescript-sdk のほかの issue

modelcontextprotocol/typescript-sdk の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。