Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở Phù hợp với người mới
#2,580 4 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@qiushui7 đang làm issue này rồi.

Từ ngày 30/7/2026.

  • #2967 của @feniix — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
68/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
typescript
Lĩnh vực
api

Hướng nghiên cứu

Bắt đầu trong src/shared/protocol.ts bằng cách đọc _onresponse và _onprogress, sau đó tái hiện race với ví dụ callTool cùng các thông báo tiến trình và phản hồi liền kề. Hoàn tất có nghĩa là một thông báo tiến trình đến muộn cho một yêu cầu đã hoàn tất bị loại bỏ mà không kích hoạt _onerror, trong khi việc gửi tiến trình bình thường vẫn không thay đổi; hãy cân nhắc xem hành vi của thông báo kết thúc có cần được ghi lại trong tài liệu hay không.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
TypeScript
Star
13.6k
Fork
2.3k
Merge trung bình
1 ngày 5 giờ
Pull request đã merge (30 ngày)
52

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của modelcontextprotocol/typescript-sdk

Tất cả issue của modelcontextprotocol/typescript-sdk

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.