Skip to content

bug: AgentClient.start() crashes with RuntimeError: Event loop is closed on second call #318

Description

@shaileshpadave

AgentClient.start() crashes with 'RuntimeError: Event loop is closed' on the second call in the same process.

httpx.AsyncClient is cached as an instance variable. Each call to start() goes through asyncio.run() which creates and closes a new event loop. The cached client's transport is bound to the old closed loop, so the next call fails when httpx tries to use it.

Repro: call runtime.client.start(agent, prompt) twice in the same process — second call blows up. Confirmed by test_suite24 test_start_returns_handle_then_joins.

Fix is to check the current loop id in _get_client() and recreate the client if the loop has changed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions