Skip to content

bug: check_system_health tool uses bare asyncio.run() — crash risk in async context #35

@G9000

Description

@G9000

Summary

check_system_health (tools.py:748-762) calls asyncio.run(registry.run_all(...)). This works today only because sync tools run in a thread pool via run_in_executor. But unlike recall_memory and recall_conversation (which use run_coroutine_threadsafe with fallback), this will crash with RuntimeError: asyncio.run() cannot be called from a running event loop if the tool ever runs in an async context.

Fix

Use the same pattern as recall_memory (lines 399-415):

try:
    loop = asyncio.get_running_loop()
except RuntimeError:
    loop = None

if loop is not None:
    report = asyncio.run_coroutine_threadsafe(
        registry.run_all(user_id=ctx.user_id), loop
    ).result(timeout=30)
else:
    report = asyncio.run(registry.run_all(user_id=ctx.user_id))

Files

  • apps/server/src/anima_server/services/agent/tools.py:748-762

Severity

High — crash if call path changes (tool becomes async, executor dispatches differently).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions