`_onprogress` raises a protocol error for a race servers cannot avoid (progress notification arriving with the response)
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 68/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Tranquilo
- Stack tecnológico
- typescript
- Área
- api
Línea de trabajo
Comienza en src/shared/protocol.ts leyendo _onresponse y _onprogress; después, reproduce la condición de carrera con el ejemplo de callTool y los mensajes de progreso y respuesta adyacentes. Se considera terminado cuando una notificación de progreso tardía de una solicitud completada se descarta sin activar _onerror, mientras la entrega normal del progreso permanece sin cambios; considera si es necesario documentar el comportamiento de la notificación terminal.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- TypeScript
- Estrellas
- 13.5k
- Forks
- 2.3k
- Merge medio
- 1 d 15 h
- PR fusionados (30 d)
- 51
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de modelcontextprotocol/typescript-sdk
-
Stateless 405 response omits the Allow headerPosiblemente ocupada @Hugo-DDT la tomó hoy. Abiertov2
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
modelcontextprotocol/typescript-sdk#2970 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
[v2] @modelcontextprotocol/server inlines fast-uri 3.1.0, which has 9 published advisoriesPosiblemente ocupada @Andiii208 la tomó hace 2 días. Abiertov2
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
modelcontextprotocol/typescript-sdk#2966 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
v1 v2
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
modelcontextprotocol/typescript-sdk#2946 · 4 comentarios ·
Los mantenedores suelen responder en 1 día
-
[v2] URI template reserved expansions encode existing %HH sequences againPosiblemente ocupada @takagibit18 la tomó hace 9 días. Abiertov1 v2
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
modelcontextprotocol/typescript-sdk#2920 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
[v2] URI template strict expansions leave !'()* unencodedPosiblemente ocupada @takagibit18 la tomó hace 9 días. Abiertov1 v2
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
modelcontextprotocol/typescript-sdk#2919 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de modelcontextprotocol/typescript-sdk
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
cline/mcp-marketplace#2932 ·
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Dificultad 1/5 Menos de una hora Aptitud para principiantes 82/100
lingdojo/kana-dojo#32188 · 1 comentario · 5 reacciones ·
Los mantenedores suelen responder en 1 día
-
triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Portkey-AI/gateway#1844 ·
Los mantenedores suelen responder en 1 día
-
needs triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 61/100
rjsf-team/react-jsonschema-form#5495 ·
Los mantenedores suelen responder en 2 días