Skip to content

Self-improving AI Employees for everyone

Fix toolkit sub-nodes executing as independent workflow nodes in parallel mode

trohitg45dd7922c678
diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml
index b32709f0..c17fdd86 100644
--- a/docker-compose.prod.yml
+++ b/docker-compose.prod.yml
@@ -1,10 +1,8 @@
services:
- # Redis Cache (optional - enable with REDIS_ENABLED=true)
+ # Redis Cache (production performance)
redis:
image: redis:7-alpine
container_name: machina-redis
- profiles:
- - redis
volumes:
- redis-data:/data
networks:
@@ -43,11 +41,13 @@ services:
# Production overrides
- PORT=${PYTHON_BACKEND_PORT:-3010}
- ENV=production
- - REDIS_ENABLED=false
+ - REDIS_ENABLED=true
- REDIS_URL=redis://redis:6379
- WHATSAPP_RPC_URL=ws://whatsapp:${WHATSAPP_RPC_PORT:-9400}/ws/rpc
- TZ=UTC
depends_on:
+ redis:
+ condition: service_healthy
whatsapp:
condition: service_healthy
diff --git a/server/constants.py b/server/constants.py
index 1f581edd..541ad1d3 100644
--- a/server/constants.py
+++ b/server/constants.py
@@ -35,6 +35,13 @@ AI_TOOL_TYPES: FrozenSet[str] = frozenset([
'androidTool',
])
+# Toolkit node types (aggregate sub-nodes, n8n Sub-Node pattern)
+# Sub-nodes connected to toolkits should not execute independently -
+# they only execute when called via the toolkit's tool interface
+TOOLKIT_NODE_TYPES: FrozenSet[str] = frozenset([
+ 'androidTool', # Aggregates Android service nodes (batteryMonitor, location, etc.)
+])
+
# All AI-related node types (for API key injection)
AI_MODEL_TYPES: FrozenSet[str] = AI_AGENT_TYPES | AI_CHAT_MODEL_TYPES
diff --git a/server/services/execution/executor.py b/server/services/execution/executor.py
index 10563ffc..6884569b 100644
--- a/server/services/execution/executor.py
+++ b/server/services/execution/executor.py
@@ -877,6 +877,9 @@ class WorkflowExecutor:
workflow. They listen for specific events/conditions and initiate
the execution of the entire workflow.
+ Config nodes and toolkit sub-nodes are excluded from layers since
+ they don't execute as independent workflow nodes.
+
Args:
nodes: List of workflow nodes
edges: List of edges
@@ -884,15 +887,34 @@ class WorkflowExecutor:
Returns:
List of layers, where each layer is a list of node IDs
"""
+ from constants import CONFIG_NODE_TYPES, TOOLKIT_NODE_TYPES
+
# Build node type lookup for trigger detection
node_types: Dict[str, str] = {
node["id"]: node.get("type", "unknown") for node in nodes
}
- # Build adjacency and in-degree maps
+ # Find toolkit sub-nodes (nodes that connect TO a toolkit)
+ toolkit_node_ids = {n.get("id") for n in nodes if n.get("type") in TOOLKIT_NODE_TYPES}
+ subnode_ids: set = set()
+ for edge in edges:
+ source = edge.get("source")
+ target = edge.get("target")
+ if target in toolkit_node_ids and source:
+ subnode_ids.add(source)
+
+ # Filter out config nodes and sub-nodes from execution
+ excluded_ids = set()
+ for node in nodes:
+ node_id = node.get("id")
+ node_type = node.get("type", "unknown")
+ if node_type in CONFIG_NODE_TYPES or node_id in subnode_ids:
+ excluded_ids.add(node_id)
+
+ # Build adjacency and in-degree maps (excluding filtered nodes)
in_degree: Dict[str, int] = defaultdict(int)
adjacency: Dict[str, List[str]] = defaultdict(list)
- node_ids = {node["id"] for node in nodes}
+ node_ids = {node["id"] for node in nodes if node["id"] not in excluded_ids}
for edge in edges:
source = edge.get("source")
diff --git a/server/services/execution/models.py b/server/services/execution/models.py
index 381b5619..2fc2ad4d 100644
--- a/server/services/execution/models.py
+++ b/server/services/execution/models.py
@@ -305,8 +305,11 @@ class ExecutionContext:
Config nodes (memory, tools, model configs) are excluded from execution
as they provide configuration to other nodes via special handles.
+
+ Toolkit sub-nodes (nodes connected TO a toolkit like androidTool) are also
+ excluded - they execute only when called via the toolkit's tool interface.
"""
- from constants import CONFIG_NODE_TYPES
+ from constants import CONFIG_NODE_TYPES, TOOLKIT_NODE_TYPES
execution_id = str(uuid.uuid4())
ctx = cls(
@@ -317,7 +320,18 @@ class ExecutionContext:
edges=edges or [],
)
- # Initialize node executions for all nodes (excluding config nodes)
+ # Find toolkit sub-nodes (nodes that connect TO a toolkit node)
+ # These should only execute when called via the toolkit, not as workflow nodes
+ toolkit_node_ids = {n.get("id") for n in (nodes or []) if n.get("type") in TOOLKIT_NODE_TYPES}
+ subnode_ids: set = set()
+ for edge in (edges or []):
+ source = edge.get("source")
+ target = edge.get("target")
+ # Any node that connects TO a toolkit is a sub-node
+ if target in toolkit_node_ids and source:
+ subnode_ids.add(source)
+
+ # Initialize node executions for all nodes (excluding config nodes and sub-nodes)
for node in (nodes or []):
node_id = node.get("id")
node_type = node.get("type", "unknown")
@@ -327,6 +341,10 @@ class ExecutionContext:
if node_type in CONFIG_NODE_TYPES:
continue
+ # Skip toolkit sub-nodes - they execute only via toolkit tool calls
+ if node_id in subnode_ids:
+ continue
+
# Check if node is pre-executed (e.g., trigger that already fired)
if node.get("_pre_executed"):
# Mark as COMPLETED with trigger output