langgraph-api 0.18.0.dev2__py3-none-any.whl → 0.18.0.dev4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. langgraph_api/__init__.py +1 -1
  2. langgraph_api/api/a2a.py +93 -10
  3. langgraph_api/api/event_streaming.py +81 -9
  4. langgraph_api/api/mcp/_calls.py +29 -0
  5. langgraph_api/api/mcp/_constants.py +15 -6
  6. langgraph_api/api/mcp/_handlers.py +146 -196
  7. langgraph_api/api/mcp/_outcome.py +43 -0
  8. langgraph_api/api/mcp/_protocol.py +224 -0
  9. langgraph_api/config/__init__.py +38 -4
  10. langgraph_api/cron_scheduler.py +2 -2
  11. langgraph_api/drain.py +164 -0
  12. langgraph_api/event_streaming/service.py +130 -133
  13. langgraph_api/event_streaming/session.py +11 -6
  14. langgraph_api/executor/__init__.py +9 -0
  15. langgraph_api/executor/__main__.py +343 -0
  16. langgraph_api/feature_flags.py +6 -0
  17. langgraph_api/graph.py +12 -2
  18. langgraph_api/grpc/ops/runs.py +41 -5
  19. langgraph_api/grpc/ops/threads.py +54 -6
  20. langgraph_api/metrics_otlp.py +8 -0
  21. langgraph_api/models/run.py +11 -3
  22. langgraph_api/queue_entrypoint.py +13 -1
  23. langgraph_api/self_hosted_logs.py +3 -1
  24. langgraph_api/self_hosted_metrics.py +1 -1
  25. langgraph_api/stream.py +49 -3
  26. langgraph_api/timing/__init__.py +16 -0
  27. langgraph_api/timing/startup.py +184 -0
  28. langgraph_api/timing/timer.py +16 -2
  29. langgraph_api/utils/headers.py +20 -3
  30. langgraph_api/validation.py +11 -5
  31. langgraph_api/worker.py +146 -13
  32. langgraph_api/worker_runtime.py +124 -4
  33. {langgraph_api-0.18.0.dev2.dist-info → langgraph_api-0.18.0.dev4.dist-info}/METADATA +1 -1
  34. {langgraph_api-0.18.0.dev2.dist-info → langgraph_api-0.18.0.dev4.dist-info}/RECORD +43 -38
  35. langgraph_grpc_common/proto/__init__.py +4 -4
  36. langgraph_grpc_common/proto/orchestrator_pb2.py +50 -0
  37. langgraph_grpc_common/proto/{runner_pb2.pyi → orchestrator_pb2.pyi} +4 -4
  38. langgraph_grpc_common/proto/orchestrator_pb2_grpc.py +108 -0
  39. langgraph_grpc_common/proto/orchestrator_pb2_grpc.pyi +82 -0
  40. openapi.json +20 -0
  41. langgraph_api/runner/__init__.py +0 -10
  42. langgraph_api/runner/__main__.py +0 -275
  43. langgraph_grpc_common/proto/runner_pb2.py +0 -50
  44. langgraph_grpc_common/proto/runner_pb2_grpc.py +0 -108
  45. langgraph_grpc_common/proto/runner_pb2_grpc.pyi +0 -73
  46. {langgraph_api-0.18.0.dev2.dist-info → langgraph_api-0.18.0.dev4.dist-info}/WHEEL +0 -0
  47. {langgraph_api-0.18.0.dev2.dist-info → langgraph_api-0.18.0.dev4.dist-info}/entry_points.txt +0 -0
  48. {langgraph_api-0.18.0.dev2.dist-info → langgraph_api-0.18.0.dev4.dist-info}/licenses/LICENSE +0 -0
@@ -21,8 +21,8 @@ from __future__ import annotations
21
21
  import asyncio
22
22
  import contextlib
23
23
  import inspect
24
- import time
25
- from collections.abc import Awaitable, Callable
24
+ import re
25
+ from collections.abc import Awaitable, Callable, Mapping
26
26
  from typing import Any, cast, get_args
27
27
  from uuid import UUID, uuid4
28
28
 
