diff --git a/web/app/components/workflow/panel/debug-and-preview/hooks.ts b/web/app/components/workflow/panel/debug-and-preview/hooks.ts index a9e961874e..20aece660f 100644 --- a/web/app/components/workflow/panel/debug-and-preview/hooks.ts +++ b/web/app/components/workflow/panel/debug-and-preview/hooks.ts @@ -518,6 +518,8 @@ export const useChat = ( upsertTopLevelTracingNodeOnStart(responseItem.workflowProcess!.tracing!, { ...data, status: NodeRunningStatus.Running, + }, { + reuseRunningNodeId: true, }) updateCurrentQAOnTree({ placeholderQuestionId, @@ -807,6 +809,8 @@ export const useChat = ( upsertTopLevelTracingNodeOnStart(responseItem.workflowProcess.tracing, { ...nodeStartedData, status: NodeRunningStatus.Running, + }, { + reuseRunningNodeId: true, }) }) }, 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 b18b642076..2fa3dda1ed 100644 --- a/web/app/components/workflow/utils/top-level-tracing.spec.ts +++ b/web/app/components/workflow/utils/top-level-tracing.spec.ts @@ -105,12 +105,33 @@ describe('upsertTopLevelTracingNodeOnStart', () => { status: NodeRunningStatus.Running, }) - const updated = upsertTopLevelTracingNodeOnStart(tracing, startedNode) + const updated = upsertTopLevelTracingNodeOnStart(tracing, startedNode, { + reuseRunningNodeId: true, + }) expect(updated).toBe(true) expect(tracing).toEqual([startedNode]) }) + it('should keep separate running top-level traces by default when a new execution id appears', () => { + const existingTrace = createTrace({ + id: 'trace-1', + node_id: 'node-1', + status: NodeRunningStatus.Running, + }) + const tracing: NodeTracing[] = [existingTrace] + 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([existingTrace, 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 817bd9eb8f..3ca57f3768 100644 --- a/web/app/components/workflow/utils/top-level-tracing.ts +++ b/web/app/components/workflow/utils/top-level-tracing.ts @@ -8,6 +8,9 @@ const isNestedTracingNode = (trace: Pick { if (isNestedTracingNode(startedNode)) return false @@ -16,6 +19,9 @@ export const upsertTopLevelTracingNodeOnStart = ( if (item.id === startedNode.id) return true + if (!options?.reuseRunningNodeId) + return false + return item.node_id === startedNode.node_id && item.status === NodeRunningStatus.Running }) if (currentIndex > -1)