fix(agent): add timeout handling for local agent class resolution to prevent deadlocks on Windows #533
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.
📝 Pull Request Template
1. Related Issue
Closes # (issue number)
2. Type of Change (select one)
Bug Fix
3. Description
Problem
Using
asyncio.to_thread(_resolve_local_agent_class, spec)occasionally hangs on Windows during request handling.Root cause (short)
asyncio.to_threadrunsimport_modulein a worker thread; if the main thread (or another thread) is also importing or holding resources, the worker can block waiting for the import lock while the main thread waits for the worker — producing a deadlock-like hang.Why it shows up in this codepath
_build_local_agent), so any blocking stalls the request pipeline between “Resolved prompt” and “Launching in-process agent”.Short mitigations
asyncio.to_threadwithasyncio.wait_for(..., timeout=5s)and fall back to sync_resolve_local_agent_classon timeout.4. Testing
5. Checklist