Skip to content

Commit bc01962

Browse files
declan-scaleclaude
andcommitted
fix(adk): make aclose calls type-safe on AsyncIterator (AGX1-391)
The resume backstop and its tests called .aclose() directly on streams typed AsyncIterator (only AsyncGenerator exposes aclose), failing the pyright lint. Guard via getattr like the existing source-stream close, keeping runtime behavior identical. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 226789c commit bc01962

4 files changed

Lines changed: 12 additions & 4 deletions

File tree

src/agentex/lib/adk/_modules/_claude_code_sync.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ async def convert_claude_code_to_agentex_events(
9191
async for event in inner:
9292
yield event
9393
finally:
94-
await inner.aclose()
94+
inner_aclose = getattr(inner, "aclose", None)
95+
if inner_aclose is not None:
96+
await inner_aclose()
9597
aclose = getattr(lines, "aclose", None)
9698
if aclose is not None:
9799
await aclose()

src/agentex/lib/adk/_modules/_codex_sync.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,9 @@ async def convert_codex_to_agentex_events(
543543
async for event in inner:
544544
yield event
545545
finally:
546-
await inner.aclose()
546+
inner_aclose = getattr(inner, "aclose", None)
547+
if inner_aclose is not None:
548+
await inner_aclose()
547549
aclose = getattr(events, "aclose", None)
548550
if aclose is not None:
549551
await aclose()

tests/lib/adk/test_claude_code_turn.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,5 +345,7 @@ async def _lines():
345345
# Consume only the first event, then close the stream early.
346346
async for _ in events:
347347
break
348-
await events.aclose()
348+
events_aclose = getattr(events, "aclose", None)
349+
assert events_aclose is not None
350+
await events_aclose()
349351
assert closed["value"] is True

tests/lib/adk/test_codex_turn.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,5 +335,7 @@ async def _events():
335335
gen = turn.events
336336
async for _ in gen:
337337
break
338-
await gen.aclose()
338+
gen_aclose = getattr(gen, "aclose", None)
339+
assert gen_aclose is not None
340+
await gen_aclose()
339341
assert closed["value"] is True

0 commit comments

Comments
 (0)