Skip to content

Commit 8f16e57

Browse files
committed
Python: fix(core): record the stream error before closing on failure paths
The reorder in d8b7a39 closed the stream before _handle_stream_error ran. close() consumes the one-shot cleanup hook run with no _stream_error set, so observability hooks recorded the failure without error.type and any retry/persistence hook saw an already-finalized stream. Run the error handling first and close in a finally so the provider stream is still released when a hook raises. Signed-off-by: Yufeng He <[email protected]>
1 parent d8b7a39 commit 8f16e57

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

  • python/packages/core/agent_framework

‎python/packages/core/agent_framework/_types.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4012,8 +4012,14 @@ async def __anext__(self) -> UpdateT:
40124012
await self._finish_consumption()
40134013
raise
40144014
except Exception as exc:
4015-
await self.close()
4016-
await self._handle_stream_error(exc)
4015+
# Run the error-scoped cleanup hooks first: they read
4016+
# self._stream_error, and close() would consume the one-shot
4017+
# cleanup run without it. close() still runs in finally so the
4018+
# provider stream is released even when a hook raises.
4019+
try:
4020+
await self._handle_stream_error(exc)
4021+
finally:
4022+
await self.close()
40174023
raise
40184024
async def close(self) -> None:
40194025
"""Close the active iterator and run cleanup hooks.

0 commit comments

Comments
 (0)