`_onprogress` raises a protocol error for a race servers cannot avoid (progress notification arriving with the response)
Les mainteneurs répondent en général sous 1 jour
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 68/100
- Type d'issue
- Bug
- Clarté
- Plutôt claire
- Activité
- Calme
- Stack technique
- typescript
- Domaine
- api
Piste de recherche
Commencez dans src/shared/protocol.ts en lisant _onresponse et _onprogress, puis reproduisez la race avec l’exemple callTool et les messages de progression et de réponse adjacents. C’est terminé lorsqu’une notification de progression tardive pour une requête terminée est ignorée sans déclencher _onerror, tandis que la transmission normale de la progression reste inchangée ; vérifiez s’il faut documenter le comportement de la notification terminale.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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.
- Langage dominant
- TypeScript
- Étoiles
- 13.7k
- Forks
- 2.3k
- Merge moyen
- 1 j 2 h
- PR mergées (30 j)
- 60
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de modelcontextprotocol/typescript-sdk
-
The `maxToolInputElements` refusal lacks the `Input validation error:` prefix that the schema refusal carriesPeut-être pris @barry166 l’a pris il y a 1 jour. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
modelcontextprotocol/typescript-sdk#3111 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
v2
Difficulté 2/5 1-3 heures Accessibilité débutants 71/100
modelcontextprotocol/typescript-sdk#3109 ·
Les mainteneurs répondent en général sous 1 jour
-
server: registeredResource.update and registeredResourceTemplate.update desync title and metadata.title when updating metadata alonePeut-être pris @FelixFangX l’a pris il y a 1 jour. Ouvertev1 v2
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
modelcontextprotocol/typescript-sdk#3103 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
[v2] server/client 2.4.0 inline fast-uri 3.1.8; four advisories published after release are fixed in 3.1.9Peut-être pris @claude l’a pris il y a 1 jour. Ouvertev2
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
modelcontextprotocol/typescript-sdk#3101 ·
Les mainteneurs répondent en général sous 1 jour
-
[v1.x] Protocol.request keeps its abort listener after the request resolved, so a later abort sends notifications/cancelled for an answered request (1.30.0)Peut-être pris Une pull request liée à cette issue est ouverte ou déjà fusionnée. Ouvertev1
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
modelcontextprotocol/typescript-sdk#3090 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de modelcontextprotocol/typescript-sdk
Issues similaires
-
[Integration]: eRPCOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
ava-labs/builders-hub#4826 ·
Les mainteneurs répondent en général sous 1 jour
-
记忆分析的默认模型显示与实际使用不一致Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 66/100
anomalyco/opencode#59886 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 85/100
-
a10y a10y-audit ai-driven-qa claude
Difficulté 2/5 1-3 heures Accessibilité débutants 86/100
Les mainteneurs répondent en général sous 1 jour