From fc2f9853c59f705409ba5a86b3435e00ead055f3 Mon Sep 17 00:00:00 2001 From: Vikhyath Mondreti Date: Wed, 4 Feb 2026 10:00:38 -0800 Subject: [PATCH] fix run from block tracespan --- apps/sim/app/api/tools/dropbox/upload/route.ts | 11 +---------- .../api/workflows/[id]/execute-from-block/route.ts | 8 ++++++-- apps/sim/lib/core/utils/validation.ts | 10 ++++++++++ apps/sim/tools/dropbox/download.ts | 11 +---------- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/apps/sim/app/api/tools/dropbox/upload/route.ts b/apps/sim/app/api/tools/dropbox/upload/route.ts index c552c1b06..bdf06a5c6 100644 --- a/apps/sim/app/api/tools/dropbox/upload/route.ts +++ b/apps/sim/app/api/tools/dropbox/upload/route.ts @@ -3,6 +3,7 @@ import { type NextRequest, NextResponse } from 'next/server' import { z } from 'zod' import { checkInternalAuth } from '@/lib/auth/hybrid' import { generateRequestId } from '@/lib/core/utils/request' +import { httpHeaderSafeJson } from '@/lib/core/utils/validation' import { FileInputSchema } from '@/lib/uploads/utils/file-schemas' import { processFilesToUserFiles, type RawFileInput } from '@/lib/uploads/utils/file-utils' import { downloadFileFromStorage } from '@/lib/uploads/utils/file-utils.server' @@ -11,16 +12,6 @@ export const dynamic = 'force-dynamic' const logger = createLogger('DropboxUploadAPI') -/** - * Escapes non-ASCII characters in JSON string for HTTP header safety. - * Dropbox API requires characters 0x7F and all non-ASCII to be escaped as \uXXXX. - */ -function httpHeaderSafeJson(value: object): string { - return JSON.stringify(value).replace(/[\u007f-\uffff]/g, (c) => { - return `\\u${(`0000${c.charCodeAt(0).toString(16)}`).slice(-4)}` - }) -} - const DropboxUploadSchema = z.object({ accessToken: z.string().min(1, 'Access token is required'), path: z.string().min(1, 'Destination path is required'), diff --git a/apps/sim/app/api/workflows/[id]/execute-from-block/route.ts b/apps/sim/app/api/workflows/[id]/execute-from-block/route.ts index 03654e61b..0d1dc5cb8 100644 --- a/apps/sim/app/api/workflows/[id]/execute-from-block/route.ts +++ b/apps/sim/app/api/workflows/[id]/execute-from-block/route.ts @@ -9,6 +9,7 @@ import { SSE_HEADERS } from '@/lib/core/utils/sse' import { markExecutionCancelled } from '@/lib/execution/cancellation' import { preprocessExecution } from '@/lib/execution/preprocessing' import { LoggingSession } from '@/lib/logs/execution/logging-session' +import { buildTraceSpans } from '@/lib/logs/execution/trace-spans/trace-spans' import { executeWorkflowCore } from '@/lib/workflows/executor/execution-core' import { createSSECallbacks } from '@/lib/workflows/executor/execution-events' import { ExecutionSnapshot } from '@/executor/execution/snapshot' @@ -233,11 +234,14 @@ export async function POST(req: NextRequest, { params }: { params: Promise<{ id: }) const executionResult = hasExecutionResult(error) ? error.executionResult : undefined + const { traceSpans, totalDuration } = executionResult + ? buildTraceSpans(executionResult) + : { traceSpans: [], totalDuration: 0 } await loggingSession.safeCompleteWithError({ - totalDurationMs: executionResult?.metadata?.duration, + totalDurationMs: totalDuration || executionResult?.metadata?.duration, error: { message: errorMessage }, - traceSpans: executionResult?.logs as any, + traceSpans, }) sendEvent({ diff --git a/apps/sim/lib/core/utils/validation.ts b/apps/sim/lib/core/utils/validation.ts index 0945b30de..5fcfc4d35 100644 --- a/apps/sim/lib/core/utils/validation.ts +++ b/apps/sim/lib/core/utils/validation.ts @@ -50,3 +50,13 @@ export function getInvalidCharacters(name: string): string[] { const invalidChars = name.match(/[^a-zA-Z0-9_\s]/g) return invalidChars ? [...new Set(invalidChars)] : [] } + +/** + * Escapes non-ASCII characters in JSON string for HTTP header safety. + * Dropbox API requires characters 0x7F and all non-ASCII to be escaped as \uXXXX. + */ +export function httpHeaderSafeJson(value: object): string { + return JSON.stringify(value).replace(/[\u007f-\uffff]/g, (c) => { + return `\\u${(`0000${c.charCodeAt(0).toString(16)}`).slice(-4)}` + }) +} diff --git a/apps/sim/tools/dropbox/download.ts b/apps/sim/tools/dropbox/download.ts index d563aaf23..487f705e9 100644 --- a/apps/sim/tools/dropbox/download.ts +++ b/apps/sim/tools/dropbox/download.ts @@ -1,16 +1,7 @@ +import { httpHeaderSafeJson } from '@/lib/core/utils/validation' import type { DropboxDownloadParams, DropboxDownloadResponse } from '@/tools/dropbox/types' import type { ToolConfig } from '@/tools/types' -/** - * Escapes non-ASCII characters in JSON string for HTTP header safety. - * Dropbox API requires characters 0x7F and all non-ASCII to be escaped as \uXXXX. - */ -function httpHeaderSafeJson(value: object): string { - return JSON.stringify(value).replace(/[\u007f-\uffff]/g, (c) => { - return `\\u${(`0000${c.charCodeAt(0).toString(16)}`).slice(-4)}` - }) -} - export const dropboxDownloadTool: ToolConfig = { id: 'dropbox_download', name: 'Dropbox Download File',