@@ -45,6 +45,7 @@ from langgraph_api.event_streaming.session import (
45
45
  from langgraph_api.event_streaming.types import Subscription
46
46
  from langgraph_api.feature_flags import FF_V2_EVENT_STREAMING, PREFER_GRPC_CHECKPOINTER
47
47
  from langgraph_api.schema import MultitaskStrategy
48
+ from langgraph_api.validation import sanitize_reserved_keys
48
49
 
49
50
  logger = structlog.stdlib.get_logger(__name__)
50
51
 
@@ -144,10 +145,24 @@ def _multitask_strategy_from_run_start(params: dict[str, Any]) -> str:
144
145
  EventSink = Callable[[dict[str, Any]], Awaitable[None] | None]
145
146
 
146
147
 
147
- # ``set_joint_status`` commits interrupts after the stream event; gRPC can lag.
148
148
  _IN_FLIGHT_THREAD_STATUS = "busy"
149
- _INTERRUPT_SETTLE_TIMEOUT_SECONDS = 5.0
150
- _INTERRUPT_SETTLE_POLL_INTERVAL_SECONDS = 0.05
149
+ # langgraph resumes interrupts by id only when every key of the resume map has
150
+ # this shape; any other key turns the whole map into one value for whichever
151
+ # interrupt is pending.
152
+ _INTERRUPT_ID_RE = re.compile(r"[0-9a-f]{32}")
153
+
154
+
155
+ class _AmbiguousResumeError(Exception):
156
+ """``run.start`` input would resume several pending interrupts at once."""
157
+
158
+
159
+ def _keyed_by_interrupt_id(value: Any) -> bool:
160
+ """Whether langgraph resumes ``value`` per interrupt rather than as one answer."""
161
+ return (
162
+ _is_record(value)
163
+ and bool(value)
164
+ and all(_INTERRUPT_ID_RE.fullmatch(key) for key in value)
165
+ )
151
166
 
152
167
 
153
168
  # Protocol v2 commands this server implements. Anything outside this
@@ -174,6 +189,9 @@ class ThreadRunManager:
174
189
  One ``ThreadRunManager`` is created per connection (HTTP SSE stream or
175
190
  WebSocket). It is not shared across connections — each observer owns
176
191
  its own view of the thread's run stream.
192
+
193
+ ``replay_buffer=False`` keeps no per-run replay buffer, for connections
194
+ that never replay from it.
177
195
  """
178
196
 
179
197
  def __init__(
@@ -183,11 +201,15 @@ class ThreadRunManager:
183
201
  runs: Any,
184
202
  threads: Any,
185
203
  send_event: EventSink | None = None,
204
+ headers: Mapping[str, str] | None = None,
205
+ replay_buffer: bool = True,
186
206
  ) -> None:
187
207
  self._thread_id = thread_id
188
208
  self._runs = runs
189
209
  self._threads = threads
190
210
  self._send_event = send_event
211
+ self._headers = headers if headers is not None else {}
212
+ self._replay_buffer = replay_buffer
191
213
  self._session: EventStreamingSession | None = None
192
214
  self._current_run_id: str | None = None
193
215
  self._queued_events: list[dict[str, Any]] = []
@@ -271,7 +293,7 @@ class ThreadRunManager:
271
293
  active=True,
272
294
  )
273
295
 
274
- def start_thread_stream(self) -> None:
296
+ def start_thread_stream(self, *, auth_filters: Any = None) -> None:
275
297
  """Start consuming the thread-level stream for this connection.
276
298
 
277
299
  Always start from the beginning of the thread's event stream
@@ -286,14 +308,19 @@ class ThreadRunManager:
286
308
  produce output…". The SSE/WS sink applies the caller's ``since``
287
309
  as a seq filter on outbound events, and the SDK dedups by
288
310
  ``event_id``, so repeat observers don't see duplicates.
311
+
312
+ ``auth_filters`` is what the route's ``check_thread_stream_auth``
313
+ returned, passed on so the stream doesn't run the read handler again.
289
314
  """
290
315
  if self._thread_source_task is not None:
291
316
  return
292
317
  self._thread_source_task = asyncio.create_task(
293
- self._consume_thread_stream(last_event_id="-")
318
+ self._consume_thread_stream(last_event_id="-", auth_filters=auth_filters)
294
319
  )
295
320
 
296
- async def _consume_thread_stream(self, *, last_event_id: str | None) -> None:
321
+ async def _consume_thread_stream(
322
+ self, *, last_event_id: str | None, auth_filters: Any
323
+ ) -> None:
297
324
  try:
298
325
  async for (
299
326
  event,
@@ -304,6 +331,7 @@ class ThreadRunManager:
304
331
  self._thread_id,
305
332
  stream_modes=["run_modes", "lifecycle"],
306
333
  last_event_id=last_event_id,
334
+ auth_filters=auth_filters,
307
335
  ):
308
336
  if not run_id or run_id == "*":
309
337
  continue
@@ -525,6 +553,8 @@ class ThreadRunManager:
525
553
 
526
554
  try:
527
555
  run = await self._create_or_resume_run(assistant_id, params)
556
+ except _AmbiguousResumeError as exc:
557
+ return self._error(command.get("id"), "invalid_argument", str(exc))
528
558
  except ProtocolV2UnsupportedError as exc:
529
559
  return self._error(command.get("id"), "unsupported", str(exc))
530
560
  except Exception as exc:
@@ -562,9 +592,7 @@ class ThreadRunManager:
562
592
  optional ``namespace``) or a ``responses`` batch — a list of
563
593
  ``{interrupt_id, response, namespace?}`` objects. The batch form
564
594
  resumes several interrupts pending at the same checkpoint (e.g.
565
- parallel tool-authorization prompts) in one command; sequential
566
- single resumes cannot, since the first resume starts a run, leaving
567
- the rest with no interrupted run to respond to. Both forms are part
595
+ parallel tool-authorization prompts) in one command. Both forms are part
568
596
  of the streaming protocol (``InputRespondParams`` =
569
597
  ``InputRespondOne / InputRespondMany``); the batch entries are read
570
598
  leniently to tolerate clients pinned to older bindings.
@@ -641,7 +669,7 @@ class ThreadRunManager:
641
669
  # this HTTP request (the stateless ``POST /commands`` transport) its
642
670
  # source task hasn't had a chance to emit ``input.requested`` yet —
643
671
  # ``_pending_interrupts`` is still empty. In that case, fall back to
644
- # the thread-state check (``_collect_settled_interrupt_ids``) so we
672
+ # the thread-row check (``_collect_interrupt_ids_unless_busy``) so we
645
673
  # don't reject legitimate resumes with a fresh handle.
646
674
  #
647
675
  # The thread-state fallback is fetched at most once per batch and
@@ -664,34 +692,27 @@ class ThreadRunManager:
664
692
  "no_such_interrupt",
665
693
  "Interrupt namespace does not match the pending interrupt.",
666
694
  )
667
- # WS can surface ``input.requested`` before postgres/gRPC
668
- # persists the thread-row interrupt. Reuse the HTTP settle
669
- # barrier before enqueueing the resume run.
670
- if not thread_state_fetched:
671
- thread_state_ids = await self._collect_settled_interrupt_ids()
672
- thread_state_fetched = True
673
695
  continue
674
696
  # HTTP fallback: the persisted lookup surfaces interrupts by id
675
697
  # only, so trust the client-claimed namespace and validate by
676
698
  # existence (the id is a namespace hash, so that's sufficient).
677
699
  if not thread_state_fetched:
678
- thread_state_ids = await self._collect_settled_interrupt_ids()
700
+ thread_state_ids = await self._collect_interrupt_ids_unless_busy()
679
701
  thread_state_fetched = True
680
- # Fail open when the lookup is unavailable (``None``): only reject
681
- # when a definitive id set was read and lacks the target. The
682
- # checkpointer resume below is authoritative, so a transient lookup
683
- # failure must not masquerade as a missing interrupt.
684
- if thread_state_ids is not None and interrupt_id not in thread_state_ids:
702
+ # ``None`` means a run is in flight or the lookup failed. Then fail
703
+ # open for any id shaped like an interrupt id: the resume below is
704
+ # authoritative, so neither must masquerade as a missing interrupt.
705
+ if thread_state_ids is None:
706
+ rejected = not _INTERRUPT_ID_RE.fullmatch(interrupt_id)
707
+ else:
708
+ rejected = interrupt_id not in thread_state_ids
709
+ if rejected:
685
710
  return self._error(
686
711
  command.get("id"),
687
712
  "no_such_interrupt",
688
713
  f"Unknown or already-consumed interrupt: {interrupt_id}",
689
714
  )
690
715
 
691
- # At this point we've confirmed every interrupt exists on the
692
- # thread state (or was surfaced via the session). No need for a
693
- # second ``_has_pending_interrupts`` round-trip.
694
-
695
716
  # Resolve the assistant from thread metadata. Run creation keeps
696
717
  # the thread's assistant_id current, avoiding a latest-run search
697
718
  # on stateless command requests.
@@ -768,26 +789,15 @@ class ThreadRunManager:
768
789
  if not capabilities.ok:
769
790
  raise ProtocolV2UnsupportedError(capabilities)
770
791
 
792
+ # Drop server-owned configurable and metadata keys before the run
793
+ # config is built, as the REST request parser does for its bodies.
794
+ sanitize_reserved_keys(params)
771
795
  config = params.get("config") if _is_record(params.get("config")) else {}
772
796
 
773
- current_run = await self._fetch_current_run()
774
-
775
- current_status = None
776
- if current_run is not None:
777
- current_status = (
778
- current_run["status"]
779
- if _is_record(current_run)
780
- else getattr(current_run, "status", None)
781
- )
782
-
783
- has_interrupts = False
784
- if params.get("input") is not None:
785
- has_interrupts = await self._has_pending_interrupts()
786
-
797
+ # ``input.respond`` checked its interrupts already and always resumes.
787
798
  is_resume = params.get("input") is not None and (
788
- params.get("force_resume")
789
- or (current_run is not None and current_status == "interrupted")
790
- or has_interrupts
799
+ bool(params.get("force_resume"))
800
+ or await self._run_start_resumes(params["input"])
791
801
  )
792
802
 
793
803
  run_config: dict[str, Any] = {
@@ -870,12 +880,22 @@ class ThreadRunManager:
870
880
  conn,
871
881
  self._thread_id,
872
882
  run_payload,
873
- {},
883
+ self._headers,
874
884
  run_id=run_id,
875
885
  )
876
886
  except Exception:
877
887
  raise
878
888
 
889
+ # ``input.respond`` clears the interrupts it answered itself.
890
+ if is_resume and not params.get("force_resume") and self._session is not None:
891
+ # Until the stream rebinds to the resumed run, input sent next must
892
+ # not answer these interrupts a second time.
893
+ answered = params["input"]
894
+ if _keyed_by_interrupt_id(answered):
895
+ for interrupt_id in answered:
896
+ self._session.clear_pending_interrupt(interrupt_id)
897
+ else:
898
+ self._session._pending_interrupts.clear()
879
899
  return run
880
900
 
881
901
  async def _ensure_run_session(
@@ -932,6 +952,7 @@ class ThreadRunManager:
932
952
  get_thread_state=self._make_get_thread_state(thread_id),
933
953
  source=None,
934
954
  send=self._make_send(),
955
+ max_buffer_size=None if self._replay_buffer else 0,
935
956
  )
936
957
 
937
958
  self._session = session
@@ -1059,19 +1080,6 @@ class ThreadRunManager:
1059
1080
  # Run lookup
1060
1081
  # ------------------------------------------------------------------
1061
1082
 
1062
- async def _fetch_current_run(self) -> dict[str, Any] | None:
1063
- """Fetch the currently-bound run from storage.
1064
-
1065
- ``Runs.get`` uses keyword-only ``thread_id`` / ``ctx`` args so we
1066
- cannot call it positionally. We also rely on ``ApiRoute``'s
1067
- ``with_user`` to populate the auth context var instead of
1068
- passing ``ctx=self._auth`` (which is a starlette
1069
- ``AuthCredentials``, not a ``BaseAuthContext``).
1070
- """
1071
- if self._current_run_id is None:
1072
- return None
1073
- return await self._fetch_run_by_id(self._current_run_id)
1074
-
1075
1083
  async def _fetch_run_by_id(self, run_id: str) -> dict[str, Any] | None:
1076
1084
  """Fetch a run by id without searching for the latest run."""
1077
1085
  from langgraph_runtime.database import connect # noqa: PLC0415
@@ -1100,38 +1108,8 @@ class ThreadRunManager:
1100
1108
  # Interrupt detection
1101
1109
  # ------------------------------------------------------------------
1102
1110
 
1103
- async def _lookup_interrupt_in_thread_state(
1104
- self, interrupt_id: str
1105
- ) -> list[str] | None:
1106
- """Existence check for ``interrupt_id`` against persisted thread state.
1107
-
1108
- Fallback for ``input.respond`` on stateless HTTP transports, where the
1109
- fresh session hasn't observed ``input.requested`` yet. Backed by the
1110
- durable thread-row map (see :meth:`_collect_persisted_interrupt_ids`).
1111
-
1112
- Returns ``[]`` if the interrupt exists, else ``None``. The ``[]`` is a
1113
- sentinel, not a namespace — the map carries no namespace, so callers
1114
- must treat it as "found, namespace unknown" and trust the client claim.
1115
- """
1116
- found = await self._collect_persisted_interrupt_ids()
1117
- if found is None:
1118
- return None
1119
- return [] if interrupt_id in found else None
1120
-
1121
- async def _collect_persisted_interrupt_ids(self) -> set[str] | None:
1122
- """Collect interrupt ids from the durable thread-row ``interrupts`` map.
1123
-
1124
- ``Threads.set_status`` writes ``{task_id: [{id, value}, ...]}`` onto the
1125
- thread row atomically with the status whenever a run pauses. Reading it
1126
- is a plain row fetch (same ``connect()`` + ``Threads.get`` path as
1127
- :meth:`_get_thread_assistant_id`) — unlike ``Threads.State.get`` it does
1128
- not rebuild the graph, so it can't spuriously raise and reject a
1129
- legitimate resume, and it survives reconnects/redeploys.
1130
-
1131
- Returns the set of interrupt ids (empty when none are pending), or
1132
- ``None`` if the fetch failed — callers treat ``None`` as "unavailable"
1133
- and fall open rather than fabricating ``no_such_interrupt``.
1134
- """
1111
+ async def _fetch_thread_row(self) -> dict[str, Any] | None:
1112
+ """Return the durable thread row, or ``None`` if the fetch failed."""
1135
1113
  from langgraph_runtime.database import connect # noqa: PLC0415
1136
1114
 
1137
1115
  try:
@@ -1146,8 +1124,16 @@ class ThreadRunManager:
1146
1124
  error_type=type(exc).__name__,
1147
1125
  )
1148
1126
  return None
1127
+ return thread if _is_record(thread) else {}
1149
1128
 
1150
- interrupts_map = thread.get("interrupts") if _is_record(thread) else None
1129
+ @staticmethod
1130
+ def _interrupt_ids(thread: dict[str, Any]) -> set[str]:
1131
+ """Ids in the row's ``interrupts`` map, written with the status when a run ends.
1132
+
1133
+ Read instead of ``Threads.State.get``, which rebuilds the graph and can
1134
+ raise, turning a valid answer into ``no_such_interrupt``.
1135
+ """
1136
+ interrupts_map = thread.get("interrupts")
1151
1137
  if not _is_record(interrupts_map):
1152
1138
  return set()
1153
1139
  found: set[str] = set()
@@ -1162,50 +1148,61 @@ class ThreadRunManager:
1162
1148
  found.add(entry_id)
1163
1149
  return found
1164
1150
 
1165
- async def _fetch_thread_status(self) -> str | None:
1166
- """Return durable thread status, or ``None`` if unreadable."""
1167
- from langgraph_runtime.database import connect # noqa: PLC0415
1151
+ async def _collect_interrupt_ids_unless_busy(self) -> set[str] | None:
1152
+ """Persisted interrupt ids, or ``None`` while a run is in flight.
1168
1153
 
1169
- try:
1170
- async with connect() as conn:
1171
- result = await self._threads.get(conn, self._thread_id)
1172
- thread = await anext(result) if hasattr(result, "__anext__") else result
1173
- except Exception:
1174
- return None
1175
- status = thread.get("status") if _is_record(thread) else None
1176
- return status if isinstance(status, str) else None
1177
-
1178
- async def _collect_settled_interrupt_ids(self) -> set[str] | None:
1179
- """Persisted interrupt ids, polling while the thread is still ``busy``."""
1180
- ids = await self._collect_persisted_interrupt_ids()
1181
- if ids is None:
1154
+ Interrupts reach the row map only when their run ends, so while one
1155
+ is in flight the map can't say which interrupts are pending: that run
1156
+ may raise new ones or answer listed ones before it pauses. ``None``
1157
+ makes ``input.respond`` fail open; the resume run queues behind the
1158
+ in-flight one, and langgraph applies it, or ignores an id that is no
1159
+ longer pending, once that run pauses. Status and map come from one
1160
+ read, so a failed read can't pass for a thread that isn't busy.
1161
+ """
1162
+ thread = await self._fetch_thread_row()
1163
+ if thread is None or thread.get("status") == _IN_FLIGHT_THREAD_STATUS:
1182
1164
  return None
1183
- if ids:
1184
- return ids
1185
- deadline = time.monotonic() + _INTERRUPT_SETTLE_TIMEOUT_SECONDS
1186
- while True:
1187
- status = await self._fetch_thread_status()
1188
- if status != _IN_FLIGHT_THREAD_STATUS:
1189
- return await self._collect_persisted_interrupt_ids()
1190
- if time.monotonic() >= deadline:
1191
- return set()
1192
- await asyncio.sleep(_INTERRUPT_SETTLE_POLL_INTERVAL_SECONDS)
1193
- ids = await self._collect_persisted_interrupt_ids()
1194
- if ids is None:
1195
- return None
1196
- if ids:
1197
- return ids
1198
-
1199
- async def _has_pending_interrupts(self) -> bool:
1200
- # Prefer the session's in-memory pending interrupts (populated the
1201
- # instant ``input.requested`` surfaces) to skip a DB round-trip;
1202
- # otherwise consult the durable thread-row map. A lookup failure
1203
- # (``None``) reads as "none pending" — ``run.start`` then falls back to
1204
- # the ``current_status == "interrupted"`` signal for resume-vs-start.
1205
- if self._session is not None and self._session._pending_interrupts:
1165
+ return self._interrupt_ids(thread)
1166
+
1167
+ async def _run_start_resumes(self, value: Any) -> bool:
1168
+ """Whether ``run.start`` input answers the interrupts the thread is paused on.
1169
+
1170
+ Decided without waiting, from one read of the thread row. Interrupts
1171
+ reach the row only when their run ends, so while a run is in flight the
1172
+ input is a new run for the multitask strategy (``enqueue``, the default,
1173
+ queues it behind the running one), never an answer for whichever
1174
+ interrupt is open when that run pauses. The exception is the run this
1175
+ connection streams: the session reports it ``interrupted`` as soon as it
1176
+ raises an interrupt, so input sent after that answers the streamed
1177
+ interrupts, until this connection resumes them or that run ends. When
1178
+ the row can't be read, the streamed interrupts decide. The last run's
1179
+ status isn't consulted: a run that pauses on an interrupt ends
1180
+ ``success``, and ``interrupted`` means it was cancelled; any interrupt it
1181
+ left open is in the row.
1182
+
1183
+ Raises ``_AmbiguousResumeError`` when the input would answer several
1184
+ interrupts and isn't keyed by interrupt id.
1185
+ """
1186
+ if _keyed_by_interrupt_id(value):
1206
1187
  return True
1207
- found = await self._collect_settled_interrupt_ids()
1208
- return bool(found)
1188
+ session = self._session
1189
+ streamed = set(session._pending_interrupts) if session is not None else set()
1190
+ thread = await self._fetch_thread_row()
1191
+ if thread is None:
1192
+ paused_on = streamed
1193
+ elif thread.get("status") == _IN_FLIGHT_THREAD_STATUS:
1194
+ paused_on = set() if session is None or session.run_done else streamed
1195
+ else:
1196
+ paused_on = self._interrupt_ids(thread)
1197
+ if len(paused_on) > 1:
1198
+ # One answer can't say which of several pending interrupts it is
1199
+ # for: langgraph fails the run, or picks one when they share a
1200
+ # subgraph task.
1201
+ raise _AmbiguousResumeError(
1202
+ f"run.start input can't say which of the {len(paused_on)} "
1203
+ "pending interrupts it answers; answer them with input.respond."
1204
+ )
1205
+ return bool(paused_on)
1209
1206
 
1210
1207
  # ------------------------------------------------------------------
1211
1208
  # Command forwarding
@@ -228,8 +228,8 @@ class EventStreamingSession:
228
228
  ) -> None:
229
229
  if max_buffer_size is None:
230
230
  max_buffer_size = LSD_PROTOCOL_V2_BUFFER_SIZE
231
- if max_buffer_size < 1:
232
- raise ValueError("max_buffer_size must be a positive integer")
231
+ if max_buffer_size < 0:
232
+ raise ValueError("max_buffer_size must be zero or a positive integer")
233
233
  self._run_id = run_id
234
234
  self._thread_id = thread_id
235
235
  self._initial_run = initial_run
@@ -251,12 +251,14 @@ class EventStreamingSession:
251
251
  self._buffer: list[dict[str, Any]] = []
252
252
  self._source_task: asyncio.Task[None] | None = None
253
253
  self._next_seq = 0
254
+ # 0 keeps no replay buffer, for transports that never replay from it.
254
255
  self._max_buffer_size = max_buffer_size
255
256
  self._root_graph_name = "root"
256
257
  self._terminal_lifecycle_emitted = False
257
258
  # Maps interrupt_id -> namespace that emitted it, so ``input.respond``
258
259
  # from the client can be verified against the originating subgraph.
259
260
  self._pending_interrupts: dict[str, Namespace] = {}
261
+ self.run_done = False
260
262
  # Latches once the underlying transport starts rejecting sends so
261
263
  # we don't spam the logs for every subsequent event on a dead
262
264
  # WebSocket / SSE stream. The session is torn down by ``close()``
@@ -374,6 +376,7 @@ class EventStreamingSession:
374
376
 
375
377
  async def complete(self) -> None:
376
378
  """Emit terminal lifecycle when an external source reports run completion."""
379
+ self.run_done = True
377
380
  await self._emit_terminal_lifecycle()
378
381
 
379
382
  async def handle_event_streaming_command(
@@ -971,7 +974,8 @@ class EventStreamingSession:
971
974
  return _synth_event_id(self._run_id, str(self._next_seq))
972
975
 
973
976
  async def _push_event(self, event: dict[str, Any]) -> None:
974
- self._buffer.append(event)
977
+ if self._max_buffer_size:
978
+ self._buffer.append(event)
975
979
  reporter = get_otlp_metrics_reporter()
976
980
  if len(self._buffer) > self._max_buffer_size:
977
981
  evicted = len(self._buffer) - self._max_buffer_size
@@ -1036,9 +1040,10 @@ class EventStreamingSession:
1036
1040
  callback for events with ``seq > since`` that match the filter,
1037
1041
  then the subscription is activated so live events flow.
1038
1042
 
1039
- Returns the number of events replayed. Used by both the WebSocket
1040
- ``subscription.subscribe`` command and the SSE event stream, which
1041
- accept a body ``since`` cursor to resume after a reconnect.
1043
+ Returns the number of events replayed. Used by the WebSocket
1044
+ ``subscription.subscribe`` and ``subscription.reconnect`` commands;
1045
+ ``since`` resumes after a reconnect. SSE streams replay from the
1046
+ thread's event stream instead.
1042
1047
 
1043
1048
  Raises :class:`ResumeGap` when *since* is older than the
1044
1049
  session's retained buffer head. This lets callers surface a
@@ -0,0 +1,9 @@
1
+ """Process-isolated graph executor for the Go multi-process queue worker.
2
+
3
+ Entrypoint: ``python -m langgraph_api.executor``
4
+
5
+ Opens single-dispatch bidi streams to the Orchestrator service at
6
+ ``LANGGRAPH_ORCHESTRATOR_ADDRESS``.
7
+
8
+ This module intentionally avoids importing the HTTP/SSE server stack.
9
+ """