fix: scope top-level trace reuse to debug preview

This commit is contained in:
Yanli 盐粒
2026-03-25 19:41:56 +08:00
parent c446dd6164
commit 6b09ecc25e
3 changed files with 32 additions and 1 deletions

View File

@@ -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,
})
})
},

View File

@@ -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',

View File

@@ -8,6 +8,9 @@ const isNestedTracingNode = (trace: Pick<NodeTracing, 'iteration_id' | 'loop_id'
export const upsertTopLevelTracingNodeOnStart = (
tracing: NodeTracing[],
startedNode: NodeTracing,
options?: {
reuseRunningNodeId?: boolean
},
) => {
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)