fix(sdk): preserve queued events on stream close

Signed-off-by: Lanre Shittu <136805224+Shizoqua@users.noreply.github.com>
This commit is contained in:
Lanre Shittu
2026-09-03 16:47:23 +08:00
committed by Xubin Ren
parent 972cdde8da
commit 816a999cac
3 changed files with 27 additions and 7 deletions
+1 -1
View File
@@ -302,7 +302,7 @@ class Nanobot:
))
raise
finally:
emitter.close()
await emitter.close()
task = asyncio.create_task(_run())
return RunStream(task, queue)
+2 -6
View File
@@ -158,15 +158,11 @@ class SDKStreamEmitter:
resuming=resuming,
))
def close(self) -> None:
async def close(self) -> None:
if self._closed:
return
self._closed = True
if self._queue.full():
with suppress(asyncio.QueueEmpty):
self._queue.get_nowait()
with suppress(asyncio.QueueFull):
self._queue.put_nowait(_STREAM_SENTINEL)
await self._queue.put(_STREAM_SENTINEL)
class SDKStreamingHook(AgentHook):