-
Notifications
You must be signed in to change notification settings - Fork 3
Sync Cohere client blocks async event loop on every LLM call #1
Copy link
Copy link
Closed
Labels
GrantFox OSSIssue tracked in GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardIssue may be eligible for a GrantFox rewardOfficial Campaign | FWC26Campaign: Official Campaign | FWC26Campaign: Official Campaign | FWC26bugSomething isn't workingSomething isn't workinghelp wantedExtra attention is neededExtra attention is needed
Description
Activity
Metadata
Metadata
Assignees
Labels
GrantFox OSSIssue tracked in GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardIssue may be eligible for a GrantFox rewardOfficial Campaign | FWC26Campaign: Official Campaign | FWC26Campaign: Official Campaign | FWC26bugSomething isn't workingSomething isn't workinghelp wantedExtra attention is neededExtra attention is needed
What
The
CohereClientclass atsrc/services/cohere_client.py:23instantiatescohere.ClientV2(the synchronous Cohere SDK client). All methods —generate(),generate_json(), andembed()— are declaredasyncand awaited by callers, but the underlying.chat()and.embed()calls execute synchronously on the main asyncio event loop thread.Why
Every LLM/embedding call freezes the entire FastAPI server for the duration of the Cohere API request (typically 1-10 seconds). Under concurrent requests, the server becomes effectively single-threaded — all other requests queue behind the blocking call. This makes the service unable to handle concurrent users and defeats the purpose of using FastAPI/async.
Scope
In scope:
cohere.ClientV2withcohere.AsyncClientV2in the Cohere clientawaiton the async client methodsOut of scope:
Acceptance Criteria
CohereClientusescohere.AsyncClientV2instead ofcohere.ClientV2generate(),generate_json(), andembed()methods are truly asyncruff check src/ tests/passespytestpassesTechnical Context
File to modify:
src/services/cohere_client.py— classCohereClient(line 23)Current code:
Fix:
The
AsyncClientV2has the same method signatures but returns awaitable coroutines. All callers alreadyawaitthe results, so no caller changes should be needed.Callers:
src/services/generation.py— course generationsrc/services/quiz_generator.py— quiz generationsrc/services/feedback_engine.py— feedback generationsrc/services/embedding.py— embedding generationscripts/build_index.py— knowledge base index builder