Skip to content

Commit 44f4ad9

Browse files
author
test
committed
fix(logs): tighten marker ordering scope
Allow same-millisecond marker writes to replace prior markers and drop the unused diagnostics read helper so this PR stays focused on persistence rather than unread foundation code.
1 parent ab6aa29 commit 44f4ad9

File tree

6 files changed

+37
-148
lines changed

6 files changed

+37
-148
lines changed

apps/sim/lib/logs/execution/diagnostics.test.ts

Lines changed: 0 additions & 55 deletions
This file was deleted.

apps/sim/lib/logs/execution/diagnostics.ts

Lines changed: 0 additions & 76 deletions
This file was deleted.

apps/sim/lib/logs/execution/logger.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import { redactApiKeys } from '@/lib/core/security/redaction'
2323
import { filterForDisplay } from '@/lib/core/utils/display-filters'
2424
import { emitWorkflowExecutionCompleted } from '@/lib/logs/events'
2525
import { snapshotService } from '@/lib/logs/execution/snapshot/service'
26-
import { countTraceSpans } from '@/lib/logs/execution/trace-span-count'
2726
import type {
2827
BlockOutputData,
2928
ExecutionEnvironment,
@@ -50,6 +49,14 @@ export interface ToolCall {
5049

5150
const logger = createLogger('ExecutionLogger')
5251

52+
function countTraceSpans(traceSpans?: TraceSpan[]): number {
53+
if (!Array.isArray(traceSpans) || traceSpans.length === 0) {
54+
return 0
55+
}
56+
57+
return traceSpans.reduce((count, span) => count + 1 + countTraceSpans(span.children), 0)
58+
}
59+
5360
export class ExecutionLogger implements IExecutionLoggerService {
5461
private buildCompletedExecutionData(params: {
5562
existingExecutionData?: WorkflowExecutionLog['executionData']

apps/sim/lib/logs/execution/logging-session.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,18 @@ describe('LoggingSession completion retries', () => {
314314
expect(dbMocks.execute).toHaveBeenCalledTimes(1)
315315
})
316316

317+
it('allows same-millisecond started markers to replace the prior marker', async () => {
318+
const session = new LoggingSession('workflow-1', 'execution-1', 'api', 'req-1')
319+
320+
await session.onBlockStart('block-1', 'Fetch', 'api', '2025-01-01T00:00:00.000Z')
321+
322+
const queryCall = dbMocks.sql.mock.calls.at(-1)
323+
expect(queryCall).toBeDefined()
324+
325+
const [query] = queryCall!
326+
expect(Array.from(query).join(' ')).toContain('<=')
327+
})
328+
317329
it('persists last completed block for zero-cost outputs', async () => {
318330
const session = new LoggingSession('workflow-1', 'execution-1', 'api', 'req-1')
319331

@@ -326,6 +338,21 @@ describe('LoggingSession completion retries', () => {
326338
expect(dbMocks.execute).toHaveBeenCalledTimes(1)
327339
})
328340

341+
it('allows same-millisecond completed markers to replace the prior marker', async () => {
342+
const session = new LoggingSession('workflow-1', 'execution-1', 'api', 'req-1')
343+
344+
await session.onBlockComplete('block-2', 'Transform', 'function', {
345+
endedAt: '2025-01-01T00:00:01.000Z',
346+
output: { value: true },
347+
})
348+
349+
const queryCall = dbMocks.sql.mock.calls.at(-1)
350+
expect(queryCall).toBeDefined()
351+
352+
const [query] = queryCall!
353+
expect(Array.from(query).join(' ')).toContain('<=')
354+
})
355+
329356
it('drains pending lifecycle writes before terminal completion', async () => {
330357
let releasePersist: (() => void) | undefined
331358
const persistPromise = new Promise<void>((resolve) => {

apps/sim/lib/logs/execution/logging-session.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function buildStartedMarkerPersistenceQuery(params: {
4343
AND COALESCE(
4444
jsonb_extract_path_text(COALESCE(execution_data, '{}'::jsonb), 'lastStartedBlock', 'startedAt'),
4545
''
46-
) < ${params.marker.startedAt}`
46+
) <= ${params.marker.startedAt}`
4747
}
4848

4949
function buildCompletedMarkerPersistenceQuery(params: {
@@ -63,7 +63,7 @@ function buildCompletedMarkerPersistenceQuery(params: {
6363
AND COALESCE(
6464
jsonb_extract_path_text(COALESCE(execution_data, '{}'::jsonb), 'lastCompletedBlock', 'endedAt'),
6565
''
66-
) < ${params.marker.endedAt}`
66+
) <= ${params.marker.endedAt}`
6767
}
6868

6969
const logger = createLogger('LoggingSession')

apps/sim/lib/logs/execution/trace-span-count.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)