Skip to content

Commit f1e430a

Browse files
committed
prevent large traces from causing get_run_details failures
1 parent b994978 commit f1e430a

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

apps/webapp/app/env.server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ const EnvironmentSchema = z.object({
436436
EVENT_LOOP_MONITOR_ENABLED: z.string().default("1"),
437437
MAXIMUM_LIVE_RELOADING_EVENTS: z.coerce.number().int().default(1000),
438438
MAXIMUM_TRACE_SUMMARY_VIEW_COUNT: z.coerce.number().int().default(25_000),
439+
MAXIMUM_TRACE_DETAILED_SUMMARY_VIEW_COUNT: z.coerce.number().int().default(10_000),
439440
TASK_PAYLOAD_OFFLOAD_THRESHOLD: z.coerce.number().int().default(524_288), // 512KB
440441
TASK_PAYLOAD_MAXIMUM_SIZE: z.coerce.number().int().default(3_145_728), // 3MB
441442
BATCH_TASK_PAYLOAD_MAXIMUM_SIZE: z.coerce.number().int().default(1_000_000), // 1MB

apps/webapp/app/v3/taskEventStore.server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ export class TaskEventStore {
285285
: Prisma.empty
286286
}
287287
ORDER BY "startTime" ASC
288-
LIMIT ${env.MAXIMUM_TRACE_SUMMARY_VIEW_COUNT}
288+
LIMIT ${env.MAXIMUM_TRACE_DETAILED_SUMMARY_VIEW_COUNT}
289289
`;
290290
} else {
291291
return await this.readReplica.$queryRaw<DetailedTraceEvent[]>`
@@ -320,7 +320,7 @@ export class TaskEventStore {
320320
: Prisma.empty
321321
}
322322
ORDER BY "startTime" ASC
323-
LIMIT ${env.MAXIMUM_TRACE_SUMMARY_VIEW_COUNT}
323+
LIMIT ${env.MAXIMUM_TRACE_DETAILED_SUMMARY_VIEW_COUNT}
324324
`;
325325
}
326326
}

packages/cli-v3/src/mcp/formatters.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {
55
} from "@trigger.dev/core/v3/schemas";
66
import type { CursorPageResponse } from "@trigger.dev/core/v3/zodfetch";
77

8+
const MAX_TRACE_LINES = 1000;
9+
810
export function formatRun(run: RetrieveRunResponse): string {
911
const lines: string[] = [];
1012

@@ -177,16 +179,25 @@ export function formatRunTrace(trace: RetrieveRunTraceResponseBody["trace"]): st
177179
lines.push("");
178180

179181
// Format the root span and its children recursively
180-
formatSpan(trace.rootSpan, lines, 0);
182+
const reachedMaxLines = formatSpan(trace.rootSpan, lines, 0, MAX_TRACE_LINES);
183+
184+
if (reachedMaxLines) {
185+
lines.push(`(truncated logs to ${MAX_TRACE_LINES} lines)`);
186+
}
181187

182188
return lines.join("\n");
183189
}
184190

185191
function formatSpan(
186192
span: RetrieveRunTraceResponseBody["trace"]["rootSpan"],
187193
lines: string[],
188-
depth: number
189-
): void {
194+
depth: number,
195+
maxLines: number
196+
): boolean {
197+
if (lines.length >= maxLines) {
198+
return true;
199+
}
200+
190201
const indent = " ".repeat(depth);
191202
const prefix = depth === 0 ? "└─" : "├─";
192203

@@ -263,14 +274,20 @@ function formatSpan(
263274

264275
// Recursively format children
265276
if (span.children) {
266-
span.children.forEach((child, index) => {
267-
formatSpan(child, lines, depth + 1);
277+
const reachedMaxLines = span.children.some((child, index) => {
278+
const reachedMaxLines = formatSpan(child, lines, depth + 1, maxLines);
268279
// Add spacing between sibling spans (except for the last one)
269-
if (index < span.children.length - 1) {
280+
if (index < span.children.length - 1 && !reachedMaxLines) {
270281
lines.push("");
271282
}
283+
284+
return reachedMaxLines;
272285
});
286+
287+
return reachedMaxLines;
273288
}
289+
290+
return false;
274291
}
275292

276293
function getStatusIndicator(

0 commit comments

Comments
 (0)