Skip to content

Commit 5e0ab8d

Browse files
committed
address comments
1 parent c560788 commit 5e0ab8d

2 files changed

Lines changed: 48 additions & 29 deletions

File tree

apps/sim/app/api/logs/export/route.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,26 @@ export const GET = withRouteHandler(async (request: NextRequest) => {
115115
for (let j = 0; j < rows.length; j++) {
116116
const r = rows[j] as any
117117
const ed = materialized[j] as Record<string, any>
118+
// A single malformed/unserializable row must not abort the whole CSV
119+
// stream — derive the message/trace columns defensively and fall back
120+
// to empty on error so the row's metadata still exports.
118121
let message = ''
119-
let traces: any = null
120-
if (ed) {
121-
if (ed.finalOutput)
122-
message =
123-
typeof ed.finalOutput === 'string'
124-
? ed.finalOutput
125-
: JSON.stringify(ed.finalOutput)
126-
if (ed.message) message = ed.message
127-
if (ed.traceSpans) traces = ed.traceSpans
122+
let tracesJson = ''
123+
try {
124+
if (ed) {
125+
if (ed.finalOutput)
126+
message =
127+
typeof ed.finalOutput === 'string'
128+
? ed.finalOutput
129+
: JSON.stringify(ed.finalOutput)
130+
if (ed.message) message = ed.message
131+
if (ed.traceSpans) tracesJson = JSON.stringify(ed.traceSpans)
132+
}
133+
} catch (rowError) {
134+
logger.warn('Skipping unserializable execution data for export row', {
135+
executionId: r.executionId,
136+
error: rowError instanceof Error ? rowError.message : String(rowError),
137+
})
128138
}
129139
const line = [
130140
escapeCsv(r.startedAt?.toISOString?.() || r.startedAt),
@@ -136,7 +146,7 @@ export const GET = withRouteHandler(async (request: NextRequest) => {
136146
escapeCsv(r.workflowId ?? ''),
137147
escapeCsv(r.executionId ?? ''),
138148
escapeCsv(message),
139-
escapeCsv(traces ? JSON.stringify(traces) : ''),
149+
escapeCsv(tracesJson),
140150
].join(',')
141151
controller.enqueue(encoder.encode(`${line}\n`))
142152
}

apps/sim/app/api/v1/logs/route.ts

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export const GET = withRouteHandler(async (request: NextRequest) => {
152152
const needsMaterialize =
153153
params.details === 'full' && (params.includeFinalOutput || params.includeTraceSpans)
154154

155-
const formattedLogs = await mapWithConcurrency(data, MATERIALIZE_CONCURRENCY, async (log) => {
155+
const buildBase = (log: (typeof data)[number]) => {
156156
const result: any = {
157157
id: log.id,
158158
workflowId: log.workflowId,
@@ -174,27 +174,36 @@ export const GET = withRouteHandler(async (request: NextRequest) => {
174174
description: log.workflowDescription,
175175
deleted: !log.workflowName,
176176
}
177-
178-
if (needsMaterialize && log.executionData) {
179-
const execData = (await materializeExecutionData(
180-
log.executionData as Record<string, unknown> | null,
181-
{
182-
workspaceId: log.workspaceId,
183-
workflowId: log.workflowId,
184-
executionId: log.executionId,
185-
}
186-
)) as any
187-
if (params.includeFinalOutput && execData.finalOutput) {
188-
result.finalOutput = execData.finalOutput
189-
}
190-
if (params.includeTraceSpans && execData.traceSpans) {
191-
result.traceSpans = execData.traceSpans
192-
}
193-
}
194177
}
195178

196179
return result
197-
})
180+
}
181+
182+
// Only run the bounded-concurrency materialization when the response actually
183+
// needs object-storage reads; otherwise a plain synchronous map avoids the
184+
// per-row worker/promise overhead.
185+
const formattedLogs = needsMaterialize
186+
? await mapWithConcurrency(data, MATERIALIZE_CONCURRENCY, async (log) => {
187+
const result = buildBase(log)
188+
if (log.executionData) {
189+
const execData = (await materializeExecutionData(
190+
log.executionData as Record<string, unknown> | null,
191+
{
192+
workspaceId: log.workspaceId,
193+
workflowId: log.workflowId,
194+
executionId: log.executionId,
195+
}
196+
)) as any
197+
if (params.includeFinalOutput && execData.finalOutput) {
198+
result.finalOutput = execData.finalOutput
199+
}
200+
if (params.includeTraceSpans && execData.traceSpans) {
201+
result.traceSpans = execData.traceSpans
202+
}
203+
}
204+
return result
205+
})
206+
: data.map(buildBase)
198207

199208
const limits = await getUserLimits(userId)
200209

0 commit comments

Comments
 (0)