diff --git a/web/app/components/workflow/utils/top-level-tracing.spec.ts b/web/app/components/workflow/utils/top-level-tracing.spec.ts index da01cc2a6c..b18b642076 100644 --- a/web/app/components/workflow/utils/top-level-tracing.spec.ts +++ b/web/app/components/workflow/utils/top-level-tracing.spec.ts @@ -91,6 +91,26 @@ describe('upsertTopLevelTracingNodeOnStart', () => { expect(tracing).toEqual([existingTrace, startedNode]) }) + it('should update an existing running top-level node when the same node restarts with a new execution id', () => { + const tracing: NodeTracing[] = [ + createTrace({ + id: 'trace-1', + node_id: 'node-1', + status: NodeRunningStatus.Running, + }), + ] + const startedNode = createTrace({ + id: 'trace-2', + node_id: 'node-1', + status: NodeRunningStatus.Running, + }) + + const updated = upsertTopLevelTracingNodeOnStart(tracing, startedNode) + + expect(updated).toBe(true) + expect(tracing).toEqual([startedNode]) + }) + it('should ignore nested iteration node starts even when the node id matches a top-level trace', () => { const existingTrace = createTrace({ id: 'top-level-trace', diff --git a/web/app/components/workflow/utils/top-level-tracing.ts b/web/app/components/workflow/utils/top-level-tracing.ts index 8ddeb2a957..817bd9eb8f 100644 --- a/web/app/components/workflow/utils/top-level-tracing.ts +++ b/web/app/components/workflow/utils/top-level-tracing.ts @@ -1,4 +1,5 @@ import type { NodeTracing } from '@/types/workflow' +import { NodeRunningStatus } from '../types' const isNestedTracingNode = (trace: Pick) => { return Boolean(trace.iteration_id || trace.loop_id) @@ -11,7 +12,12 @@ export const upsertTopLevelTracingNodeOnStart = ( if (isNestedTracingNode(startedNode)) return false - const currentIndex = tracing.findIndex(item => item.id === startedNode.id) + const currentIndex = tracing.findIndex((item) => { + if (item.id === startedNode.id) + return true + + return item.node_id === startedNode.node_id && item.status === NodeRunningStatus.Running + }) if (currentIndex > -1) // Started events are the authoritative snapshot for an execution; merging would retain stale client-side fields. tracing[currentIndex] = startedNode