用户引导沙箱优化

This commit is contained in:
董宏凯 committed 2026-08-26 14:14:26 +08:00
1 parent 21f3787b8b
commit 910cee9e67
8 files changed
+604 -224

No files matched your search

@@ -1243,12 +1243,19 @@ async def sse_consumer(
The ``finally`` block implements ``on_disconnect`` semantics:
- ``cancel``: abort the background task on client disconnect.
- ``continue``: let the task run; events are discarded.
- ``continue``: let the task run so the client can ``joinStream``.
``is_disconnected()`` is only consulted in cancel mode. In continue
(resumable) mode a false-positive disconnect would *cleanly* end the
HTTP stream; the LangGraph SDK treats that as success, clears
``lg:stream:{threadId}``, and flips ``isLoading`` off — while the
backend run keeps the thread occupied, so the next send 409s.
A truly gone client fails on the next ``yield`` instead.
"""
last_event_id = request.headers.get("Last-Event-ID")
try:
async for entry in bridge.subscribe(record.run_id, last_event_id=last_event_id):
if await request.is_disconnected():
if record.on_disconnect == DisconnectMode.cancel and await request.is_disconnected():
break
if entry is HEARTBEAT_SENTINEL:
@@ -1261,6 +1268,9 @@ async def sse_consumer(
yield format_sse(entry.event, entry.data, event_id=entry.id or None)
except (ConnectionError, BrokenPipeError, ConnectionResetError, ConnectionAbortedError):
logger.info("SSE client connection lost run_id=%s thread_id=%s", record.run_id, record.thread_id)
finally:
if record.status in (RunStatus.pending, RunStatus.running):
if record.on_disconnect == DisconnectMode.cancel: