imbajin commented on code in PR #301:
URL: 
https://github.com/apache/incubator-hugegraph-ai/pull/301#discussion_r2447068104


##########
hugegraph-llm/pyproject.toml:
##########
@@ -85,3 +86,4 @@ allow-direct-references = true
 
 [tool.uv.sources]
 hugegraph-python-client = { workspace = true }
+pycgraph = { git = "https://github.com/ChunelFeng/CGraph.git";, subdirectory = 
"python", rev = "main", marker = "sys_platform == 'linux'"  }

Review Comment:
   ‼️ **Critical: Platform-specific dependency with insufficient error 
handling**
   
   The `pycgraph` dependency is marked with `marker = "sys_platform == 
'linux'"`, meaning it will only install on Linux systems. However, the code 
imports and uses `PyCGraph` unconditionally without any platform checks or 
error handling.
   
   **Impact:** The application will crash immediately on non-Linux systems 
(macOS, Windows) when trying to import modules from `hugegraph_llm.flows`.
   
   **Recommendation:**
   1. Add platform compatibility checks and graceful degradation
   2. Provide clear error messages for unsupported platforms
   3. Consider making CGraph support optional with a feature flag
   4. Document platform requirements in README/docs



##########
hugegraph-llm/src/hugegraph_llm/flows/scheduler.py:
##########
@@ -0,0 +1,90 @@
+#  Licensed to the Apache Software Foundation (ASF) under one or more
+#  contributor license agreements.  See the NOTICE file distributed with
+#  this work for additional information regarding copyright ownership.
+#  The ASF licenses this file to You under the Apache License, Version 2.0
+#  (the "License"); you may not use this file except in compliance with
+#  the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+
+import threading
+from typing import Dict, Any
+from PyCGraph import GPipelineManager
+from hugegraph_llm.flows.build_vector_index import BuildVectorIndexFlow
+from hugegraph_llm.flows.common import BaseFlow
+from hugegraph_llm.flows.graph_extract import GraphExtractFlow
+from hugegraph_llm.utils.log import log
+
+
+class Scheduler:
+    pipeline_pool: Dict[str, Any] = None
+    max_pipeline: int
+
+    def __init__(self, max_pipeline: int = 10):
+        self.pipeline_pool = {}
+        # pipeline_pool act as a manager of GPipelineManager which used for 
pipeline management
+        self.pipeline_pool["build_vector_index"] = {
+            "manager": GPipelineManager(),
+            "flow": BuildVectorIndexFlow(),
+        }
+        self.pipeline_pool["graph_extract"] = {
+            "manager": GPipelineManager(),
+            "flow": GraphExtractFlow(),
+        }
+        self.max_pipeline = max_pipeline
+
+    # TODO: Implement Agentic Workflow
+    def agentic_flow(self):
+        pass
+
+    def schedule_flow(self, flow: str, *args, **kwargs):

Review Comment:
   ‼️ **Critical: Missing thread safety in pipeline access**
   
   The `schedule_flow` method accesses and modifies the pipeline pool without 
proper synchronization. While `SchedulerSingleton` uses a lock for instance 
creation, the `schedule_flow` method itself doesn't protect concurrent access 
to the shared `pipeline_pool` dictionary.
   
   **Race condition scenarios:**
   1. Multiple threads calling `schedule_flow` for the same flow type
   2. Concurrent `fetch()` and `release()` operations on the same manager
   3. Pipeline state corruption during concurrent runs
   
   **Recommendation:**
   Add proper locking around pipeline operations:
   ```python
   def schedule_flow(self, flow: str, *args, **kwargs):
       if flow not in self.pipeline_pool:
           raise ValueError(f"Unsupported workflow {flow}")
       
       with threading.Lock():  # Add lock here
           manager = self.pipeline_pool[flow]["manager"]
           # ... rest of the logic
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to