[Bug]: TypeScript GET-with-body requests remain pending after a truncated response

Aperta Adatta ai principianti
#6,059 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@BlueRaddish ci sta già lavorando.

Dal 17/10/2026.

  • #6060 di @BlueRaddish — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
85/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
node.js, typescript

Direzione di ricerca

Inizia da clients/typescript/src/client/http-client.ts, concentrandoti sul fallback esclusivo di Node per GET con body e sulla relativa callback IncomingMessage. Esegui la riproduzione dell’issue, quindi individua i test esistenti di HttpClient esportato e aggiungi una copertura di regressione per una risposta distrutta prima che arrivi la lunghezza del contenuto dichiarata. Il lavoro è concluso quando questo caso viene rifiutato tempestivamente con l’errore di trasporto come causa, mentre le risposte complete e il comportamento esistente in caso di errori della richiesta restano invariati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug priority:low ready-for-dev
Is there an existing issue for the same bug?
  • I searched existing issues and open pull requests. #5611 / #5612 concern caller cancellation; that patch does not handle a response stream failing after headers arrive.
Bug Description

The TypeScript HttpClient GET-with-body transport leaves its promise pending when the server closes a response before its declared content length is received. It listens for errors on ClientRequest, but not on the separate IncomingMessage response stream. A request configured with a 1000 ms timeout remains pending after 1500 ms because the socket has already closed.

This reproduces against main at 1fbfd37f6fb21491ed733fc92d409aff1517ff4a, using the actual exported client on Node 24.18.0. No agent server, credentials or model calls are needed.

Steps to Reproduce

Save this as repro-response.mjs in the repository root, then run node --experimental-transform-types repro-response.mjs:

import { createServer } from 'node:http';
import { once } from 'node:events';
import { HttpClient } from './clients/typescript/src/client/http-client.ts';

const server = createServer((_request, response) => {
  response.writeHead(200, { 'Content-Type': 'application/json', 'Content-Length': '100' });
  response.write('{"events":');
  setImmediate(() => response.destroy());
});
server.listen(0, '127.0.0.1');
await once(server, 'listening');
const client = new HttpClient({ baseUrl: `http://127.0.0.1:${server.address().port}`, timeout: 1000 });
try {
  console.log(await Promise.race([
    client.get('/batch', { data: ['event-1'] }).then(
      () => 'resolved', (error) => `rejected: ${error.message}`
    ),
    new Promise((resolve) => setTimeout(() => resolve('still pending'), 1500)),
  ]));
} finally {
  server.closeAllConnections();
  server.close();
}

Actual output: still pending.

Expected Behavior

Reject the request promptly when its response stream fails, retaining the transport error as the cause. Do not resolve with partial data or leave the request pending indefinitely. Complete responses and existing request-error behavior should remain unchanged.

Adding an error listener to the existing IncomingMessage callback, using the same rejection convention as req.on('error'), makes the identical reproduction report rejected: Request failed: aborted.

Scope

This concerns the existing Node-only GET-with-body fallback in clients/typescript/src/client/http-client.ts. The browser fetch path, public API, schemas, Python server and caller-cancellation fix are separate. OpenAI Codex assisted with diagnosis and the local reproduction.


OpenHands AI triage

The following comments and acceptance criteria were added by the OpenHands AI agent.

Triage

clients/typescript/ owns this Node-only fallback, and the report pins a concrete gap in it: requestWithBodyOnGet() in clients/typescript/src/client/http-client.ts attaches error and timeout handling to the ClientRequest but nothing to the IncomingMessage response stream, so a response destroyed after headers arrive leaves the returned promise unsettled. That path is what the GET-with-body batch endpoints use (BashClient.batchGetEvents, conversation events). Scope is the smallest coherent one: make that fallback settle when its response stream fails, reusing the rejection convention the method already applies to request errors, plus regression coverage.

Non-goals: the browser fetch path in request(), the public HttpClient options/API and exported types, the generated agent-server schema, the Python SDK and agent server, caller-owned cancellation (#5611 / #5612), and retry/backoff policy.

Actual Behavior

client.get('/batch', { data: ['event-1'] }) with timeout: 1000 against a server that destroys the response after writing {"events": still prints still pending at 1500 ms; the promise neither resolves nor rejects. The reproduction uses the exported client on Node 24.18.0 and needs no agent server, credentials, or model calls.

Acceptance Criteria
  • A GET request with a JSON body whose response stream is destroyed after the headers arrive rejects instead of remaining pending: the reproduction with timeout: 1000 reports a rejection before the 1500 ms deadline rather than still pending.
  • The rejection preserves the transport error as cause and follows the existing Request failed: <message> convention already used for ClientRequest errors, so a truncated response rejects with Request failed: aborted.
  • A complete GET-with-body response still resolves with the parsed body, status, statusText, and headers.
  • Existing request-error behavior is unchanged: connection-level failures and the configured request timeout keep their current rejection messages and cause.
  • No public API change is needed to observe the fix: no new option, parameter, or exported type, and the browser fetch path is untouched.
  • Automated coverage exercises the exported HttpClient against a server that closes the response before its declared Content-Length is received and asserts the promise rejects, so the pending-promise regression cannot silently return.
Lingua principale
Python
Stelle
1.4k
Fork
797
Merge medio
1g 17h
PR unite (30g)
354

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di OpenHands/software-agent-sdk

Tutte le issue di OpenHands/software-agent-sdk

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.