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).
Labels: bug, async, performance
Severity: S1. The
sync_in_asynchonesty rule only detectssession_scope(); these blocking calls pass the audit.platform/tools/knowledge.py:77,169KnowledgeStoreTool.forward/KnowledgeQueryTool.forwardareasync defand callmodel.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 beto_thread-wrapped by the dispatcherplatform/services/embedding.py:50,83BGEProvider.embed/MiniLMProvider.embedare syncmodel.encode(...);KnowledgeServicecalls them from async pathsstorage/database.py:230(backup_database)async defrunssubprocess.run(["pg_dump", ...], timeout=300)synchronously -> blocks the loop for the full dump (up to 300s)modules/forensics/services/offline_installer.py:197,208,327async def prepare_pip_wheels/_install_apt_offlinerunsubprocess.run(["pip"/"apt-get", "download", ...], timeout=600/120)synchronously on the loopmodules/vulnerability/providers/nvd.py:95,144(+epss.py,kev.py)httpx.Client+time.sleep()in the async provider chain (reinforces #55)Architectural inconsistency (module to_thread ban):
HONESTY_AUDIT.mdbans modules undersrc/aila/modules/fromasyncio.to_thread/ThreadPoolExecutor, somodules/vulnerability/reporting/pdf.py:104andmodules/vr/reporting/pdf_report.py:186run weasyprint (CPU-bound, no async API) on the event loop by policy. Butmodules/malware/services/target_analysis.py:1161,modules/vr/services/target_analysis.py:1148, andmodules/vr/api_router.py:3527(MASVS PDF) all callasyncio.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, andpip/apt downloadoff the loop (sync helper + platform-boundaryto_thread, or an async driver); provider I/O useshttpx.AsyncClient+asyncio.sleep; broaden thesync_in_asyncaudit rule to also flagsubprocess.run,time.sleep, synchttpx.Client, andmodel.encodeinside anasync defbody; settle the module to_thread policy (either allow a sanctioned offload helper or enforce the ban consistently).