@@ -341,19 +341,31 @@ async def process_request(
341341
342342 # Ensure the workflow is valid (rebuild if terminated or stuck from a prior run)
343343 current_workflow = orchestration_config .get_current_orchestration (user_id )
344+
345+ cached_team_id = getattr (current_workflow , "_team_id" , None )
346+ team_mismatch = (
347+ current_workflow is not None and cached_team_id != team_id
348+ )
349+
344350 workflow_unusable = (
345351 current_workflow is None
346352 or getattr (current_workflow , "_terminated" , False )
347353 or getattr (current_workflow , "_is_running" , False )
354+ or team_mismatch
348355 )
349356 if workflow_unusable :
350357 logger .info (
351- "Workflow unusable for user '%s' (None=%s, terminated=%s, is_running=%s) — rebuilding" ,
358+ "Workflow unusable for user '%s' (None=%s, terminated=%s, is_running=%s, "
359+ "team_mismatch=%s cached_team=%s selected_team=%s) — rebuilding" ,
352360 user_id ,
353361 current_workflow is None ,
354362 getattr (current_workflow , "_terminated" , False ),
355363 getattr (current_workflow , "_is_running" , False ),
364+ team_mismatch ,
365+ cached_team_id ,
366+ team_id ,
356367 )
368+
357369 # Force-clear the running flag so get_current_or_new_orchestration
358370 # sees it as terminated and takes the lightweight reset path.
359371 if current_workflow is not None and getattr (current_workflow , "_is_running" , False ):
@@ -1454,4 +1466,4 @@ async def get_generated_image(blob_name: str):
14541466 return Response (content = data , media_type = "image/png" )
14551467 except Exception as exc :
14561468 logging .error (f"Error retrieving image '{ blob_name } ': { exc } " )
1457- raise HTTPException (status_code = 404 , detail = "Image not found" )
1469+ raise HTTPException (status_code = 404 , detail = "Image not found" )
0 commit comments