diff --git a/src/agent.py b/src/agent.py index b8816291..07fd911e 100644 --- a/src/agent.py +++ b/src/agent.py @@ -418,12 +418,8 @@ async def async_langflow_chat( from services.session_ownership_service import session_ownership_service from services.user_binding_service import user_binding_service - # Check if this is a Google user (has binding but not UUID format) - import re - uuid_pattern = r'^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}$' - is_uuid = bool(re.match(uuid_pattern, user_id.lower().replace('-', ''))) - - if not is_uuid and user_binding_service.has_binding(user_id): + # Check if this is a Google user (Google IDs are numeric, Langflow IDs are UUID) + if user_id.isdigit() and user_binding_service.has_binding(user_id): langflow_user_id = user_binding_service.get_langflow_user_id(user_id) if langflow_user_id: session_ownership_service.claim_session(user_id, response_id, langflow_user_id) @@ -511,12 +507,8 @@ async def async_langflow_chat_stream( from services.session_ownership_service import session_ownership_service from services.user_binding_service import user_binding_service - # Check if this is a Google user (has binding but not UUID format) - import re - uuid_pattern = r'^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}$' - is_uuid = bool(re.match(uuid_pattern, user_id.lower().replace('-', ''))) - - if not is_uuid and user_binding_service.has_binding(user_id): + # Check if this is a Google user (Google IDs are numeric, Langflow IDs are UUID) + if user_id.isdigit() and user_binding_service.has_binding(user_id): langflow_user_id = user_binding_service.get_langflow_user_id(user_id) if langflow_user_id: session_ownership_service.claim_session(user_id, response_id, langflow_user_id) diff --git a/src/services/langflow_history_service.py b/src/services/langflow_history_service.py index e6e49f4d..ad17a238 100644 --- a/src/services/langflow_history_service.py +++ b/src/services/langflow_history_service.py @@ -44,11 +44,9 @@ class LangflowHistoryService: return None def _is_uuid_format(self, user_id: str) -> bool: - """Check if string looks like a UUID (Langflow user ID format)""" - import re - # Basic UUID pattern check (with or without dashes) - uuid_pattern = r'^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}$' - return bool(re.match(uuid_pattern, user_id.lower().replace('-', ''))) + """Check if string looks like a UUID (Langflow user ID format vs Google numeric ID)""" + # Langflow IDs are UUID v4, Google IDs are purely numeric + return not user_id.isdigit() def _filter_sessions_by_ownership(self, session_ids: List[str], user_id: str, langflow_user_id: str) -> List[str]: """Filter sessions based on user type and ownership""" diff --git a/src/services/user_binding_service.py b/src/services/user_binding_service.py index 4cead0aa..b7bbe905 100644 --- a/src/services/user_binding_service.py +++ b/src/services/user_binding_service.py @@ -237,11 +237,9 @@ class UserBindingService: return self.bindings.copy() def is_langflow_user_id(self, user_id: str) -> bool: - """Check if user_id appears to be a Langflow UUID""" - import re - # Basic UUID pattern check (with or without dashes) - uuid_pattern = r'^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}$' - return bool(re.match(uuid_pattern, user_id.lower().replace('-', ''))) + """Check if user_id appears to be a Langflow UUID (vs Google numeric ID)""" + # Langflow IDs are UUID v4, Google IDs are purely numeric + return not user_id.isdigit() def get_user_type(self, user_id: str) -> str: """Determine user type: 'google_oauth', 'langflow_direct', or 'unknown'"""