AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
feat(executor;frontend): Move output processing step from node executor to graph executor & simplify input beads calculation (#10066)
Zamil Majdy2647417e9f3e
diff --git a/autogpt_platform/backend/backend/blocks/llm.py b/autogpt_platform/backend/backend/blocks/llm.pyindex 2ff5687f5c..f4c16e48ad 100644--- a/autogpt_platform/backend/backend/blocks/llm.py+++ b/autogpt_platform/backend/backend/blocks/llm.py@@ -1047,8 +1047,8 @@ class AITextSummarizerBlock(AIBlockBase):def run(self, input_data: Input, *, credentials: APIKeyCredentials, **kwargs) -> BlockOutput:- for output in self._run(input_data, credentials):- yield output+ for output_name, output_data in self._run(input_data, credentials):+ yield output_name, output_datadef _run(self, input_data: Input, credentials: APIKeyCredentials) -> BlockOutput:chunks = self._split_text(diff --git a/autogpt_platform/backend/backend/data/execution.py b/autogpt_platform/backend/backend/data/execution.pyindex d27e427566..7fc534d30d 100644--- a/autogpt_platform/backend/backend/data/execution.py+++ b/autogpt_platform/backend/backend/data/execution.py@@ -3,6 +3,7 @@ from collections import defaultdictfrom datetime import datetime, timedelta, timezonefrom enum import Enumfrom multiprocessing import Manager+from queue import Emptyfrom typing import (Annotated,Any,@@ -621,14 +622,29 @@ async def update_graph_execution_stats(return GraphExecution.from_db(graph_exec)-async def update_node_execution_stats(node_exec_id: str, stats: NodeExecutionStats):+async def update_node_execution_stats(+ node_exec_id: str, stats: NodeExecutionStats+) -> NodeExecutionResult:data = stats.model_dump()if isinstance(data["error"], Exception):data["error"] = str(data["error"])- await AgentNodeExecution.prisma().update(+ execution_status = ExecutionStatus.FAILED+ else:+ execution_status = ExecutionStatus.COMPLETED++ res = await AgentNodeExecution.prisma().update(where={"id": node_exec_id},- data={"stats": Json(data)},+ data={+ "stats": Json(data),+ "executionStatus": execution_status,+ "endedTime": datetime.now(tz=timezone.utc),+ },+ include=EXECUTION_RESULT_INCLUDE,)+ if not res:+ raise ValueError(f"Node execution {node_exec_id} not found.")++ return NodeExecutionResult.from_db(res)async def update_node_execution_status_batch(@@ -702,6 +718,16 @@ async def delete_graph_execution()+async def get_node_execution(node_exec_id: str) -> NodeExecutionResult | None:+ execution = await AgentNodeExecution.prisma().find_first(+ where={"id": node_exec_id},+ include=EXECUTION_RESULT_INCLUDE,+ )+ if not execution:+ return None+ return NodeExecutionResult.from_db(execution)++async def get_node_executions(graph_exec_id: str,node_id: str | None = None,@@ -794,6 +820,12 @@ class ExecutionQueue(Generic[T]):def empty(self) -> bool:return self.queue.empty()+ def get_or_none(self) -> T | None:+ try:+ return self.queue.get_nowait()+ except Empty:+ return None+# --------------------- Event Bus --------------------- #diff --git a/autogpt_platform/backend/backend/executor/database.py b/autogpt_platform/backend/backend/executor/database.pyindex f120433da5..e1b4c9c776 100644--- a/autogpt_platform/backend/backend/executor/database.py+++ b/autogpt_platform/backend/backend/executor/database.py@@ -9,6 +9,7 @@ from backend.data.execution import (get_graph_execution_meta,get_graph_executions,get_latest_node_execution,+ get_node_execution,get_node_executions,update_graph_execution_start_time,update_graph_execution_stats,@@ -90,6 +91,7 @@ class DatabaseManager(AppService):get_graph_executions = _(get_graph_executions)get_graph_execution_meta = _(get_graph_execution_meta)create_graph_execution = _(create_graph_execution)+ get_node_execution = _(get_node_execution)get_node_executions = _(get_node_executions)get_latest_node_execution = _(get_latest_node_execution)update_node_execution_status = _(update_node_execution_status)@@ -147,6 +149,7 @@ class DatabaseManagerClient(AppServiceClient):get_graph_executions = _(d.get_graph_executions)get_graph_execution_meta = _(d.get_graph_execution_meta)create_graph_execution = _(d.create_graph_execution)+ get_node_execution = _(d.get_node_execution)get_node_executions = _(d.get_node_executions)get_latest_node_execution = _(d.get_latest_node_execution)update_node_execution_status = _(d.update_node_execution_status)diff --git a/autogpt_platform/backend/backend/executor/manager.py b/autogpt_platform/backend/backend/executor/manager.pyindex acc5bab91d..58ad8933fd 100644--- a/autogpt_platform/backend/backend/executor/manager.py+++ b/autogpt_platform/backend/backend/executor/manager.py@@ -5,10 +5,12 @@ import osimport signalimport sysimport threading+import time+from collections import defaultdictfrom concurrent.futures import Future, ProcessPoolExecutorfrom contextlib import contextmanager-from multiprocessing.pool import AsyncResult, Pool-from typing import TYPE_CHECKING, Any, Generator, Optional, TypeVar, cast+from multiprocessing.pool import Pool+from typing import TYPE_CHECKING, Optional, TypeVar, castfrom pika.adapters.blocking_connection import BlockingChannelfrom pika.spec import Basic, BasicProperties@@ -39,7 +41,13 @@ from prometheus_client import Gauge, start_http_serverfrom backend.blocks.agent import AgentExecutorBlockfrom backend.data import redis-from backend.data.block import BlockData, BlockInput, BlockSchema, get_block+from backend.data.block import (+ BlockData,+ BlockInput,+ BlockOutput,+ BlockSchema,+ get_block,+)from backend.data.credit import UsageTransactionMetadatafrom backend.data.execution import (ExecutionQueue,@@ -54,6 +62,8 @@ from backend.executor.utils import (GRAPH_EXECUTION_CANCEL_QUEUE_NAME,GRAPH_EXECUTION_QUEUE_NAME,CancelExecutionEvent,+ ExecutionOutputEntry,+ NodeExecutionProgress,block_usage_cost,execution_usage_cost,get_execution_event_bus,@@ -116,18 +126,17 @@ class LogMetadata(TruncatedLogger):T = TypeVar("T")-ExecutionStream = Generator[NodeExecutionEntry, None, None]def execute_node(- db_client: "DatabaseManagerClient",+ node: Node,creds_manager: IntegrationCredentialsManager,data: NodeExecutionEntry,execution_stats: NodeExecutionStats | None = None,node_credentials_input_map: Optional[dict[str, dict[str, CredentialsMetaInput]]] = None,-) -> ExecutionStream:+) -> BlockOutput:"""Execute a node in the graph. This will trigger a block execution on a node,persist the execution result, and return the subsequent node to be executed.@@ -146,24 +155,8 @@ def execute_node(graph_id = data.graph_idnode_exec_id = data.node_exec_idnode_id = data.node_id-- def update_execution_status(status: ExecutionStatus) -> NodeExecutionResult:- """Sets status and fetches+broadcasts the latest state of the node execution"""- exec_update = db_client.update_node_execution_status(node_exec_id, status)- send_execution_update(exec_update)- return exec_update-- node = db_client.get_node(node_id)-node_block = node.block- def push_output(output_name: str, output_data: Any) -> None:- db_client.upsert_execution_output(- node_exec_id=node_exec_id,- output_name=output_name,- output_data=output_data,- )-log_metadata = LogMetadata(user_id=user_id,graph_eid=graph_exec_id,@@ -177,8 +170,7 @@ def execute_node(input_data, error = validate_exec(node, data.inputs, resolve_input=False)if input_data is None:log_metadata.error(f"Skip execution, input validation error: {error}")- push_output("error", error)- update_execution_status(ExecutionStatus.FAILED)+ yield "error", errorreturn# Re-shape the input data for agent block.@@ -195,7 +187,6 @@ def execute_node(input_data_str = json.dumps(input_data)input_size = len(input_data_str)log_metadata.debug("Executed node with input", input=input_data_str)- update_execution_status(ExecutionStatus.RUNNING)# Inject extra execution arguments for the blocks via kwargsextra_exec_kwargs: dict = {@@ -219,47 +210,19 @@ def execute_node(output_size = 0try:- outputs: dict[str, Any] = {}for output_name, output_data in node_block.execute(input_data, **extra_exec_kwargs):output_data = json.convert_pydantic_to_json(output_data)output_size += len(json.dumps(output_data))log_metadata.debug("Node produced output", **{output_name: output_data})- push_output(output_name, output_data)- outputs[output_name] = output_data- for execution in _enqueue_next_nodes(- db_client=db_client,- node=node,- output=(output_name, output_data),- user_id=user_id,- graph_exec_id=graph_exec_id,- graph_id=graph_id,- log_metadata=log_metadata,- node_credentials_input_map=node_credentials_input_map,- ):- yield execution-- update_execution_status(ExecutionStatus.COMPLETED)+ yield output_name, output_dataexcept Exception as e:error_msg = str(e)- push_output("error", error_msg)- update_execution_status(ExecutionStatus.FAILED)-- for execution in _enqueue_next_nodes(- db_client=db_client,- node=node,- output=("error", error_msg),- user_id=user_id,- graph_exec_id=graph_exec_id,- graph_id=graph_id,- log_metadata=log_metadata,- node_credentials_input_map=node_credentials_input_map,- ):- yield execution-+ yield "error", error_msgraise e+finally:# Ensure credentials are released even if execution failsif creds_lock and creds_lock.locked() and creds_lock.owned():@@ -290,10 +253,12 @@ def _enqueue_next_nodes(def add_enqueued_execution(node_exec_id: str, node_id: str, block_id: str, data: BlockInput) -> NodeExecutionEntry:- exec_update = db_client.update_node_execution_status(- node_exec_id, ExecutionStatus.QUEUED, data+ update_node_execution_status(+ db_client=db_client,+ exec_id=node_exec_id,+ status=ExecutionStatus.QUEUED,+ execution_data=data,)- send_execution_update(exec_update)return NodeExecutionEntry(user_id=user_id,graph_exec_id=graph_exec_id,@@ -334,6 +299,11 @@ def _enqueue_next_nodes(input_name=next_input_name,input_data=next_data,)+ update_node_execution_status(+ db_client=db_client,+ exec_id=next_node_exec_id,+ status=ExecutionStatus.INCOMPLETE,+ )# Complete missing static input pins data using the last execution input.static_link_names = {@@ -493,7 +463,7 @@ class Executor:@error_loggeddef on_node_execution(cls,- q: ExecutionQueue[NodeExecutionEntry],+ q: ExecutionQueue[ExecutionOutputEntry],node_exec: NodeExecutionEntry,node_credentials_input_map: Optional[dict[str, dict[str, CredentialsMetaInput]]@@ -507,27 +477,35 @@ class Executor:node_id=node_exec.node_id,block_name="-",)+ node = cls.db_client.get_node(node_exec.node_id)execution_stats = NodeExecutionStats()timing_info, _ = cls._on_node_execution(- q, node_exec, log_metadata, execution_stats, node_credentials_input_map+ q=q,+ node_exec=node_exec,+ node=node,+ log_metadata=log_metadata,+ stats=execution_stats,+ node_credentials_input_map=node_credentials_input_map,)execution_stats.walltime = timing_info.wall_timeexecution_stats.cputime = timing_info.cpu_timeif isinstance(execution_stats.error, Exception):execution_stats.error = str(execution_stats.error)- cls.db_client.update_node_execution_stats(+ exec_update = cls.db_client.update_node_execution_stats(node_exec.node_exec_id, execution_stats)+ send_execution_update(exec_update)return execution_stats@classmethod@time_measureddef _on_node_execution(cls,- q: ExecutionQueue[NodeExecutionEntry],+ q: ExecutionQueue[ExecutionOutputEntry],node_exec: NodeExecutionEntry,+ node: Node,log_metadata: LogMetadata,stats: NodeExecutionStats | None = None,node_credentials_input_map: Optional[@@ -536,14 +514,26 @@ class Executor:):try:log_metadata.info(f"Start node execution {node_exec.node_exec_id}")- for execution in execute_node(+ update_node_execution_status(db_client=cls.db_client,+ exec_id=node_exec.node_exec_id,+ status=ExecutionStatus.RUNNING,+ )++ for output_name, output_data in execute_node(+ node=node,creds_manager=cls.creds_manager,data=node_exec,execution_stats=stats,node_credentials_input_map=node_credentials_input_map,):- q.add(execution)+ q.add(+ ExecutionOutputEntry(+ node=node,+ node_exec_id=node_exec.node_exec_id,+ data=(output_name, output_data),+ )+ )log_metadata.info(f"Finished node execution {node_exec.node_exec_id}")except Exception as e:# Avoid user error being marked as an actual error.@@ -709,6 +699,13 @@ class Executor:error = Nonefinished = False+ def drain_output_queue():+ while output := output_queue.get_or_none():+ log_metadata.debug(+ f"Received output for {output.node.id} - {output.node_exec_id}: {output.data}"+ )+ running_executions[output.node.id].add_output(output)+def cancel_handler():nonlocal execution_status@@ -733,19 +730,20 @@ class Executor:amount=1,)- queue = ExecutionQueue[NodeExecutionEntry]()+ output_queue = ExecutionQueue[ExecutionOutputEntry]()+ execution_queue = ExecutionQueue[NodeExecutionEntry]()for node_exec in cls.db_client.get_node_executions(graph_exec.graph_exec_id,statuses=[ExecutionStatus.RUNNING, ExecutionStatus.QUEUED],):- queue.add(node_exec.to_node_execution_entry())+ execution_queue.add(node_exec.to_node_execution_entry())- running_executions: dict[str, AsyncResult] = {}+ running_executions: dict[str, NodeExecutionProgress] = defaultdict(+ lambda: NodeExecutionProgress(drain_output_queue)+ )def make_exec_callback(exec_data: NodeExecutionEntry):def callback(result: object):- running_executions.pop(exec_data.node_id)-if not isinstance(result, NodeExecutionStats):return@@ -773,21 +771,12 @@ class Executor:return callback- while not queue.empty():+ while not execution_queue.empty():if cancel.is_set():execution_status = ExecutionStatus.TERMINATEDreturn execution_stats, execution_status, error- queued_node_exec = queue.get()-- # Avoid parallel execution of the same node.- execution = running_executions.get(queued_node_exec.node_id)- if execution and not execution.ready():- # TODO (performance improvement):- # Wait for the completion of the same node execution is blocking.- # To improve this we need a separate queue for each node.- # Re-enqueueing the data back to the queue will disrupt the order.- execution.wait()+ queued_node_exec = execution_queue.get()log_metadata.debug(f"Dispatching node execution {queued_node_exec.node_exec_id} "@@ -807,12 +796,12 @@ class Executor:output_name="error",output_data=str(error),)-- execution_status = ExecutionStatus.FAILED- exec_update = cls.db_client.update_node_execution_status(- node_exec_id, execution_status+ update_node_execution_status(+ db_client=cls.db_client,+ exec_id=node_exec_id,+ status=ExecutionStatus.FAILED,)- send_execution_update(exec_update)+ execution_status = ExecutionStatus.FAILEDcls._handle_low_balance_notif(graph_exec.user_id,@@ -835,34 +824,52 @@ class Executor:)# Initiate node execution- running_executions[queued_node_exec.node_id] = cls.executor.apply_async(- cls.on_node_execution,- (queue, queued_node_exec, node_creds_map),- callback=make_exec_callback(queued_node_exec),+ running_executions[queued_node_exec.node_id].add_task(+ queued_node_exec.node_exec_id,+ cls.executor.apply_async(+ cls.on_node_execution,+ (output_queue, queued_node_exec, node_creds_map),+ callback=make_exec_callback(queued_node_exec),+ ),)# Avoid terminating graph execution when some nodes are still running.- while queue.empty() and running_executions:+ while execution_queue.empty() and running_executions:log_metadata.debug(f"Queue empty; running nodes: {list(running_executions.keys())}")++ # Register next node executions from running_executions.for node_id, execution in list(running_executions.items()):if cancel.is_set():execution_status = ExecutionStatus.TERMINATEDreturn execution_stats, execution_status, error- if not queue.empty():+ if not execution_queue.empty():break # yield to parent loop to execute new queue itemslog_metadata.debug(f"Waiting on execution of node {node_id}")- execution.wait(3)+ while output := execution.pop_output():+ cls._process_node_output(+ output=output,+ node_id=node_id,+ graph_exec=graph_exec,+ log_metadata=log_metadata,+ node_creds_map=node_creds_map,+ execution_queue=execution_queue,+ )++ if execution.is_done(1):+ running_executions.pop(node_id)+ else:+ time.sleep(0.1)log_metadata.info(f"Finished graph execution {graph_exec.graph_exec_id}")execution_status = ExecutionStatus.COMPLETEDexcept Exception as e:error = e- log_metadata.error(+ log_metadata.exception(f"Failed graph execution {graph_exec.graph_exec_id}: {error}")execution_status = ExecutionStatus.FAILED@@ -875,6 +882,61 @@ class Executor:clean_exec_files(graph_exec.graph_exec_id)return execution_stats, execution_status, error+ @classmethod+ def _process_node_output(+ cls,+ output: ExecutionOutputEntry,+ node_id: str,+ graph_exec: GraphExecutionEntry,+ log_metadata: LogMetadata,+ node_creds_map: Optional[dict[str, dict[str, CredentialsMetaInput]]],+ execution_queue: ExecutionQueue[NodeExecutionEntry],+ ) -> None:+ """Process a node's output, update its status, and enqueue next nodes.++ Args:+ output: The execution output entry to process+ node_id: The ID of the node that produced the output+ graph_exec: The graph execution entry+ log_metadata: Logger metadata for consistent logging+ node_creds_map: Optional map of node credentials+ execution_queue: Queue to add next executions to+ """+ try:+ name, data = output.data+ cls.db_client.upsert_execution_output(+ node_exec_id=output.node_exec_id,+ output_name=name,+ output_data=data,+ )+ if exec_update := cls.db_client.get_node_execution(output.node_exec_id):+ send_execution_update(exec_update)++ log_metadata.debug(f"Enqueue nodes for {node_id}: {output}")+ for next_execution in _enqueue_next_nodes(+ db_client=cls.db_client,+ node=output.node,+ output=output.data,+ user_id=graph_exec.user_id,+ graph_exec_id=graph_exec.graph_exec_id,+ graph_id=graph_exec.graph_id,+ log_metadata=log_metadata,+ node_credentials_input_map=node_creds_map,+ ):+ execution_queue.add(next_execution)+ except Exception as e:+ log_metadata.exception(f"Failed to process node output: {e}")+ cls.db_client.upsert_execution_output(+ node_exec_id=output.node_exec_id,+ output_name="error",+ output_data=str(e),+ )+ update_node_execution_status(+ db_client=cls.db_client,+ exec_id=output.node_exec_id,+ status=ExecutionStatus.FAILED,+ )+@classmethoddef _handle_agent_run_notif(cls,@@ -1139,6 +1201,20 @@ def send_execution_update(entry: GraphExecution | NodeExecutionResult | None):return get_execution_event_bus().publish(entry)+def update_node_execution_status(+ db_client: "DatabaseManagerClient",+ exec_id: str,+ status: ExecutionStatus,+ execution_data: BlockInput | None = None,+) -> NodeExecutionResult:+ """Sets status and fetches+broadcasts the latest state of the node execution"""+ exec_update = db_client.update_node_execution_status(+ exec_id, status, execution_data+ )+ send_execution_update(exec_update)+ return exec_update++@contextmanagerdef synchronized(key: str, timeout: int = 60):lock: RedisLock = redis.get_redis().lock(f"lock:{key}", timeout=timeout)diff --git a/autogpt_platform/backend/backend/executor/utils.py b/autogpt_platform/backend/backend/executor/utils.pyindex 12e4e8c5ff..af6340a4ac 100644--- a/autogpt_platform/backend/backend/executor/utils.py+++ b/autogpt_platform/backend/backend/executor/utils.py@@ -1,5 +1,7 @@import logging-from typing import TYPE_CHECKING, Any, Optional, cast+from collections import defaultdict+from multiprocessing.pool import AsyncResult+from typing import TYPE_CHECKING, Any, Callable, Optional, castfrom autogpt_libs.utils.cache import thread_cachedfrom pydantic import BaseModel@@ -804,3 +806,72 @@ def add_graph_execution(stats=GraphExecutionStats(error=str(e)),)raise+++# ============ Execution Output Helpers ============ #+++class ExecutionOutputEntry(BaseModel):+ node: Node+ node_exec_id: str+ data: BlockData+++class NodeExecutionProgress:+ def __init__(self, drain_output_queue: Callable[[], None]):+ self.output: dict[str, list[ExecutionOutputEntry]] = defaultdict(list)+ self.tasks: dict[str, AsyncResult] = {}+ self.drain_output_queue = drain_output_queue++ def add_task(self, node_exec_id: str, task: AsyncResult):+ self.tasks[node_exec_id] = task++ def add_output(self, output: ExecutionOutputEntry):+ self.output[output.node_exec_id].append(output)++ def pop_output(self) -> ExecutionOutputEntry | None:+ exec_id = self._next_exec()+ if not exec_id:+ return None++ if self._pop_done_task(exec_id):+ return self.pop_output()++ if next_output := self.output[exec_id]:+ return next_output.pop(0)++ return None++ def is_done(self, wait_time: float = 0.0) -> bool:+ exec_id = self._next_exec()+ if not exec_id:+ return True++ if self._pop_done_task(exec_id):+ return self.is_done(wait_time)++ if wait_time <= 0:+ return False++ self.tasks[exec_id].wait(wait_time)+ return self.is_done(0)++ def _pop_done_task(self, exec_id: str) -> bool:+ task = self.tasks.get(exec_id)+ if not task:+ return True++ if not task.ready():+ return False++ self.drain_output_queue()+ if self.output[exec_id]:+ return False++ self.tasks.pop(exec_id)+ return True++ def _next_exec(self) -> str | None:+ if not self.tasks:+ return None+ return next(iter(self.tasks.keys()))diff --git a/autogpt_platform/frontend/src/components/CustomEdge.tsx b/autogpt_platform/frontend/src/components/CustomEdge.tsxindex d3f94fb1ac..bb620b2e6f 100644--- a/autogpt_platform/frontend/src/components/CustomEdge.tsx+++ b/autogpt_platform/frontend/src/components/CustomEdge.tsx@@ -12,6 +12,7 @@ import "./customedge.css";import { X } from "lucide-react";import { useBezierPath } from "@/hooks/useBezierPath";import { FlowContext } from "./Flow";+import { NodeExecutionResult } from "@/lib/autogpt-server-api";export type CustomEdgeData = {edgeColor: string;@@ -19,7 +20,7 @@ export type CustomEdgeData = {isStatic?: boolean;beadUp?: number;beadDown?: number;- beadData?: any[];+ beadData?: Map<string, NodeExecutionResult["status"]>;};type Bead = {diff --git a/autogpt_platform/frontend/src/hooks/useAgentGraph.tsx b/autogpt_platform/frontend/src/hooks/useAgentGraph.tsxindex f559ac863c..1a258653d3 100644--- a/autogpt_platform/frontend/src/hooks/useAgentGraph.tsx+++ b/autogpt_platform/frontend/src/hooks/useAgentGraph.tsx@@ -241,7 +241,7 @@ export default function useAgentGraph(isStatic: link.is_static,beadUp: 0,beadDown: 0,- beadData: [],+ beadData: new Map<string, NodeExecutionResult["status"]>(),},markerEnd: {type: MarkerType.ArrowClosed,@@ -307,61 +307,46 @@ export default function useAgentGraph(setEdges((edges) => {return edges.map((e) => {const edge = { ...e, data: { ...e.data } } as CustomEdge;-- if (executionData.status === "COMPLETED") {- // Produce output beads- for (let key in executionData.output_data) {- if (- edge.source !== getFrontendId(executionData.node_id, nodes) ||- edge.sourceHandle !== cleanupSourceName(key) ||- (isToolSourceName(key) &&- getToolArgName(key) !== edge.targetHandle)- ) {- console.log(- key,- cleanupSourceName(key),- edge.targetHandle,- " are not equal ",- getToolArgName(key),- edge.sourceHandle,- );- continue;- }- const count = executionData.output_data[key].length;- edge.data!.beadUp = (edge.data!.beadUp ?? 0) + count;- // For static edges beadDown is always one less than beadUp- // Because there's no queueing and one bead is always at the connection point- if (edge.data?.isStatic) {- edge.data!.beadDown = (edge.data!.beadUp ?? 0) - 1;- edge.data!.beadData = edge.data!.beadData!.slice(0, -1);- continue;- }- edge.data!.beadData = [- ...executionData.output_data[key].toReversed(),- ...edge.data!.beadData!,- ];+ const execStatus =+ edge.data!.beadData ||+ new Map<string, NodeExecutionResult["status"]>();++ // Update execution status for input edges+ for (let key in executionData.input_data) {+ if (+ edge.target !== getFrontendId(executionData.node_id, nodes) ||+ edge.targetHandle !== key+ ) {+ continue;}- } else if (executionData.status === "RUNNING") {- // Consume input beads- for (let key in executionData.input_data) {- if (- edge.target !== getFrontendId(executionData.node_id, nodes) ||- edge.targetHandle !== key- ) {- continue;- }- // Skip decreasing bead count if edge doesn't match or if it's static- if (- edge.data!.beadData![edge.data!.beadData!.length - 1] !==- executionData.input_data[key] ||- edge.data?.isStatic- ) {- continue;- }- edge.data!.beadDown = (edge.data!.beadDown ?? 0) + 1;- edge.data!.beadData = edge.data!.beadData!.slice(0, -1);++ // Store only the execution status+ execStatus.set(executionData.node_exec_id, executionData.status);+ }++ // Calculate bead counts based on execution status+ let beadUp = 0;+ let beadDown = 0;++ execStatus.forEach((status) => {+ beadUp++;+ if (status !== "INCOMPLETE") {+ // Count any non-incomplete execution as consumed+ beadDown++;}+ });++ // For static edges, ensure beadUp is always beadDown + 1+ // This is because static edges represent reusable inputs that are never fully consumed+ // The +1 represents the input that's still available for reuse+ if (edge.data?.isStatic && beadUp > 0) {+ beadUp = beadDown + 1;}++ // Update edge data+ edge.data!.beadUp = beadUp;+ edge.data!.beadDown = beadDown;+return edge;});});@@ -397,7 +382,11 @@ export default function useAgentGraph(executionResults:Object.keys(executionData.output_data).length > 0? [- ...(node.data.executionResults || []),+ // Execution updates are not cumulative, so we need to filter out the old ones.+ ...(node.data.executionResults?.filter(+ (result) =>+ result.execId !== executionData.node_exec_id,+ ) || []),{execId: executionData.node_exec_id,data: {@@ -434,14 +423,11 @@ export default function useAgentGraph(}setUpdateQueue((prev) => {prev.forEach((data) => {- // Skip already processed updates by checking- // if the data is in the processedUpdates array by reference- // This is not to process twice in react dev mode- // because it'll add double the beads- if (processedUpdates.current.includes(data)) {- return;- }updateNodesWithExecutionData(data);+ // Execution updates are not cumulative, so we need to filter out the old ones.+ processedUpdates.current = processedUpdates.current.filter(+ (update) => update.node_exec_id !== data.node_exec_id,+ );processedUpdates.current.push(data);});return [];@@ -997,7 +983,6 @@ export default function useAgentGraph(edgeColor: edge.data?.edgeColor!,beadUp: 0,beadDown: 0,- beadData: [],},}));});