fix: guard agents.models import in warm_up_llm against cross-thread partial-import race (#1248) - #1252
Open
not-knope wants to merge 1 commit into
Open
Conversation
…artial-import race (usestrix#1248) Wait on an Event for the agents graph instead of joining the whole warm-up thread, so LiteLLM/Docker/Caido still overlap model preflight.
Contributor
Greptile SummaryThis PR serializes the first cross-thread
Confidence Score: 5/5The PR appears safe to merge, with no concrete blocking or independently actionable non-blocking issue identified. The new wait covers both model-preflight entry paths, releases safely on failed warm-up attempts, and does not block completion of unrelated background imports. Important Files Changed
Reviews (1): Last reviewed commit: "fix: guard agents.models import in warm_..." | Re-trigger Greptile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
KeyError: 'agents.models'becausewarm_up_llmimportedagents.models.interfaceon the main thread while the perf: take heavy imports off the startup path and pre-warm them in the background #1141 daemon was still populating that package (#1248).Event(_agents_models_ready) released afterstrix.core.runnerfinishes (it loadsagents.models) or fails.wait_for_agents_models()blocks on that Event only — it does notjoin()the warm-up thread — then the original import runs. LiteLLM / Caido / Docker keep overlapping model preflight.finallyso a failed warm-up (missing optional deps, etc.) cannot deadlock waiters._purge_orphaned_modulesis unchanged.--resumeshares thiswarm_up_llmpath, so it is covered rather than regressed.Test plan
uv run pytest tests/test_import_warmup.py(8 passed), including: wait is a no-op without warm-up; wait does not join remaining modules; wait returns when the graph import fails;from agents.models.interface import ModelTracingafter the wait succeeds.ruff check/ruff format --check/mypyon the touched files.main()with Docker stubbed using--target http://example.com --instruction-file … --scan-mode quick --max-budget 2 --non-interactive: import survives; process reaches real model preflight (401 on a dummy key), notKeyError.wait_for_agents_models()returns withLLM_API_KEYunset (warm-up is import-only).pull_docker_image()is a local inspect, a few hundred milliseconds). 3/3 runs, noKeyError: 'agents.models'. The process gets past import warm-up and reaches live model preflight.Real CLI logs (macOS arm64, source install, image cached)
STRIX_LLM=anthropic/claude-sonnet-5, dummyLLM_API_KEY(enough to prove we get past the import; the original crash happened before any provider call).Run 1/2/3 — all exit 1 at preflight, none at
agents.models:Exit 1 is expected (invalid key). Before this fix the same command died at
warm_up_llmwithKeyError: 'agents.models'and never sent a request.Closes #1248.
Related: #1230 (same crash site on
--resume; this guards that import without a full-thread join).