SkillSpector icon indicating copy to clipboard operation
SkillSpector copied to clipboard

fix(async): handle nested event loops in asyncio.run calls

Open array-cat opened this issue 5 months ago • 0 comments

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

  1. Run SkillSpector in a Jupyter notebook with LLM analysis enabled
  2. Before this fix: RuntimeError occurs, LLM analysis is silently skipped
  3. 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

array-cat avatar Jun 20 '26 09:06 array-cat