Commit Graph
17 Commits
Author SHA1 Message Date
Nick HollonandGitHub af5dab5b77 fix(sdk-py): percent-encode thread_id in v3 stream transport default paths (#7954)
## Problem

Fixes #7953.

The v3 SSE and WebSocket stream transports build their default paths by
interpolating `thread_id` directly into the URL:

```python
self._commands_url = commands_path or f"/threads/{thread_id}/commands"
self._stream_url   = stream_path   or f"/threads/{thread_id}/stream/events"
```

This skips the `_quote_path_param` escaping that the rest of the SDK
adopted in #7893. A `thread_id` containing reserved characters or
dot-segments is then normalized by the HTTP/WebSocket stack before
transmission. For example, `thread_id = "../assistants/abc"`:

| | before |
|---|---|
| constructed | `/threads/../assistants/abc/commands` |
| wire path | `/assistants/abc/commands` |

So the value stops being one opaque identifier under
`/threads/{thread_id}/...` and silently hits a different resource.

## Fix

Reuse the existing `_quote_path_param` helper for the **default** paths
in all four transports (`http`, `sync_http`, `ws`, `sync_ws`). Explicit
`commands_path` / `stream_path` overrides are left untouched, so callers
that pass their own paths opt out of encoding as before.

`_quote_path_param("../assistants/abc")` → `..%2Fassistants%2Fabc`,
which the HTTP/WS stack no longer collapses.

## Tests

Adds `tests/streaming/test_transport_path_encoding.py` covering all four
transports:
- default `_commands_url` / `_stream_url` / `_stream_path` are
percent-encoded,
- the actual SSE wire path (async + sync) stays under `/threads/`,
- the built WebSocket URL (async + sync) stays under `/threads/`,
- explicit path overrides are left untouched.

`make format`, `make lint`, and `make test` all pass in `libs/sdk-py`
(491 passed).
2026-06-01 13:20:32 -04:00
Nick HollonandGitHub 1fcb768182 feat(sdk-py): extract stream decoders and add interleave_projections (#7935)
## Summary

Refactors the four (now five) sdk-py streaming projections into
reusable, transport-agnostic `Decoder` classes and adds a new
`interleave_projections(channels)` method to `AsyncThreadStream` and
`SyncThreadStream` that drives multiple decoders from one shared
subscription, yielding `(channel_name, item)` tuples in arrival order
(the SDK analog of local `GraphRunStream.interleave`).

- **New `langgraph_sdk/stream/decoders.py`**: pure `feed(event) ->
Iterable[item]` state machines — `ValuesDecoder`, `MessagesDecoder`,
`ToolCallsDecoder`, `SubgraphsDecoder`, `ExtensionsDecoder` — behind a
`Decoder` Protocol. No subscription/queue/thread access.
- **Projection migration (async + sync)**: the five existing projections
now delegate their per-event logic to the decoders. Behavior-preserving
— the existing test suite is the regression net. Thread-coupled side
effects (active-stream registration, terminal-error-on-close, root-inbox
forwarding) stay in the projection wrappers; sync messages/tool_calls
keep their pre-dispatch contract (handle/stream resolved on yield) via a
FIFO-head buffer.
- **`interleave_projections`**: flat-namespace channel list (built-ins +
extension names), `tool_calls`↔`tools` wire mapping, subgraphs fed every
event, extensions keyed by bare name.

### Notable
- Fixes a latent sync bug surfaced by the refactor: two tool calls /
messages whose events interleave previously dropped the second; both now
surface. Locked in with a regression test.
- `Decoder.feed` takes `Mapping[str, Any]` (read-only), so the Protocol
is load-bearing in both stream files.

### Deferred (not in this PR)
- Wiring `RemoteGraph._RemoteGraphRunStream.interleave` to
`interleave_projections` (gated on #7927).
- Migrating the handle-scoped projections (`_Handle*Projection`) to the
decoders — hence the small, verified-identical helper duplication
between `decoders.py` and `_async/stream.py`.
- `interleave_projections` handles aren't registered for thread-close
cleanup (additive follow-up).

## Test Plan
- [x] `make test` in `libs/sdk-py` — 464 passed, 0 failures
- [x] `make format` / `make lint` (ruff + ty) clean
- [x] Per-decoder unit tests in `tests/streaming/test_decoders.py`
- [x] `interleave_projections` tests (single-channel, multi-channel
arrival order, builtin+extension mix, tool_calls public-name, subgraphs
discovery) async + sync
- [x] Existing projection suites pass unchanged (regression net for the
migration)
2026-05-29 17:14:14 -04:00
Nick HollonandGitHub 8cb0f3a96d feat(sdk-py): add thread stream helpers (#7833) 2026-05-27 17:02:59 -04:00
Nick HollonandGitHub fd4257300e feat(sdk-py): wire websocket stream selection (#7832) 2026-05-27 16:48:22 -04:00
Nick HollonandGitHub d482fca105 feat(sdk-py): add websocket stream transports (#7830) 2026-05-27 16:01:01 -04:00
Nick HollonandGitHub 4f3ab2f969 feat(sdk-py): harden streaming reconnects (#7829) 2026-05-27 15:24:25 -04:00
Nick HollonandGitHub 3282ac10e3 feat(sdk-py): add sync scoped subgraphs (#7828) 2026-05-27 14:23:56 -04:00
Nick HollonandGitHub 3d61d1b32f feat(sdk-py): add sync messages and tool calls (#7827) 2026-05-27 14:04:34 -04:00
Nick HollonandGitHub fe1c683fe1 feat(sdk-py): add sync thread stream core (#7826) 2026-05-27 13:41:55 -04:00
Nick HollonandGitHub 10b701cf41 feat(sdk-py): add async stream reconnect support (#7825) 2026-05-27 13:30:01 -04:00
Nick HollonandGitHub bb9cfe7a22 feat(sdk-py): add scoped subgraph handles (#7824) 2026-05-27 13:18:52 -04:00
Nick HollonandGitHub 30fea64687 feat(sdk-py): add messages and tool call projections (#7823) 2026-05-27 12:11:06 -04:00
Nick HollonandGitHub 66ec594540 feat(sdk-py): add output, values, and controller extraction (#7822) 2026-05-27 11:27:11 -04:00
Nick HollonandGitHub 221deee774 feat(sdk-py): wire lifecycle state and output prerequisites (#7821) 2026-05-27 11:06:37 -04:00
Nick HollonandGitHub d03310abbb feat(sdk-py): add shared stream subscriptions (#7820) 2026-05-27 10:53:26 -04:00
Nick HollonandGitHub 22259558cc feat(sdk-py): add async thread stream skeleton (#7819) 2026-05-27 10:41:50 -04:00
Nick HollonandGitHub 3268a54791 feat(sdk-py): add v3 streaming primitives and SSE transport (#7818) 2026-05-27 10:10:09 -04:00