Repository navigation
Commit f9e7a4c
authored
fix(agents): guard null response body in proxy stream reader (#107325)
* fix(agents): guard null response body in proxy stream reader
The proxy transport used response.body! (non-null assertion) to enter the
SSE read loop without checking whether the body is present. response.ok
does not guarantee response.body is non-null — empty 200 responses and
prematurely-closed connections leave body=null while ok=true.
Sibling transports in the same repository already guard this case:
- provider-transport-fetch.ts:148,385,541
- anthropic-transport-stream.ts:847
- openai-completions-transport.ts:272
- mcp-http-fetch.ts:60,76 (added in #98143)
Add the same guard before getReader() so the caller receives a business-
level diagnostic ("Proxy returned an empty response body") instead of
the misleading JS runtime error "Cannot read properties of null (reading
'getReader')". The try-catch in streamProxy already catches the error
and pushes it as a stream event, so this does not introduce a new crash
— it replaces an internal TypeError with a meaningful error.
* test(agents): cover null response body in proxy stream reader1 parent 9e3a50b commit f9e7a4c
2 files changed
Lines changed: 34 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
598 | 598 | | |
599 | 599 | | |
600 | 600 | | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
601 | 630 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
340 | 340 | | |
341 | 341 | | |
342 | 342 | | |
343 | | - | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
344 | 348 | | |
345 | 349 | | |
346 | 350 | | |
| |||
0 commit comments