Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: address Copilot review comments on release_session
  • Loading branch information
PratikWayase committed Jul 31, 2026
commit 777b695b6c1cc449b03ed6bd0ac948990f441fbc
Original file line number Diff line number Diff line change
Expand Up @@ -319,24 +319,29 @@ async def release_session(self, session_id: str, *, cancel_running: bool = True)
session_id: The session ID to release.
cancel_running: If True, cancel pending asyncio.Tasks safely.
"""



runtime = self._runtime.get(session_id)
Comment thread
PratikWayase marked this conversation as resolved.
Resolved
if runtime is None:
return

pending = [t for t in runtime.in_flight_tasks.values() if not t.done()]
tasks = list(runtime.in_flight_tasks.values())
Comment thread
PratikWayase marked this conversation as resolved.
Resolved
pending = [t for t in tasks if not t.done()]

if pending and not cancel_running:
raise RuntimeError(
f"Cannot release session {session_id}: {len(pending)} tasks still running."
)

if pending:
if cancel_running and pending:
Comment thread
PratikWayase marked this conversation as resolved.
Resolved
for task in pending:
task.cancel()

await asyncio.wait(pending, return_when=asyncio.ALL_COMPLETED)

if tasks:
await asyncio.gather(*tasks, return_exceptions=True)

self._runtime.pop(session_id, None)

runtime.in_flight_tasks.clear()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,16 @@ async def test_release_session_cancels_and_clears() -> None:
runtime = provider._runtime.get(session.session_id)
assert runtime is not None
assert len(runtime.in_flight_tasks) == 1

task = next(iter(runtime.in_flight_tasks.values()))

await provider.release_session(session.session_id, cancel_running=True)

assert task.done()
assert task.cancelled()
assert runtime.in_flight_tasks == {}
assert runtime.background_sessions == {}

assert session.session_id not in provider._runtime
Comment thread
PratikWayase marked this conversation as resolved.
Resolved


Expand Down
Loading