SkillSpector
SkillSpector copied to clipboard
fix(async): handle nested event loops in asyncio.run calls
Summary
This fix allows SkillSpector to run in environments that already have a running event loop, preventing RuntimeError when asyncio.run() is called from within an existing loop.
Problem
When running SkillSpector in environments like:
- Jupyter Notebooks
- LangGraph Studio
- FastAPI applications
- Any programmatic usage within async code
The call to asyncio.run() throws a RuntimeError: This event loop is already running and falls back to unfiltered static findings, silently disabling LLM analysis.
Solution
Added detection for running event loops:
- If a loop is already running, use
loop.run_until_complete()to execute the async task - If no loop is running, fall back to standard
asyncio.run()
This maintains backward compatibility while supporting nested loop environments.
Testing
- Run SkillSpector in a Jupyter notebook with LLM analysis enabled
- Before this fix: RuntimeError occurs, LLM analysis is silently skipped
- After this fix: LLM analysis runs successfully
Impact
- Compatibility: Full - works in both standalone and nested loop environments
- Behavior: Fixes silent fallback to unfiltered findings
- Performance: No impact - minimal loop detection overhead
Fixes #108