Skip to content

Commit 490dc9a

Browse files
Refactor WebSocket and process request handling to remove context variable dependency
1 parent 891853a commit 490dc9a

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

src/backend/v3/api/router.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import asyncio
2-
import contextvars
32
import json
43
import logging
54
import uuid
@@ -19,8 +18,8 @@
1918
from semantic_kernel.agents.runtime import InProcessRuntime
2019
from v3.common.services.plan_service import PlanService
2120
from v3.common.services.team_service import TeamService
22-
from v3.config.settings import (connection_config, current_user_id,
23-
orchestration_config, team_config)
21+
from v3.config.settings import (connection_config, orchestration_config,
22+
team_config)
2423
from v3.orchestration.orchestration_manager import OrchestrationManager
2524

2625
router = APIRouter()
@@ -41,8 +40,6 @@ async def start_comms(websocket: WebSocket, process_id: str, user_id: str = Quer
4140

4241
user_id = user_id or "00000000-0000-0000-0000-000000000000"
4342

44-
current_user_id.set(user_id)
45-
4643
# Add to the connection manager for backend updates
4744
connection_config.add_connection(
4845
process_id=process_id, connection=websocket, user_id=user_id
@@ -74,7 +71,7 @@ async def start_comms(websocket: WebSocket, process_id: str, user_id: str = Quer
7471
logging.error(f"Error in WebSocket connection: {str(e)}")
7572
finally:
7673
# Always clean up the connection
77-
await connection_config.close_connection(user_id)
74+
await connection_config.close_connection(process_id=process_id)
7875

7976

8077
@app_v3.get("/init_team")
@@ -288,18 +285,14 @@ async def process_request(
288285
raise HTTPException(status_code=500, detail="Failed to create plan")
289286

290287
try:
291-
current_user_id.set(user_id) # Set context
292-
current_context = contextvars.copy_context() # Capture context
293288
# background_tasks.add_task(
294289
# lambda: current_context.run(lambda:OrchestrationManager().run_orchestration, user_id, input_task)
295290
# )
296291

297-
async def run_with_context():
298-
return await current_context.run(
299-
OrchestrationManager().run_orchestration, user_id, input_task
300-
)
292+
async def run_orchestration_task():
293+
await OrchestrationManager().run_orchestration(user_id, input_task)
301294

302-
background_tasks.add_task(run_with_context)
295+
background_tasks.add_task(run_orchestration_task)
303296

304297
return {
305298
"status": "Request started successfully",

0 commit comments

Comments
 (0)