[BUG] KeyError: 'agents' — race condition between llm/warmup.py background thread and strix.report import chain
Describe the bug
strix --target <any target> crashes on startup, 100% reproducible, before any scan output appears. The crash is a race condition: start_import_warmup() (strix/interface/main.py:436) spawns a daemon thread that pre-imports strix.core.runner, which imports the agents package (openai-agents SDK) at module level. 18 lines later, the main thread reaches strix.report.dedupe, which also imports from agents. Both threads touch the agents package almost simultaneously, and Python's per-module import lock doesn't fully serialize this pattern — the parent module gets dropped from sys.modules mid-import, producing KeyError: 'agents'.
Confirmed this only reproduces with code that includes the warmup thread — could not reproduce against PyPI strix-agent==1.0.4 (predates warmup.py) with the identical import chain.
To Reproduce Steps to reproduce the behavior:
git clonethe repouv syncuv run strix --target http://localhost:3000(or any target)- Crash occurs deterministically, every run, regardless of target
Expected behavior Strix starts normally and proceeds to recon/scanning.
Traceback (most recent call last): File ".../.venv/bin/strix", line 12, in <module> sys.exit(main()) File ".../strix/interface/main.py", line 454, in main from strix.report.state import get_global_report_state File ".../strix/report/__init__.py", line 3, in <module> from strix.report.dedupe import check_duplicate File ".../strix/report/dedupe.py", line 10, in <module> from agents.model_settings import ModelSettings File ".../.venv/lib/python3.12/site-packages/agents/model_settings.py", line 17, in <module> from .retry import ( File "<frozen importlib._bootstrap>", line 1360, in _find_and_load File "<frozen importlib._bootstrap>", line 1337, in _find_and_load_unlocked KeyError: 'agents'
System Information:
- OS: Ubuntu 24.04 (WSL2 on Windows)
- Strix Version or Commit: 1.5.3 (built from source,
uv sync) - Python Version: 3.12.3
- LLM Used: openrouter/deepseek/deepseek-v4-flash-0731
Additional context
Workaround: removing "strix.core.runner" from WARMUP_MODULES in strix/llm/warmup.py eliminates the race; the rest of the warmup (litellm, caido_sdk_client, docker) still works fine:
python WARMUP_MODULES = ( "litellm", "caido_sdk_client", "docker", )
Suggested fix: drop strix.core.runner from the warmup list, or synchronously pre-import agents/agents.model_settings in the main thread before calling start_import_warmup(), so the background thread finds it already in sys.modules.
Hi! I'd like to take this one.
From the traceback and investigation, it looks like a startup race between the import warmup thread and the main thread, where both end up importing the agents package at nearly the same time. I'll investigate the warmup sequence and implement a fix that preserves the warmup optimization while avoiding the concurrent import race (whether that's by adjusting the warmup modules, changing the import order, or another appropriate approach).
If no one is already working on this, could you please assign it to me? Thanks!
A fix is available in https://github.com/usestrix/strix/pull/1243
This addresses the import race described here while retaining the background warm-up optimization. The main thread now waits after startup I/O and before either the non-interactive or interactive scan phase enters the warmed dependency graph.
The fix was validated with 1679 passing tests, focused concurrency tests, and a PyInstaller binary built from the PR branch. The official v1.6.1 binary reproduces the startup crash, while the patched binary completes import bootstrap and reaches model preflight successfully.