Skip to content

BUG: Event-loop blocking -- sync CPU/IO in async paths not caught by sync_in_async #64

Description

@echel0nn

Labels: bug, async, performance
Severity: S1. The sync_in_async honesty rule only detects session_scope(); these blocking calls pass the audit.

Finding (path:line) Issue
platform/tools/knowledge.py:77,169 KnowledgeStoreTool.forward / KnowledgeQueryTool.forward are async def and call model.encode(...) (synchronous CPU, BGE-M3/MiniLM, 100ms-2s on CPU) inline on the event loop; _get_embedding_model() also loads the model synchronously on first call. Since the forward is async it cannot be to_thread-wrapped by the dispatcher
platform/services/embedding.py:50,83 BGEProvider.embed / MiniLMProvider.embed are sync model.encode(...); KnowledgeService calls them from async paths
storage/database.py:230 (backup_database) async def runs subprocess.run(["pg_dump", ...], timeout=300) synchronously -> blocks the loop for the full dump (up to 300s)
modules/forensics/services/offline_installer.py:197,208,327 async def prepare_pip_wheels / _install_apt_offline run subprocess.run(["pip"/"apt-get", "download", ...], timeout=600/120) synchronously on the loop
modules/vulnerability/providers/nvd.py:95,144 (+ epss.py, kev.py) Sync httpx.Client + time.sleep() in the async provider chain (reinforces #55)

Architectural inconsistency (module to_thread ban): HONESTY_AUDIT.md bans modules under src/aila/modules/ from asyncio.to_thread/ThreadPoolExecutor, so modules/vulnerability/reporting/pdf.py:104 and modules/vr/reporting/pdf_report.py:186 run weasyprint (CPU-bound, no async API) on the event loop by policy. But modules/malware/services/target_analysis.py:1161, modules/vr/services/target_analysis.py:1148, and modules/vr/api_router.py:3527 (MASVS PDF) all call asyncio.to_thread -- either whitelisted or the audit rule has a gap. The rule is inconsistently enforced, and CPU-bound module work has no consistent offload story.

Acceptance: move model.encode, pg_dump, and pip/apt download off the loop (sync helper + platform-boundary to_thread, or an async driver); provider I/O uses httpx.AsyncClient + asyncio.sleep; broaden the sync_in_async audit rule to also flag subprocess.run, time.sleep, sync httpx.Client, and model.encode inside an async def body; settle the module to_thread policy (either allow a sanctioned offload helper or enforce the ban consistently).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions