fix(ai): offload model resolution from async paths

Wrap blocking _resolve_model calls in asyncio.to_thread across async model interaction paths so endpoint/model resolution does not stall the event loop. Preserve owner-scoped resolution and add focused regression coverage.
This commit is contained in:
tanmayraut45
2026-06-28 05:18:35 +05:30
committed by GitHub
parent 8b110c28e6
commit c01c09559a
8 changed files with 80 additions and 14 deletions
+3 -2
View File
@@ -25,9 +25,10 @@ def test_model_listing_and_image_fallback_are_owner_scoped():
assert "owner: Optional[str] = None" in list_body
assert "owner_filter(query, ModelEndpoint, owner)" in list_body
assert "_resolve_model(candidate, owner=owner)" in image_body
# _resolve_model is offloaded to a worker thread (#4589) but stays owner-scoped.
assert "asyncio.to_thread(_resolve_model, candidate, owner=owner)" in image_body
assert "owner_filter(_img_q, ModelEndpoint, owner)" in image_body
assert "_resolve_model(model_spec, owner=owner)" in image_body
assert "asyncio.to_thread(_resolve_model, model_spec, owner=owner)" in image_body
# chat_with_model, list_models and ask_teacher moved to the registry (#3629)