Skip to content

Commit a34f84e

Browse files
committed
chore(_task_compat): harden callback suppress + close coro on unsupported backend
1 parent 33f686d commit a34f84e

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/claude_agent_sdk/_internal/_task_compat.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ def _mark_done(self, exc: BaseException | None) -> None:
9999
self._exception = exc
100100
self._done_event.set()
101101
for cb in self._callbacks:
102-
with suppress(Exception):
102+
# Suppress BaseException so a misbehaving callback can never
103+
# propagate out of the system-task _runner (which would crash
104+
# trio with TrioInternalError). The actual callbacks used here
105+
# are set.discard / dict.pop, so this is purely defensive.
106+
with suppress(BaseException):
103107
cb(self)
104108
self._callbacks.clear()
105109

@@ -146,6 +150,9 @@ async def _runner() -> None:
146150

147151
trio.lowlevel.spawn_system_task(_runner)
148152
return handle
153+
# Unsupported backend: close the coroutine so we don't leak a "coroutine
154+
# was never awaited" RuntimeWarning on top of the RuntimeError.
155+
coro.close()
149156
raise RuntimeError(
150157
f"Unsupported async backend: {backend!r}. "
151158
"claude_agent_sdk requires asyncio or trio."

0 commit comments

Comments
 (0)