Skip to content

Commit f5047f6

Browse files
committed
fix: 扩大跨源去重窗口
1 parent 995279b commit f5047f6

2 files changed

Lines changed: 36 additions & 5 deletions

File tree

packages/maa-log-parser/src/__tests__/parser.subTaskScope.test.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, expect, it } from 'vitest'
2-
import type { UnifiedFlowItem } from '@windsland52/maa-log-parser/types'
3-
import { LogParser } from '@windsland52/maa-log-parser'
2+
import type { UnifiedFlowItem } from '../shared/types'
3+
import { LogParser } from '../core/logParser'
44

55
const formatTimestamp = (eventIndex: number): string => {
66
const second = Math.floor(eventIndex / 1000)
@@ -411,6 +411,36 @@ describe('LogParser sub task scoped node aggregation', () => {
411411
expect(matchedTasks[0].nodes.length).toBe(1)
412412
})
413413

414+
it('deduplicates delayed mirrored cross-source Tasker.Task.Succeeded without creating an empty terminal task', async () => {
415+
const lines = [
416+
makeEventLine(200, 'Tasker.Task.Starting', { task_id: 92, entry: 'MainTask', hash: 'h-main-92', uuid: 'u-main-92' }, {
417+
processId: 'Px1',
418+
threadId: 'Tx1',
419+
}),
420+
makeEventLine(201, 'Node.PipelineNode.Starting', { task_id: 92, node_id: 9201, name: 'MainNode' }),
421+
makeEventLine(202, 'Node.PipelineNode.Succeeded', { task_id: 92, node_id: 9201, name: 'MainNode' }),
422+
makeEventLine(203, 'Tasker.Task.Succeeded', { task_id: 92, entry: 'MainTask', hash: 'h-main-92', uuid: 'u-main-92' }, {
423+
processId: 'Px1',
424+
threadId: 'Tx1',
425+
}),
426+
makeEventLine(230, 'Tasker.Task.Succeeded', { task_id: 92, entry: 'MainTask', hash: 'h-main-92', uuid: 'u-main-92' }, {
427+
processId: 'Px2',
428+
threadId: 'Tx2',
429+
}),
430+
]
431+
432+
const parser = new LogParser()
433+
await parser.parseFile(lines.join('\n'))
434+
const tasks = parser.getTasksSnapshot()
435+
const matchedTasks = tasks.filter(item => item.task_id === 92)
436+
437+
expect(matchedTasks).toHaveLength(1)
438+
expect(matchedTasks[0]?.status).toBe('succeeded')
439+
expect(matchedTasks[0]?.nodes).toHaveLength(1)
440+
expect(matchedTasks[0]?.start_time).toBe('2026-04-06 10:00:00.200')
441+
expect(matchedTasks[0]?.end_time).toBe('2026-04-06 10:00:00.203')
442+
})
443+
414444
it('keeps same-source duplicate Tasker.Task.Starting as separate task scopes', async () => {
415445
const lines = [
416446
makeEventLine(191, 'Tasker.Task.Starting', { task_id: 91, entry: 'MainTask', hash: 'h-main-91', uuid: 'u-main-91' }),

packages/maa-log-parser/src/core/logParser.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,11 @@ const forceCopyString = (value: string): string => {
7171
return copied
7272
}
7373

74-
// Mirrored OnEventNotify lines from agent/server pairs can arrive a few extra
74+
// Mirrored OnEventNotify lines from agent/server pairs can arrive tens of
7575
// milliseconds after the primary emitter. Keep the cross-source dedup window
76-
// slightly wider so lone mirrored `starting` events do not leak into the trace.
77-
const CROSS_SOURCE_DUPLICATE_WINDOW_MS = 20
76+
// wide enough so delayed mirrored terminal events do not create synthetic
77+
// empty scopes after the real scope has already been closed.
78+
const CROSS_SOURCE_DUPLICATE_WINDOW_MS = 50
7879

7980
export class LogParser {
8081
private events: EventNotification[] = []

0 commit comments

Comments
 (0)