langgraph/libs/sdk-py/langgraph_sdk/stream
Richard Scarrott 5a3e5dd739
fix(sdk-py): retry failed stream reconnects with backoff (#9462)
## Summary

A stream reconnect that fails to open (429, 5xx, transport error,
non-SSE response) is now retried with backoff instead of ending the
stream, e.g. while the server restarts or deploys.

```diff
 HttpClient.stream / SyncHttpClient.stream, on reconnect (GET to Location)
-  retry only a mid-read drop, with no delay, 5 times per stream
+  also retry a reconnect that fails to open: 429, 5xx, transport error, non-SSE
+  sleep 1, 2, 4, 5, 5s (+ up to 25% jitter) before each reconnect
+  reset the 5 attempts once a reconnect yields an event
+  give up with "Exceeded maximum…" raised from the last error
```

The first POST still raises on any error, since retrying it could start
a duplicate run. The backoff formula moves to `_shared/utilities.py`,
shared with the stream controllers.

The sleep also delays the first reconnect after a plain drop by about a
second, which matches the JS SDK. A run created without
`stream_resumable=True` can't replay what it sent while the client was
away, so it now loses about a second more of events. Resumable runs lose
nothing.

## Evidence

- **Before:** a reconnect hitting 429/502/503, a connect error or a
non-SSE response raised, a stream with 6 spaced-out drops gave up, and
reconnects never slept.
**After:** `test_client_stream.py` covers each (sync and async), plus
404 and first-POST failures staying fatal, and giving up after ~20s.

## Merge Danger

**Door:** two-way

**Blast Radius:** small (sdk-py stream reconnects only)
2026-10-28 11:46:39 +00:00
..
transport fix(sdk-py): percent-encode thread_id in v3 stream transport default paths (#7954) 2026-06-01 13:20:32 -04:00
__init__.py feat(sdk-py): add messages and tool call projections (#7823) 2026-05-27 12:11:06 -04:00
controller.py fix(sdk-py): retry failed stream reconnects with backoff (#9462) 2026-10-28 11:46:39 +00:00
decoders.py feat(sdk-py): extract stream decoders and add interleave_projections (#7935) 2026-05-29 17:14:14 -04:00
errors.py fix(sdk-py): surface thread stream errors and stop retrying a rejected stream (#9317) 2026-10-16 15:29:34 -04:00
multi_cursor_buffer.py feat(sdk-py): add v3 streaming primitives and SSE transport (#7818) 2026-05-27 10:10:09 -04:00
subscription.py feat(sdk-py): add shared stream subscriptions (#7820) 2026-05-27 10:53:26 -04:00
sync_controller.py fix(sdk-py): retry failed stream reconnects with backoff (#9462) 2026-10-28 11:46:39 +00:00